带有Angular 4的量角器5.1.0:两个语句与单个语句相反超时

时间:2017-08-17 15:27:01

标签: angular protractor e2e-testing

我遇到了一个带有以下e2e测试的量角器的奇怪错误:

it('should render vehicle title', () => {
  expect(vehicleTitle.getText()).toBeTruthy();
});

it('should have color dropdown', () => {
  expect(colorDropdown.isDisplayed()).toBeTruthy();
});

it('should have title and color dropdown', () => {
  expect(vehicleTitle.getText()).toBeTruthy();
  expect(colorDropdown.isDisplayed()).toBeTruthy();
});

结果:

  ✓ should render vehicle title
  ✓ should have color dropdown
  ✗ sould have title and color dropdown
    - Failed: Timed out waiting for asynchronous Angular tasks to finish after 11 seconds. This may be because the current page is not an Angular application. Please see the FAQ for more details: https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular
    While waiting for element with locator

我的量角器配置:

// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts

/*global jasmine */
const { SpecReporter } = require('jasmine-spec-reporter');
const HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
const reporter = new HtmlScreenshotReporter({
  dest: 'e2e/reporter/screenshots',
  filename: 'protractor-report.html',
  userCss: '../style.css',
  ignoreSkippedSpecs: true,
  reportOnlyFailedSpecs: false,
  captureOnlyFailedSpecs: true
});

exports.config = {
  allScriptsTimeout: 11000,
  specs: [
    './e2e/**/*.e2e-spec.ts'
  ],
  capabilities: {
    browserName: 'chrome',
    chromeOptions: {
      args: [
        'incognito',
        'disable-extensions'
      ]
    }
  },
  directConnect: true,
  baseUrl: 'http://127.0.0.1:9000/',
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  // Setup the report before any tests start
  beforeLaunch: function() {
    return new Promise(function(resolve){
      reporter.beforeLaunch(resolve);
    });
  },
  afterLaunch: function(exitCode) {
    return new Promise(function(resolve){
      reporter.afterLaunch(resolve.bind(this, exitCode));
    });
  },
  onPrepare() {
    require('ts-node').register({
      project: 'e2e'
    });
    jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
    jasmine.getEnv().addReporter(reporter);
  }
};

我已经尝试增加量角器配置中可用的多个超时,并使用browser.sleep(n),browser.ignoreSynchronization = true和/或browser.waitForAngularEnabled(false)但没有任何效果..

提前感谢您的时间!

2 个答案:

答案 0 :(得分:0)

确定Angular环境中有$超时。 要求前端开发人员查看$timeout并将其替换为$ interval。

如果您的AngularJS应用程序不断轮询$ timeout或$ http,Protractor将无限期地等待并超时。您应该将$ interval用于连续轮询的任何内容(在Angular 1.2rc3中引入)。

答案 1 :(得分:0)

您需要使用更高的值来增加allScriptsTimeout。在你的情况下,量角器等了11秒,它就抛出了一个错误。