javascript - AngularJS Protractor : randomly fail in headless mode (Firefox)

标签 javascript angularjs firefox selenium-webdriver protractor

这是我的配置文件。

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

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

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

最佳答案

将下面的代码添加到你的配置中

allScriptsTimeout: 20000,
    jasmineNodeOpts: {
    defaultTimeoutInterval: 100000
     }

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

希望对你有帮助

关于javascript - AngularJS Protractor : randomly fail in headless mode (Firefox),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53607724/

相关文章:

javascript - Firefox 中的代理设置不是 "stick"

javascript - Jquery 滚动必须更频繁地触发

angularjs - 如何通过指令更改图像源属性

angularjs - 如何在 angular-grid 中进行服务器端排序/过滤?

javascript - 如何在 Web 扩展弹出窗口中使用 Vue.js?

html - Div 在 Firefox 50.0 和 IE 11 中定位不正确

javascript - 如何使用 JQuery 在到达 div 点时删除文本

javascript - 如何使用在其用法下定义的函数?

javascript - 为什么这些对象不相等?

javascript - 使用 Angular.js 创建表