量角器耐久测试内存泄漏

时间:2019-03-04 16:16:41

标签: selenium-webdriver protractor

我使用量角器进行了一个非常小的测试,以打开我的应用程序(基于angular)并开始按随机顺序单击随机链接。我们使用它来使Web应用程序运行几天并检查内存泄漏。

一段时间后,浏览器(chrome)的内存很大,当我创建一个内存转储时,我发现33k个字符串都包含相同的代码(如下所示)。

我尝试搜索这是从哪里来的,它导致我进入Webdriver,并且代码看起来像是由webdriver注入的东西来触发鼠标单击功能,但是从那里我迷路了。

我做错了还是应该在测试中清理内存?

(当我正常运行应用程序数小时并打开所有页面时,此字符串完全没有出现)

"(function() { // Copyright (c) 2012 The Chromium Authors. All rights reserved. 
// Use of this source code is governed by a BSD-style license that can be 
// found in the LICENSE file. 

/**
 * Enum for WebDriver status codes.
 * @enum {number}
 */
var StatusCode = { STALE_ELEMENT_REFERENCE: 10, JAVA_SCRIPT_ERROR: 17, };

/**
 * Enum for node types.
 * @enum {number}
 */
var NodeType = { ELEMENT: 1, DOCUMENT: 9, };

/**
 * Dictionary key to use for holding an element ID.
 * @const
 * @type {string}
 */
var ELEMENT_KEY = 'ELEMENT';

/**
 * True if using W3C Element references.
 * @const
 * @type {boolean}
 */
var w3cEnabled = false;

/**
 * True if shadow dom is enabled.
 * @const
 * @type {boolean}
 */
var SHADOW_DOM_ENABLED = typeof ShadowRoot === 'function';

/**
 * Generates a unique ID to identify an element.
 * @void
 * @return {string} Randomly generated ID.
 */
function generateUUID() {
  var array = new Uint8Array(16);
  window.crypto.getRandomValues(array);
  array[6] = 0x40 | (array[6] & 0x0f);"

.... (continues for a lot more lines)

我尝试运行的测试是:

import {browser, by, element} from 'protractor';

describe('Webclient', () => {
  const MAX_SAFE_TIMEOUT = Math.pow(2, 31) - 1;

  beforeAll(async function () {
    await browser.get('/');
  });

  it('Endurance test', (done) => {
    runTest();
  }, MAX_SAFE_TIMEOUT);
});

let counter = 0;

async function runTest() {

  try {
    const elements = await element.all(by.css('.header a, .sidebar-left a, .footer a, .content a'));
    let random = Math.floor(Math.random() * elements.length);

    while (!(await elements[random].isDisplayed())) {
      random = Math.floor(Math.random() * elements.length);
    }

    await elements[random].click();
    console.log('click counter:', counter++, await browser.getCurrentUrl());
  } catch (e) {
    // Do nothing, just continue
  }

  // Break the chain so that we don't get one big recursive function
  setTimeout(() => {
    runTest();
  }, 0);
}

0 个答案:

没有答案