Browser.wait在页面同步时超时

时间:2016-06-27 14:44:59

标签: javascript protractor

我有一个案例需要等待"等待数据加载"模态消失,所述模态取决于$ http请求运行。

我使用了browser.wait语句,根据Protractor API使用了预期条件 我的声明目前有这样的形式:

beforeEach(function() {
    browser.wait(element(EC.invisibilityOf(element(by.css(".msg-overlay"))), 30000);
});

it("describes something", function() {
    ...do some actions involving clicking...
})

不幸的是,spec总是失败并显示消息:

Message:
  Failed: Timed out waiting for Protractor to synchronize with the page after 11 seconds. Please see https://github.com/angular/protractor/blob/master/docs/faq.md
  While waiting for element with locator - Locator: By(css selector, .msg-overlay).
  The following tasks were pending:
   - $http: 
Stack:
  Error: Failed: Timed out waiting for Protractor to synchronize with the page after 11 seconds. Please see https://github.com/angular/protractor/blob/master/docs/faq.md
  While waiting for element with locator - Locator: By(css selector, .msg-overlay).
  The following tasks were pending:
   - $http: 
      at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:101:16
      at Promise.invokeCallback_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1329:14)
      at TaskQueue.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2790:14)
      at TaskQueue.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2773:21)

我不想将allScriptsTimeout设置为30000,因为这会减慢实际失败,我只想让Protractor等待一个模态消失。帮助

1 个答案:

答案 0 :(得分:0)

我认为您可以像使用jasmine default timeout interval(未经测试)一样暂时更改allScriptsTimeout

var originalTimeout;

beforeEach(function() {
    originalTimeout = browser.allScriptsTimeout;
    browser.allScriptsTimeout = 35000;
    browser.wait(element(EC.invisibilityOf(element(by.css(".msg-overlay"))), 30000);
});

afterEach(function() {
    browser.allScriptsTimeout = originalTimeout;
});