使用带有Bootstrapped AngularJS的量角器测试

时间:2014-08-31 22:01:42

标签: angularjs requirejs protractor

我希望能够使用Protractor测试我的Angular应用程序。由于我使用RequireJS,我不能在我的DOM中使用ng-app指令,这就是我用angular.bootstrap手动引导Angular的原因。

量角器打印错误输出如下:

  

错误:无法在页面http://localhost:1428/上找到角度:重试超出角度

然后,我意识到Protractor文档有一个警告:

  

与使用angular.bootstrap手动引导的应用程序相比,量角器无法开箱即用。您必须使用ng-app指令。

那么,是否有任何解决方法可以使用手动引导角度应用程序运行Protractor测试,还是应该开始了解其他测试套件?

1 个答案:

答案 0 :(得分:13)

转到量角器配置并添加此

onPrepare: function() {
// implicit and page load timeouts
  browser.manage().timeouts().pageLoadTimeout(40000);
  browser.manage().timeouts().implicitlyWait(25000);

  // for non-angular page
  browser.ignoreSynchronization = true;

  // sign in before all tests

}

它对我有用

我的完整配置文件看起来像这样......

// conf.js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['../**/*.e2e.js'],
multiCapabilities: [{
browserName: 'firefox'
}],

onPrepare: function() {
// implicit and page load timeouts
browser.manage().timeouts().pageLoadTimeout(40000);
browser.manage().timeouts().implicitlyWait(25000);

// for non-angular page
browser.ignoreSynchronization = true;

// sign in before all tests

 }
}

实际发生的是你要求量角器等待一段时间并忽略document.ready(),以便给你时间手动引导角度。