【问题标题】:browser.wait ignores my parameter to wait 20 seconds Protractorbrowser.wait 忽略我的参数等待 20 秒量角器
【发布时间】:2018-04-30 15:37:53
【问题描述】:

我已经编写了这个测试,但是浏览器在寻找元素之前不会等待这 20 秒。它会忽略该部分,只等待默认的 11 秒。我的代码有问题吗?

it('should navigate to Home tab', function() {
    element(by.css('[ui-sref="main.home"]')).click();

    var telematicsSection = element(by.id('teleMap'));

    var EC = protractor.ExpectedConditions;
    browser.wait(EC.presenceOf(telematicsSection), 20000);
});

这是我得到的错误

失败:等待异步 Angular 任务在 11 秒后完成时超时。这可能是因为当前页面不是 Angular 应用程序。更多详情请查看常见问题解答:https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular 在等待带有定位器的元素时 - 定位器:By(css selector, *[id="teleMap"])。

@edit

我已经设法修复它。 Yash Jagdale 的代码和

allScriptsTimeout: 20000

在 conf.js 中使其工作。

【问题讨论】:

  • 在你的配置文件中,你为allScriptsTimeout设置了什么值?
  • 您是否阅读了给出的链接?
  • 正如 Gunderson 指出的那样,您的超时声明可能存在问题。你能告诉我们你的 conf.js 代码吗?

标签: javascript protractor automated-tests


【解决方案1】:

您可以使用以下方式正确处理异步循环

    it('should navigate to Home tab', function(callback) {
        element(by.css('[ui-sref="main.home"]')).click().then(function() {

        var telematicsSection = element(by.id('teleMap'));

        var EC = protractor.ExpectedConditions;
        browser.wait(EC.presenceOf(telematicsSection), 20000).then(function() {
           callback();
         });
      });
    }, 40000);

【讨论】:

  • 不幸的是同样的结果
  • allScriptsTimeout: 20000 in conf.js 并且你的代码解决了这个问题
【解决方案2】:

在量角器conf.js的onPrepare中添加browser.ignoreSynchronization = true;

onPrepare: function() {

  browser.ignoreSynchronization = true;

【讨论】:

  • 在任何其他情况下不忽略同步不是很有用,但不是这个。 ignoreSynchronization 会影响我所有的测试。
猜你喜欢
  • 1970-01-01
  • 2016-05-13
  • 2020-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多