【问题标题】:AngularJS Protractor: randomly fail in headless mode (Firefox)AngularJS Protractor:在无头模式下随机失败(Firefox)
【发布时间】:2018-12-04 17:00:31
【问题描述】:

这是我的 conf 文件。

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'],
    },
  }
}

因此,使用此配置,我的测试随机失败并出现以下错误

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

但是!当我注释掉以下几行时

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

它代表无头模式,并观察 firefox 如何运行我的测试 - 测试永远不会失败并减少 3 时间。

下面是一个测试示例,由于我上面提到的错误而失败了几次。

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

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

    await FormDriver.pressClose();
  });

这里是我引用的驱动程序的方法

  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();
  };

我的问题是 - 我做错了什么,我可能遗漏了什么,我该如何解决?谢谢!

【问题讨论】:

    标签: javascript angularjs firefox selenium-webdriver protractor


    【解决方案1】:

    将以下代码添加到您的配置中

    allScriptsTimeout: 20000,
        jasmineNodeOpts: {
        defaultTimeoutInterval: 100000
         }
    

    根据您的测试执行时间调整超时间隔。 更多信息请参考https://www.theoldschoolhouse.com/reviews_client/node_modules/protractor/docs/timeouts.md

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2019-09-13
      • 2018-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-12
      • 2022-12-24
      • 1970-01-01
      相关资源
      最近更新 更多