在 Bootstrapped AngularJS 中使用量角器测试 [英] Using Protractor Test with Bootstrapped AngularJS

查看:24
本文介绍了在 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 打印如下错误输出:

Protractor prints an error output like below:

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

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.

好吧,是否有任何解决方法可以使用手动引导的 Angular 应用程序运行量角器测试,还是应该开始了解替代测试套件?

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

推荐答案

转到量角器配置并添加此

go to protractor confiuration and add this

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(),以便给您时间手动引导 angular.

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天全站免登陆