简体   繁体   English

AngularJS量角器:在无头模式下随机失败(Firefox)

[英]AngularJS Protractor: randomly fail in headless mode (Firefox)

Here is my conf file. 这是我的配置文件。

exports.config = {
  rootElement: '[ng-app="myapp"]',
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['./web/assets/e2e/**/*protractor.js'],
  SELENIUM_PROMISE_MANAGER: false,
  baseUrl: 'https://localhost',
  capabilities: {
    browserName: 'firefox',
    marionette: true,
    acceptInsecureCerts: true,
    'moz:firefoxOptions': {
      args: ['--headless'],
    },
  }
}

So with this config my tests fails randomly with the following error 因此,使用此配置,我的测试会随机失败,并显示以下错误

Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

But! 但! When I comment out following lines 当我注释掉以下几行时

    'moz:firefoxOptions': {
      args: ['--headless'],
    },

which stands for headless mode and watch how firefox run my tests - tests never fail and take 3 time less time. 它代表无头模式,并观看firefox如何运行我的测试-测试永不失败,并且花费的时间减少了3倍。

Below is an example of test that failed a couple of times with the error I mentioned above. 下面是一个测试示例,由于我上面提到的错误而失败了几次。

  it('- should test add button open a form', async () => {
    await ClientListPageDriver.openAddClientForm();

    await FormDriver.toBeShown('Add New Client');

    await FormDriver.pressClose();
  });

And here are methods from drivers I referencing 这是我引用的驱动程序中的方法

  this.openAddClientForm = async () => {
    const button = await $('button[ng-click="$ctrl.addClient()"]');
    await button.click();
  };

  this.toBeShown = async (title) => {
    const modalElement = await $('#form').element(by.cssContainingText('.form-header h2', title))

    const awaitSeconds = 6;
    return await browser.wait(
      protractor.ExpectedConditions.presenceOf(modalElement),
      awaitSeconds * 1000,
      `Form should be shown within ${awaitSeconds} sec`,
    );
  };

  this.pressClose = async () => {
    const button = await $('button[ng-click="$ctrl.closeForm()"]');
    await button.click();
  };

My question is - what I'm doing wrong, what I'm probably missing and how can I fix it? 我的问题是-我做错了什么,我可能丢失了什么以及如何解决? Thanks! 谢谢!

Add the below code to your config 将以下代码添加到您的配置中

allScriptsTimeout: 20000,
    jasmineNodeOpts: {
    defaultTimeoutInterval: 100000
     }

Adjust the timeout interval as per your test execution time. 根据测试执行时间调整超时间隔。 Refer https://www.theoldschoolhouse.com/reviews_client/node_modules/protractor/docs/timeouts.md for more info 有关更多信息,请参阅https://www.theoldschoolhouse.com/reviews_client/node_modules/protractor/docs/timeouts.md

Hope it help you 希望对你有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM