将量角器测试与Bootstrapped AngularJS一起使用 [英] Using Protractor Test with Bootstrapped AngularJS

查看:77
本文介绍了将量角器测试与Bootstrapped AngularJS一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to be able to test my Angular application with Protractor. Since I use RequireJS, I cannot use ng-app directive in my DOM and that is why I bootstrap Angular manually with angular.bootstrap.

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

Protractor prints an error output like below:

错误:在页面http://localhost:1428/上找不到角度:重试以寻找超出角度的角度

Error: Angular could not be found on the page http://localhost:1428/ : retries looking for angular exceeded

然后,我意识到量角器文档中有一个警告:

Then, I realized that Protractor documentation has a warning:

Protractor不能与使用angular.bootstrap手动引导的应用程序配合使用.您必须使用ng-app指令.

Protractor does not work out-of-the-box with apps that bootstrap manually using angular.bootstrap. You must use the ng-app directive.

那么,是否有任何解决方法可以通过手动引导的角度应用程序运行量角器测试,还是我应该开始学习替代测试套件?

Well, Is there any workaround to run Protractor tests with manually bootstrapped angular application or should I start to learn about alternative testing suites?

推荐答案

转到量角器标签并添加

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

}

对我有用

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

my full config file looks like this...

// 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(),以便让您有时间手动引导角度.

What actually happens is that you ask from protractor to wait for an amount of time and ignnore the document.ready(), in order to give you time to bootstrap angular manually.

这篇关于将量角器测试与Bootstrapped AngularJS一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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