Our Engineers can Write as well

Why automate AngularJS applications with Protractor rather than Selenium? – Part I

When automation testers are assigned the job of automating a web application, the first tool that comes in their mind is “Selenium”! Let’s take a moment to think whether there is any other open source tool to automate a web application.

During our exploration or analysis of available tools, we have to understand which application should go for automation testing

Is your application based on AngularJS?

If Yes, then the best option to automate the AngularJS application would be Protractor.

Reasons to choose Protractor over Selenium:
  • Selenium’s support for AngularJS based applications is still limited and does not sync with Angular based Locators.

  • While automating AngularJS based application, we will encounter page synching issues, despite providing implicit/explicit wait functions for the web elements to load on webpages.

In-order to overcome the above challenges, choose Protractor. Protractor can wait until the webpage loads, through its default 11 seconds wait time. So, we don’t need to implement wait conditions explicitly.

Specifications of Protractor:

Protractor is a program, built in Node.js and working on top of SeleniumWebDriver. Some of the unique features of protractor are,

  1. Protractor supports both Angular based Locators such as ng-model, ng-binding, ng-repeat and Selenium WebDriver Locators (such as Id, Name, Class, XPath, CSS etc) to identify web elements of the AngularJS based web application.
  2. Protractor supports test frameworks like Jasmine and Mocha by default. We can also integrate Protractor with CUCUMBER to provide Behaviour Driven Development (BDD) features and make the framework simpler & readable to all the stakeholders.
  3. Protractor can be configured to harness a Selenium Grid to execute tests across multiple platforms at once.
  4. Protractor basically works on basis of configuration and specification files.
Browser Support:

Protractor supports almost all the major browsers such as Chrome, Edge, Firefox, Safari, and IE.

browser list
How to configure Protractor and perform first test using Protractor and Jasmine?
Required Installations
1.Download and install Node.js using linkhttps://nodejs.org/en/
2.Verify JavaScript package manager installation using following command at command promptnpm –version
3.Install Protractor from global software registry using following commandnpm install -g protractor
4.Once Protractor is installed, Jasmine is also installed by default
5.List all the nodes installed in the system using the commandnpm -g list
6.Download and install Java JDK using linkhttp://www.oracle.com/technetwork/java/javase/downloads/index.html
7.Download and install Selenium WebDriver using linkhttp://www.seleniumhq.org/download/
Protractor Test Project:
  1. Create a folder in your local directory and name suitably. This will be your project folder.
  2. Create Protractor Configuration File and Specification File within this folder.

Configuration file contains necessary system configuration details, browser details, Selenium server address, Jasmine timeout options, Protractor Specification file name and Jasmine onPrepare functions.

Specification file contains actual test steps and expected conditions. Note that a spec file may contain ‘n’ number of describe and it blocks.

Sample Protractor Configuration File(conf.js):
Protractor Configuration File
Sample Protractor Specification File (spec.js):
Protractor Specification File
Test Execution:

1. Open command prompt and navigate to project folder using following commands
2. In Protractor, we should execute only Protractor configuration file using command protractor conf.js

parthiban - Software Test Engineer

Contributed by:

Software Testing Engineer

Your email address will not be published. Required fields are marked *