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,
- 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.
- 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.
- Protractor can be configured to harness a Selenium Grid to execute tests across multiple platforms at once.
- Protractor basically works on basis of configuration and specification files.
Protractor supports almost all the major browsers such as Chrome, Edge, Firefox, Safari, and IE.
How to configure Protractor and perform first test using Protractor and Jasmine?
|1.||Download and install Node.js using link||https://nodejs.org/en/|
|3.||Install Protractor from global software registry using following command||npm 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 command||npm -g list|
|6.||Download and install Java JDK using link||http://www.oracle.com/technetwork/java/javase/downloads/index.html|
|7.||Download and install Selenium WebDriver using link||http://www.seleniumhq.org/download/|
Protractor Test Project:
- Create a folder in your local directory and name suitably. This will be your project folder.
- 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):
Sample Protractor Specification File (spec.js):
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
Software Testing Engineer