Identification of HTML elements is the main task when it comes to E2E testing of web applications. Though the existing way of using HTML & CSS selectors suffice this requirement of element identification, still this force the developer / tester to add /maintain unique identifiers for each element to be accessed by the automation.

For E2E Testing of web applications ,most preferred one is selenium. But for Angular apps testing selenium will not be a choice. And the reason’s i have penned down in this blog.

Selenium will work in angularjs , but it will get synchronisation issues. Selenium WebDriver code is not friendly business users for Behaviour Driven Development such as jasmine and mocha.

Angularjs needs to identify the elements which are not recognized by selenium for ex: ng-model, css etc.But in Selenium Webdriver this can be achieved only via the required identifiers or unique class to access the elements.It takes more effort and time, when does the same in selenium.

Protractor uses selenium webdriver and it uses the selenium js driver with its own wrapper to support angular context helper methods, but why we need to prefer use of protractor than selenium for testing Angular and Angularjs applications ?

Even though I am using selenium stand-alone to test the app ,but testing could be more challenging Sometimes.

Here I`ve ln-lined the reasons below

Protractor provides some new locator strategies and functions which are very helpful to automate the AngularJS application. Examples include things like:

  • waitForAngular
  • By.binding
  • By.repeater,
  • By.textarea
  • By.model
  • WebElement.all,
  • WebElement.evaluate, etc.

Sometimes it is difficult to capture the web elements in AngularJS applications using JUnit or Selenium Webdriver. Protractor supports Angular-specific locator strategies, which allows you to test Angular-specific elements without any setup effort on your part.

It supports multiple browsers like chrome,firefox,safari and IE .It can run parallel test using the multiCapabilities configuration option. i.e (Conf.js)

Protractor supports two testing frameworks  behaviour driver development such as jasmine and mocha .By using this BDD frameworks reporting was ease to adapt in the protractor.

For this comparison, I ran the simple Authentication scenario with username and password , then logged into the home screen of https://app.bitrise.io/users/sign_in web application build using AngularJS.

The Protractor takes approximately ~11 seconds for execution while the Selenium tests were running for over ~20 seconds.I’ve attached the code and screenshot for your reference below

 

Protractor results :

 

In this example, selenium takes twice the time of protractor. So, when creating larger applications the time difference output may be more in selenium.It is faster than selenium because there is no need for any additional waits and sleeps

since the protractor track the network, router changes and execute the testing scripts accordingly.

For testing angularjs and Angular, it is better to go with protractor.