Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Protractor with Angular 2?

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

like image 434
JohnnyC Avatar asked Nov 05 '15 09:11

JohnnyC


People also ask

Does Protractor support Angular?

Since Protractor was initially designed to support AngularJS, many of its features like locators and mock modules are specific to AngularJS. These features only work in AngularJS and not Angular. They will no longer be relevant once development on AngularJS ceases by December 31, 2021.

What is use of Protractor in Angular?

Protractor is a wrapper around Selenium Webdriver that provides an automation test framework, which simulates user interaction with an Angular web application for a range of browsers and mobile devices. It provides all features of Selenium WebDriver along with Angular specific features for seamless end to end testing.


1 Answers

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
like image 161
alecxe Avatar answered Sep 22 '22 20:09

alecxe