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

时间:2021-12-04 01:23:57

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测试我的Angular应用程序。由于我使用RequireJS,我不能在我的DOM中使用ng-app指令,这就是我用angular.bootstrap手动引导Angular的原因。

Protractor prints an error output like below:

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

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

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

Then, I realized that Protractor documentation has a warning:

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

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

Protractor不能与使用angular.bootstrap手动引导的应用程序一起开箱即用。您必须使用ng-app指令。

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

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

1 个解决方案

#1


13  

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

}

It worked for me

它对我有用

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

 }
}

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.

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

#1


13  

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

}

It worked for me

它对我有用

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

 }
}

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.

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