How to use Protractor with Angular 2?

28,751

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:

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

Share:
28,751

Related videos on Youtube

JohnnyC
Author by

JohnnyC

Updated on July 09, 2022

Comments

  • JohnnyC
    JohnnyC almost 2 years

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

    • Eric Martinez
      Eric Martinez over 8 years
      Not at all, if you see in the playground e2e examples most of them, if not all, use protractor.
    • jornare
      jornare over 8 years
      To me, that qualifies as an answer @EricMartinez
    • JohnnyC
      JohnnyC over 8 years
      Yes, it's a response part but it's TS and not JS pure and this files aren't an official status on Protractor's futur. But thank you, this is an initial response
  • rarrarrarrr
    rarrarrarrr about 8 years
    How does it work to test a website that is mixed angular 1.x and angular 2? Is that a use-case that just isn't supported?
  • michael_hook
    michael_hook almost 8 years
    While you can use Protractor with Angular 2 at this time there are several key matchers which don't work, as explained on this post: stackoverflow.com/questions/36201691/…
  • Eric Francis
    Eric Francis about 7 years
    github.com/angular/protractor/blob/master/CHANGELOG.md#500 This was changed in Protractor 5.0.0
  • alecxe
    alecxe about 7 years
    @EricFrancis thanks for the update! I've updated the answer, let me know if you think we can add anything else here.