Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

requirejs - Using Protractor Test with Bootstrapped AngularJS

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:

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 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...