How to Perform Angular Testing with ProtractorTesters often face a situation of delayed test times, especially while working with WebDriver.  This leads to frustration in crunch testing times. However, if you are working with Angular JS applications, Protractor proves to be the best tool.

It is an end-to-end testing framework built on top of WebDriver JS. It has been released as an open source and includes key enhancements meant for Angular JS applications.

Advantages with Protractor

  • No Waits or Sleeps

Protractor can automatically communicate with the Angular JS application soon after executing the pending tasks and will perform the next step. This avoids the need to wait for the test and synchronization of the web page.

  • Locator Strategies for Angular JS Applications

Angular JS locator strategies like binding, model, repeater along with native WebDriver locator strategies are supported. This helps in testing Angular-specific elements without any extra effort.

  • Page Object Setup

Protractor executes WebDriver command only when an action like get, click, etc. is required. This allows you to easily setup page objects and modify page elements without manipulating the HTML.

  • Uses Jasmine

Same language can be used to write Angular JS unit tests, JavaScript, and Angular JS applications.

You can run the Protractor test by following the below mentioned points.

  • Use the npm command to install protractor and webdriver-manager.

npm install -g protractor

  • Startup Selenium server instance.

webdriver-manager update & webdriver-manager start

  • Write the test as shown below.

modularizing testing logic by using page objects

  • Specify the environment to run the test by configuring the Protractor file.

run the test by configuring the Protractor file

  • Run the test using the command.

protractor conf.js

  • The test output should be:

1 test, 1 assertions, 0 failures

You might also like: Using Locators in Protractor