Getting started with Protractor for E2E Automated testing- Part1

What is Protractor?

Protractor is the E2E testing framework built as an wrapper over selenium using webdriver js api.

Protractor can be used for testing both angular and non angular apps.

We can run our tests both in headless way and with real browsers also.

The main benefit of writing our tests in angular is that we don’t need to add waits and timers.

Installation:

Pre-requisites:

Install Java/JDK:

Follow https://www3.ntu.edu.sg/home/ehchua/programming/howto/JDK_Howto.html

To Verify Java is installed on your system run :

Java -version command on your terminal

Install NodeJs and NPM:

Follow https://www.taniarascia.com/how-to-install-and-use-node-js-and-npm-mac-and-windows/

To verify node is installed on your system run:

Node -v

To verify npm is installed on your system run:

Npm -v

Install IDE (Sublime, Webstorm etc):

We will cover this in more detail later

Installing Protractor:

For installing protractor on your machine, run following command

npm install -g protractor

This command will install Protractor, Webdriver-Manager and associated libraries

Webdriver Manager is a helper tool to get the selenium standalone server up and running.

For knowing the version of Protractor installed on your system just run

Protractor --version command

Webdriver-manager update: This command installs the chromedriver, geckodriver and selenium standalone jar file.

Webdriver-manager start

 

This command starts up the selenium server.

Protractor test will send requests to this server to control a local browser. You can see information about the status of the server at http://localhost:4444/wd/hub.

Writing a basic test and Running it:

For running a basic test we need two files:

  1. Spec File
  2. Configuration

Spec File:

This file contains the tests we want to run

We will create a file spec.js in our root folder named as pro

Name the file as spec.js

We can name it as anything but make sure we have .js extension.

describe('page tests', function() {

it(‘should have title’, function () {

browser.get(‘https://angularjs.org/’);

expect(browser.getTitle()).toEqual(‘AngularJS — Superheroic JavaScript MVW Framework’);

});

} );

Configuration file:

Create a file named as conf.js and add below snippet:

exports.config = {

seleniumAddress: ‘http://localhost:4444/wd/hub’,

specs: [‘spec.js’]

};

We will explain more about the above two files in next chapters.

Steps to run the the above test:

  1. Open up your terminal
  2. CD to folder where you saved above two files example pro
  3. Run protractor conf.js

 

The green dot in above screenshot indicates that our test has passed.

We can also see total execution time in above screenshot.

We will cover how to setup Eclipse and Webstorm for Protractor JS in our Next series.

 

 

 

One thought on “Getting started with Protractor for E2E Automated testing- Part1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s