超时等待Protractor在11秒后与页面同步

时间:2016-04-09 05:10:18

标签: angularjs protractor

我是Protractor的新手(可以说仅仅1天)并且一直在尝试进行端到端测试。

但是,每次运行conf.js时,我都会显示“Timed out等待Protractor在11秒后与页面同步。”

在发布此问题之前,已尝试过其他受访者提供的所有选项,但仍无法解决问题,因此请求您的帮助。

为了支持,下面是我的配置和规范js文件的详细信息:

Conf.js:

    exports.config = {
      directConnect: true,
      capabilities: {'browserName': 'chrome'},
      framework: 'jasmine',
      specs: ['example_spec.js'],
    jasmineNodeOpts: {
    defaultTimeoutInterval: 100000
      }
     };

example_spec.js:

    describe('forfirm homepage', function() {
        it('login window should open', function() {
         browser.get('https://www.forfirm.com');
         element(by.model('forfirm.email')).sendKeys('email@email.com');
         element(by.model('form.password')).sendKeys('Password');
             });
         });

收到的输出:

      Failures:
       1) forfirm homepage login window should open
       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. The following tasks were pending:
       - $timeout: function (){a.next(),h=f(j,5e3)}
       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. The following tasks were pending:
        - $timeout: function (){a.next(),h=f(j,5e3)}
    at /Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/jasminewd2/index.js:101:16
    at Promise.invokeCallback_ (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1329:14)
    at TaskQueue.execute_ (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2790:14)
    at TaskQueue.executeNext_ (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2773:21)

   1 spec, 1 failure
   Finished in 22.022 seconds
   [launcher] 0 instance(s) of WebDriver still running
   [launcher] chrome #01 failed 1 test(s)
    [launcher] overall: 1 failed spec(s)
    [launcher] Process exited with error code 1

另外,在运行量角器conf.js时,我看不到量角器启动Chrome浏览器。

2 个答案:

答案 0 :(得分:4)

您应该查看Timeouts并尝试先设置所有这些

allScriptsTimeout: 120000,
getPageTimeout: 120000,
jasmineNodeOpts: {
    defaultTimeoutInterval: 120000
},

更新: 我讨厌ignoreSynchronization,你应该阅读它,如何在官方量角器文档中避免它 - 试试这个:

conf.js

exports.config = {
directConnect: true,
capabilities: {'browserName': 'chrome'},
framework: 'jasmine',
specs: ['example_spec.js'],
allScriptsTimeout: 120000,
getPageTimeout: 120000,
jasmineNodeOpts: {
    defaultTimeoutInterval: 120000
},
onPrepare: function () {
    browser.driver.manage().window().maximize();
}};

example_spec.js

describe('forfirm homepage', function() {
it('login window should open', function() {
    browser.ignoreSynchronization = true;
    browser.get('https://www.forfirm.com');
    element(by.model('form.email')).sendKeys('email@email.com');
    element(by.model('form.password')).sendKeys('Password');
    browser.sleep(5000);
});});

答案 1 :(得分:3)

我认为这应该可以解决这个问题,按照“https://github.com/angular/protractor/blob/master/docs/timeouts.md”的量角器官方文档。

有趣的是,在我们的应用程序中,我发现即使我将allScriptsTimeout设置为120秒的值,这仍然需要11秒的默认值。

我也尝试在OnPrepare中这样做,尽管我看到同样的错误,说明Protractor与页面同步11秒。任何想法都会受到高度赞赏。

以下是我的配置示例(Node - 4.2.4,Protractor - 3.1.1)

exports.config = {
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['DemoTest.js'],
  getPageTimeout: 120000,
  allScriptsTimeout: 120000,

  capabilities: {
    browserName: 'chrome',
    },

  onPrepare: function(){
      browser.ignoreSynchronization = true;
      getPageTimeout: 120000;
      allScriptsTimeout: 120000;
      jasmine.DEFAULT_TIMEOUT_INTERVAL = 180000;

   },
}