How to use Protractor with Angular 2?

2020-05-18 05:01发布

问题:

I use Protractor with Angular 1.x. I would like to migrate to Angular 2.0 step by step but I don't see Protractor in the docs.

Has protractor been dropped since Angular 2? Should I write my tests without using Protractor, using Jasmine instead (or others)?

回答1:

You can test Angular 2 applications with Protractor (starting from Protractor 2.5.0).

For Protractor 5.0.0+, you don't have to do anything specific, Protractor will auto-detect the Angular version used in the application under test.

For Protractor >= 2.5.0 and <= 4.0.14, you would only need to add useAllAngular2AppRoots: true to your config. Here is a sample.


Note that several built-in Protractor matchers would not yet work with Angular2, see:

  • Protractor Angular 2 Failed: unknown error: angular is not defined

There is also that Protractor+Angular2 problem in Firefox (still unresolved), see:

  • Can't run Selenium via Protractor on Firefox after update to Angular 2