量角器-在localhost上运行良好,但远程抛出超时-在指定的超时时间内未调用异步回调 [英] Protractor - works well on localhost but remote throws Timeout - Async callback was not invoked within timeout specified

查看:99
本文介绍了量角器-在localhost上运行良好,但远程抛出超时-在指定的超时时间内未调用异步回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行 protractor protractor.conf.js --baseUrl = http:// localhost:4200 / 时,它运行良好-填充数据,验证元素等。

When I execute protractor protractor.conf.js --baseUrl=http://localhost:4200/, it works well - fills data, validates elements, etc.

当我尝试通过远程URL测试完全相同的网站时 protractor protractor.conf.js --baseUrl = http:// the-same -website.com / ,它将在浏览器中打开,登录并且所有必需的部分都像在localhost中一样被加载,但是Protractor / Jasmine无法填充/单击/验证任何内容,并且在指定时间后我超时:

When I try to test exactly the same website via remote URL protractor protractor.conf.js --baseUrl=http://the-same-website.com/, it opens up in browser, logins and all necessary parts are loaded like in localhost but Protractor/Jasmine does not fill/click/validate anything and I get timeout after specified time:

  - Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
      at ontimeout (timers.js:436:11)
      at tryOnTimeout (timers.js:300:5)
      at listOnTimeout (timers.js:263:5)
      at Timer.processTimers (timers.js:223:10)
  - Failed: script timeout: result was not received in 30 seconds
    (Session info: chrome=71.0.3578.98)

还有其他线程在堆栈溢出时会出现类似的问题-尝试 browser.ignoreSynchronization = true Protractor.waitForAngular(false),但随后页面无法正确加载,并且由于找不到元素而导致测试失败。

There are other threads will similar problems on Stack Overflow - tried browser.ignoreSynchronization = true and Protractor.waitForAngular(false) but then page doesn't load properly and tests fail because elements aren't found.

更新1

下面的测试在localhost上运行良好-根据h1输出成功或失败,但在远程URL上却没有

The test below works well on localhost - outputs success or failure depending on h1 but on remote URL it doesn't check anything despite web is loaded:

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

describe('example-test', () => {

  const PATH_TO_TEST = 'specific-path/to/test';

  beforeEach(() => {
    browser.get(PATH_TO_TEST);
  });

  it('should exist header', () => {
    expect(element(by.css('h1')).getText()).toEqual('test');
  });
});

如果添加日志记录,则会看到输出,但期望未执行:

If I add logging, I see output but expect is not executed:

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

describe('example-test', () => {

  const PATH_TO_TEST = 'specific-path/to/test';

  beforeEach(() => {
    browser.get(PATH_TO_TEST);
    console.log('beforeEach');
  });

  it('should exist header', () => {
    expect(element(by.css('h1')).getText()).toEqual('test');
    console.log('test end');
  });
});

量角器配置:

const { SpecReporter } = require('jasmine-spec-reporter');

exports.config = {
  allScriptsTimeout: 30000,
  specs: [
    './e2e/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'chrome'
  },
  directConnect: true,
  baseUrl: 'http://localhost:4200/',
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  onPrepare() {
    require('ts-node').register({
      project: 'e2e/tsconfig.e2e.json'
    });
    jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
  }
}

更新2

如果我添加 browser.sleep browser.ignoreSynchronization ,测试开始工作,但随后我需要为每个看起来不太不错的同步添加 browser.sleep

If I add browser.sleep and browser.ignoreSynchronization, tests begin to work but then I need to add browser.sleep for every synchronization which doesn't look nice:

beforeEach(() => {
  browser.get('path/to/test');
  browser.sleep(3000);
  browser.ignoreSynchronization = true;
});

似乎量角器无法识别页面为已满载还是Angular Web。 strong>

It seems that Protractor does not recognize page as fully loaded or as Angular web.

尽管页面已正确加载,但量角器为何仍无法验证内容?

Why Protractor does not validate content despite the page is loaded properly?

推荐答案

已更新:已完成对原始建议答案的更改。

UPDATED: Completed changed original proposed answer.

此问题可能是由于您的登录页面的性质所致。如果您的登录是非角度的,那么您必须指示量角器不要等待角度变为可测试(默认情况下将是可测试的)。为此,您可以使用 browser.waitForAngularEnabled(false)命令,该命令是推荐的新方法,与以前的 browser.ignoreSynchronization = true 相反。

This issue could be due to the nature of your login page. If your login is non-angular then you must instruct protractor not to wait for angular to become testable (which it will by default). To do this you can use the browser.waitForAngularEnabled(false) command which it the recommended new way as opposed to the previous browser.ignoreSynchronization = true.

登录到应用程序后,可以将 browser.waitForAngularEnabled 设置为true,并且该规范中的其余测试应正常运行。

After you have logged into your application you can set your browser.waitForAngularEnabled back to true and the rest of your tests in that spec should behave correctly.

describe('Main', function {
  beforeAll(function () {
      browser.waitForAngularEnabled(false);
      Site.login();
      //after you have successfully logged into you site you can 
      browser.waitForAngularEnabled(true);
  });

  it('should show the main page', function () {
     //Your code
  });
});

这篇关于量角器-在localhost上运行良好,但远程抛出超时-在指定的超时时间内未调用异步回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆