SlideShare a Scribd company logo
Protractor
By: Syed Shadab Gilani
Introduction
 Protractor, formally known as E2E testing framework, is an open source functional automation framework designed
specifically for AngularJS web applications. It was introduced during AngularJS 1.2 as a replacement of the existing E2E
testing framework. The Protractor automation tool is also recommended by AngularJS for scenario testing.
 For an angular app functional automation framework to automate the UI and functionality of the web application, we zeroed
in on the Protractor automation tool.
Features
 Built on the top of WebdriverJS and Selenium server
 Introduced new simple syntax to write tests
 Allows running tests targeting remote addresses
 Can take advantage of Selenium grid to run multiple browsers at once
 Can use Jasmine or Mocha to write test suites
Benefits
 Protractor is a wrapper (built on the top) around Selenium WebDriver, so it contains every feature that is available in the
Selenium WebDriver. Additionally, 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.
Installation
Pre Requisite:
 Download and install NodeJS. http://nodejs.org/download/. After installation make sure its path is configured correctly, so
that command execution can find Node.
Installation…
 Open the command prompt and type in the following command to install protractor globally.
- npm install –g protractor
 Install Protractor Locally
You can install protractor locally in your project directory. Go to your project directory and type in the following command in the command
prompt:
- npm install protractor
 Verify Installation
To verify your installation, please type in the command
- Protractor –version
 If Protractor is installed successfully then the system will display the installed version. Otherwise you will have to recheck the installation.
 If you don’t have the Selenium server on your machine, then download the latest version onto your machine. If you want to run tests on different
browsers, then please download the respective drivers as well. For example, Chrome driver will come in handy to run tests on the Chrome browser.
Architecture of Framework
Pages : Contains pages and elements(Locators)
CommonUtils: Contains common methods or operations used for UI and API automation
TestData : Contains constant value and payload in case of API automation
Specs: Contains scenario - test cases
Conf : Contains configuration and capabilities
Reports : Allure reporting - screenshots and reports
TestLogs : Contains logs
Pages Example
"use strict";
//Importing required files
var data = require('../TestData/TestData.json');
var commonCode = require('../CommonUtils/CommonCode.js')
var elementsPage = require('../CommonUtils/ElementsPage.js');
var log4js = require('log4js');
var logger = log4js.getLogger();
var XYZPage = function () {
var EC = protractor.ExpectedConditions;
// Login to the application
this.loginInToTheApplication = async function (userNameElement,userName,passwordElement, password) {
try {
commonCode.wait_tillVisible(elementsPage.adminEmailTextbox);
commonCode.sendDataToTextBox(userNameElement,userName);
commonCode.sendDataToTextBox(passwordElement, password);
commonCode.clickAction(elementsPage.loginButton);
commonCode.wait_tillVisible(elementsPage.someTitle);
expect(elementsPage.someTitle.isDisplayed()).toBe(true);
} catch (e) {
logger.error('Error while Logging in to the application' + e.message);
}
};
};
module.exports = new XYZPage();
It is used for UI automation.
Common Code Example
// To perform Click operation
this.clickAction = async function (element) {
try {
this.wait_tillClickable(element);
this.highlightElement(element);
element.click();
} catch (e) {
logger.error('Error while clicking on the web element' +
e.message);
}
};
For UI
Common Code Example
// Get method with cookie
this.getMethodWithCookie = async function (IP, PATH,
COOKIE) {
const expect = chai.expect;
const chaiHttp1 = chai.request(IP);
const response = await chaiHttp1.get(PATH).set(COOKIE);
return response;
};
For API
Elements File Example
"use strict";
var ElementsPage = function () {
//landingPage
this.xyz_button = element.all(by.css('input[value*="xyz"]')).get(0);
this.emailTextbox = element(by.css('input[placeholder*="E-mail
Address"]'));
this.passwordTextbox = element(by.css('input[placeholder*="Password"]'));
this.loginButton = element(by.css('button[class*="btn-login-btn"]'));
};
module.exports = new ElementsPage();
Test Data Example
{
"comments": " // Login Credentials",
“url": "http://abc.net/",
”userName": abc,
“password": "123",
}
Specs File Example
"use strict";
//Importing required files
var data = require('../TestData/TestData.json');
var commonCode = require('../CommonUtils/CommonCode.js')
var elementsPage = require('../CommonUtils/ElementsPage.js');
var landingPage = require('../Pages/LandingPage.js');
//* Login scenario for XYZ automation
describe("Login for XYZ - ", function () {
beforeAll(function () {
commonCode.appInitialization(data["url"]);
});
it("Login to the portal", async function () {
abcPage.loginInToTheApplication(elementsPage.emailTextbox,data["username"],elementsPage.passwordTextbox,data
["password"]);
});
});
For UI
Specs File Example
"use strict";
// Importing necessary plugins and required files
var chai = require('chai'),
chaiHttp = require('chai-http');
chai.use(chaiHttp);
var data = require('../TestData/TestData.json');
var commonCode = require('../CommonUtils/CommonCode.js')
var elementsPage = require('../CommonUtils/ElementsPage.js');
// Sample API scenarios
describe("Sample Api test cases - ", function () {
beforeAll(function () {
commonCode.appInitialization(data["adminURL"]);
commonCode.getCookie();
browser.sleep(10000);
});
// Get method with cookie sample
it("GET method with cookie", async function () {
const expect = chai.expect;
await commonCode.getMethodWithCookie(IP, Path, global.cookie).then(function (response) {
console.log(JSON.stringify(response));
console.log(response.status);
console.log(JSON.stringify(response.body));
global.DataOne = response.body.dataOne;
console.log('dataOne : ', response.body.dataOne);
expect(response).to.have.status(data.successStatusCode);
});
});
});
For API
Conf File Example
"use strict";
const log4js = require('log4js');
log4js.configure({
appenders: {
everything: {
type: 'file',
filename:
'testLogs/Execution_Logs_Consolidated.log',
maxLogSize: 10485760,
backups: 3,
compress: true
}
},
categories: {
default: {
appenders: ['everything'],
level: 'debug'
}
}
});
exports.config = {
// Browser use
capabilities: {
'browserName': 'chrome',
//'chromeOptions': {
//'args': ["no-sandbox", "--headless", "--disable-gpu",
"--window-size=800x600"]
//}
},
// Framework selection
framework: 'jasmine2',
// Executing a single test case - "protractor Config.js"
specs: ['./Specs/SampleSpecs.js'],
// Executing suite - "protractor Config.js --suite
spec1,spec2"
suites: {
spec1: [
'Specs/FirstSpecs.js'
],
spec2: [
'Specs/SecondSpecs.js'
]
},
Conf File Example
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 400000,
isVerbose: true,
includeStackTrace: true
},
onPrepare: function () {
var AllureReporter = require('jasmine-allure-reporter');
jasmine.getEnv().addReporter(new AllureReporter({
allureReport: {
resultsDir: 'allure-results'
}
}));
jasmine.getEnv().afterEach(function (done) {
browser.takeScreenshot().then(function (png) {
allure.createAttachment('Screenshot', function () {
return new Buffer(png, 'base64');
}, 'image/png')();
done();
});
});
}
};
Allure Reporting
 For Windows, Allure is available from the Scoop commandline-installer.
 To install Allure, download and install Scoop and then execute in the Powershell:
- scoop install allure
 Also Scoop is capable of updating Allure distribution installations. To do so navigate to the Scoop installation directory and
execute
 bincheckver.ps1 allure -u
 This will check for newer versions of Allure, and update the manifest file. Then execute
- scoop update allure
Alternate commands….
 Using Allure Command Line Tool
 Add the allure-commandline dependency in your current project by running the below command.
- npm install allure-commandline --save-dev
Some Useful NPM commands
 Installing node modules : npm install
 Downgrade npm to specific version: npm install –g npm@2
 Check npm version: npm –version
 Install package locally: npm install package_name
 Install package locally and make an entry in package.json as dependency : npm install package_name --save
 List installed packages: npm ls
 Update npm: npm update
 Clean npm cache: npm cache clean –f
………….
Protractor framework architecture with example
Protractor framework architecture with example
Ad

Recommended

Jquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
Knoldus Inc.
 
Build Web Apps using Node.js
Build Web Apps using Node.js
davidchubbs
 
AngularJS Unit Test
AngularJS Unit Test
Chiew Carol
 
Elefrant [ng-Poznan]
Elefrant [ng-Poznan]
Marcos Latorre
 
Testing in AngularJS
Testing in AngularJS
Peter Drinnan
 
Unit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJS
Knoldus Inc.
 
Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015
Morris Singer
 
Nicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JS
JavaScript Meetup HCMC
 
Vuejs testing
Vuejs testing
Greg TAPPERO
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmine
Timothy Oxley
 
Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJS
Jim Lynch
 
Full Stack Unit Testing
Full Stack Unit Testing
GlobalLogic Ukraine
 
Test Driven Development with JavaFX
Test Driven Development with JavaFX
Hendrik Ebbers
 
Unit testing in JavaScript with Jasmine and Karma
Unit testing in JavaScript with Jasmine and Karma
Andrey Kolodnitsky
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introduction
Nir Kaufman
 
Test like a pro with Ember.js
Test like a pro with Ember.js
Mike North
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and Karma
Christopher Bartling
 
Rapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirage
Krzysztof Bialek
 
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Samyak Bhalerao
 
Reactive Streams and RxJava2
Reactive Streams and RxJava2
Yakov Fain
 
Spring Boot
Spring Boot
Jiayun Zhou
 
Ember testing internals with ember cli
Ember testing internals with ember cli
Cory Forsyth
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
Gil Fink
 
#11.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원학원,재직자/실업자교육학원,스프링교육,마이바...
#11.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원학원,재직자/실업자교육학원,스프링교육,마이바...
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Practical Celery
Practical Celery
Cameron Maske
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma intro
Maurice De Beijer [MVP]
 
Django Celery - A distributed task queue
Django Celery - A distributed task queue
Alex Eftimie
 
Testing Ember Apps: Managing Dependency
Testing Ember Apps: Managing Dependency
Matthew Beale
 
Android UI Testing with Appium
Android UI Testing with Appium
Luke Maung
 
Web UI test automation instruments
Web UI test automation instruments
Artem Nagornyi
 

More Related Content

What's hot (20)

Vuejs testing
Vuejs testing
Greg TAPPERO
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmine
Timothy Oxley
 
Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJS
Jim Lynch
 
Full Stack Unit Testing
Full Stack Unit Testing
GlobalLogic Ukraine
 
Test Driven Development with JavaFX
Test Driven Development with JavaFX
Hendrik Ebbers
 
Unit testing in JavaScript with Jasmine and Karma
Unit testing in JavaScript with Jasmine and Karma
Andrey Kolodnitsky
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introduction
Nir Kaufman
 
Test like a pro with Ember.js
Test like a pro with Ember.js
Mike North
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and Karma
Christopher Bartling
 
Rapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirage
Krzysztof Bialek
 
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Samyak Bhalerao
 
Reactive Streams and RxJava2
Reactive Streams and RxJava2
Yakov Fain
 
Spring Boot
Spring Boot
Jiayun Zhou
 
Ember testing internals with ember cli
Ember testing internals with ember cli
Cory Forsyth
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
Gil Fink
 
#11.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원학원,재직자/실업자교육학원,스프링교육,마이바...
#11.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원학원,재직자/실업자교육학원,스프링교육,마이바...
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Practical Celery
Practical Celery
Cameron Maske
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma intro
Maurice De Beijer [MVP]
 
Django Celery - A distributed task queue
Django Celery - A distributed task queue
Alex Eftimie
 
Testing Ember Apps: Managing Dependency
Testing Ember Apps: Managing Dependency
Matthew Beale
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmine
Timothy Oxley
 
Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJS
Jim Lynch
 
Test Driven Development with JavaFX
Test Driven Development with JavaFX
Hendrik Ebbers
 
Unit testing in JavaScript with Jasmine and Karma
Unit testing in JavaScript with Jasmine and Karma
Andrey Kolodnitsky
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introduction
Nir Kaufman
 
Test like a pro with Ember.js
Test like a pro with Ember.js
Mike North
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and Karma
Christopher Bartling
 
Rapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirage
Krzysztof Bialek
 
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Samyak Bhalerao
 
Reactive Streams and RxJava2
Reactive Streams and RxJava2
Yakov Fain
 
Ember testing internals with ember cli
Ember testing internals with ember cli
Cory Forsyth
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
Gil Fink
 
#11.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원학원,재직자/실업자교육학원,스프링교육,마이바...
#11.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원학원,재직자/실업자교육학원,스프링교육,마이바...
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma intro
Maurice De Beijer [MVP]
 
Django Celery - A distributed task queue
Django Celery - A distributed task queue
Alex Eftimie
 
Testing Ember Apps: Managing Dependency
Testing Ember Apps: Managing Dependency
Matthew Beale
 

Similar to Protractor framework architecture with example (20)

Android UI Testing with Appium
Android UI Testing with Appium
Luke Maung
 
Web UI test automation instruments
Web UI test automation instruments
Artem Nagornyi
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
Visual Engineering
 
Test strategy for web development
Test strategy for web development
alice yang
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
chrisb206 chrisb206
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
SpringPeople
 
Selenium.pptx
Selenium.pptx
Pandiya Rajan
 
Beyond Unit Testing
Beyond Unit Testing
Steve Loughran
 
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
Mek Srunyu Stittri
 
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at Runtime
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at Runtime
NETWAYS
 
Protractor overview
Protractor overview
Abhishek Yadav
 
AngularJS application architecture
AngularJS application architecture
Gabriele Falace
 
Javascript ui for rest services
Javascript ui for rest services
Ioan Eugen Stan
 
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
Boni García
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciolla
Andrea Paciolla
 
Protractor Testing Automation Tool Framework / Jasmine Reporters
Protractor Testing Automation Tool Framework / Jasmine Reporters
Haitham Refaat
 
OWASP ZAP Workshop for QA Testers
OWASP ZAP Workshop for QA Testers
Javan Rasokat
 
Using protractor to build automated ui tests
Using protractor to build automated ui tests
🌱 Dale Spoonemore
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
Ludmila Nesvitiy
 
Complete_QA_Automation_Guide__1696637878.pdf
Complete_QA_Automation_Guide__1696637878.pdf
ramya9288
 
Android UI Testing with Appium
Android UI Testing with Appium
Luke Maung
 
Web UI test automation instruments
Web UI test automation instruments
Artem Nagornyi
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
Visual Engineering
 
Test strategy for web development
Test strategy for web development
alice yang
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
chrisb206 chrisb206
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
SpringPeople
 
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
Mek Srunyu Stittri
 
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at Runtime
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at Runtime
NETWAYS
 
AngularJS application architecture
AngularJS application architecture
Gabriele Falace
 
Javascript ui for rest services
Javascript ui for rest services
Ioan Eugen Stan
 
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
Boni García
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciolla
Andrea Paciolla
 
Protractor Testing Automation Tool Framework / Jasmine Reporters
Protractor Testing Automation Tool Framework / Jasmine Reporters
Haitham Refaat
 
OWASP ZAP Workshop for QA Testers
OWASP ZAP Workshop for QA Testers
Javan Rasokat
 
Using protractor to build automated ui tests
Using protractor to build automated ui tests
🌱 Dale Spoonemore
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
Ludmila Nesvitiy
 
Complete_QA_Automation_Guide__1696637878.pdf
Complete_QA_Automation_Guide__1696637878.pdf
ramya9288
 
Ad

Recently uploaded (20)

PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Quantum AI: Where Impossible Becomes Probable
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Quantum AI: Where Impossible Becomes Probable
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
Ad

Protractor framework architecture with example

  • 2. Introduction  Protractor, formally known as E2E testing framework, is an open source functional automation framework designed specifically for AngularJS web applications. It was introduced during AngularJS 1.2 as a replacement of the existing E2E testing framework. The Protractor automation tool is also recommended by AngularJS for scenario testing.  For an angular app functional automation framework to automate the UI and functionality of the web application, we zeroed in on the Protractor automation tool.
  • 3. Features  Built on the top of WebdriverJS and Selenium server  Introduced new simple syntax to write tests  Allows running tests targeting remote addresses  Can take advantage of Selenium grid to run multiple browsers at once  Can use Jasmine or Mocha to write test suites
  • 4. Benefits  Protractor is a wrapper (built on the top) around Selenium WebDriver, so it contains every feature that is available in the Selenium WebDriver. Additionally, 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.
  • 5. Installation Pre Requisite:  Download and install NodeJS. http://nodejs.org/download/. After installation make sure its path is configured correctly, so that command execution can find Node.
  • 6. Installation…  Open the command prompt and type in the following command to install protractor globally. - npm install –g protractor  Install Protractor Locally You can install protractor locally in your project directory. Go to your project directory and type in the following command in the command prompt: - npm install protractor  Verify Installation To verify your installation, please type in the command - Protractor –version  If Protractor is installed successfully then the system will display the installed version. Otherwise you will have to recheck the installation.  If you don’t have the Selenium server on your machine, then download the latest version onto your machine. If you want to run tests on different browsers, then please download the respective drivers as well. For example, Chrome driver will come in handy to run tests on the Chrome browser.
  • 7. Architecture of Framework Pages : Contains pages and elements(Locators) CommonUtils: Contains common methods or operations used for UI and API automation TestData : Contains constant value and payload in case of API automation Specs: Contains scenario - test cases Conf : Contains configuration and capabilities Reports : Allure reporting - screenshots and reports TestLogs : Contains logs
  • 8. Pages Example "use strict"; //Importing required files var data = require('../TestData/TestData.json'); var commonCode = require('../CommonUtils/CommonCode.js') var elementsPage = require('../CommonUtils/ElementsPage.js'); var log4js = require('log4js'); var logger = log4js.getLogger(); var XYZPage = function () { var EC = protractor.ExpectedConditions; // Login to the application this.loginInToTheApplication = async function (userNameElement,userName,passwordElement, password) { try { commonCode.wait_tillVisible(elementsPage.adminEmailTextbox); commonCode.sendDataToTextBox(userNameElement,userName); commonCode.sendDataToTextBox(passwordElement, password); commonCode.clickAction(elementsPage.loginButton); commonCode.wait_tillVisible(elementsPage.someTitle); expect(elementsPage.someTitle.isDisplayed()).toBe(true); } catch (e) { logger.error('Error while Logging in to the application' + e.message); } }; }; module.exports = new XYZPage(); It is used for UI automation.
  • 9. Common Code Example // To perform Click operation this.clickAction = async function (element) { try { this.wait_tillClickable(element); this.highlightElement(element); element.click(); } catch (e) { logger.error('Error while clicking on the web element' + e.message); } }; For UI
  • 10. Common Code Example // Get method with cookie this.getMethodWithCookie = async function (IP, PATH, COOKIE) { const expect = chai.expect; const chaiHttp1 = chai.request(IP); const response = await chaiHttp1.get(PATH).set(COOKIE); return response; }; For API
  • 11. Elements File Example "use strict"; var ElementsPage = function () { //landingPage this.xyz_button = element.all(by.css('input[value*="xyz"]')).get(0); this.emailTextbox = element(by.css('input[placeholder*="E-mail Address"]')); this.passwordTextbox = element(by.css('input[placeholder*="Password"]')); this.loginButton = element(by.css('button[class*="btn-login-btn"]')); }; module.exports = new ElementsPage();
  • 12. Test Data Example { "comments": " // Login Credentials", “url": "http://abc.net/", ”userName": abc, “password": "123", }
  • 13. Specs File Example "use strict"; //Importing required files var data = require('../TestData/TestData.json'); var commonCode = require('../CommonUtils/CommonCode.js') var elementsPage = require('../CommonUtils/ElementsPage.js'); var landingPage = require('../Pages/LandingPage.js'); //* Login scenario for XYZ automation describe("Login for XYZ - ", function () { beforeAll(function () { commonCode.appInitialization(data["url"]); }); it("Login to the portal", async function () { abcPage.loginInToTheApplication(elementsPage.emailTextbox,data["username"],elementsPage.passwordTextbox,data ["password"]); }); }); For UI
  • 14. Specs File Example "use strict"; // Importing necessary plugins and required files var chai = require('chai'), chaiHttp = require('chai-http'); chai.use(chaiHttp); var data = require('../TestData/TestData.json'); var commonCode = require('../CommonUtils/CommonCode.js') var elementsPage = require('../CommonUtils/ElementsPage.js'); // Sample API scenarios describe("Sample Api test cases - ", function () { beforeAll(function () { commonCode.appInitialization(data["adminURL"]); commonCode.getCookie(); browser.sleep(10000); }); // Get method with cookie sample it("GET method with cookie", async function () { const expect = chai.expect; await commonCode.getMethodWithCookie(IP, Path, global.cookie).then(function (response) { console.log(JSON.stringify(response)); console.log(response.status); console.log(JSON.stringify(response.body)); global.DataOne = response.body.dataOne; console.log('dataOne : ', response.body.dataOne); expect(response).to.have.status(data.successStatusCode); }); }); }); For API
  • 15. Conf File Example "use strict"; const log4js = require('log4js'); log4js.configure({ appenders: { everything: { type: 'file', filename: 'testLogs/Execution_Logs_Consolidated.log', maxLogSize: 10485760, backups: 3, compress: true } }, categories: { default: { appenders: ['everything'], level: 'debug' } } }); exports.config = { // Browser use capabilities: { 'browserName': 'chrome', //'chromeOptions': { //'args': ["no-sandbox", "--headless", "--disable-gpu", "--window-size=800x600"] //} }, // Framework selection framework: 'jasmine2', // Executing a single test case - "protractor Config.js" specs: ['./Specs/SampleSpecs.js'], // Executing suite - "protractor Config.js --suite spec1,spec2" suites: { spec1: [ 'Specs/FirstSpecs.js' ], spec2: [ 'Specs/SecondSpecs.js' ] },
  • 16. Conf File Example jasmineNodeOpts: { showColors: true, defaultTimeoutInterval: 400000, isVerbose: true, includeStackTrace: true }, onPrepare: function () { var AllureReporter = require('jasmine-allure-reporter'); jasmine.getEnv().addReporter(new AllureReporter({ allureReport: { resultsDir: 'allure-results' } })); jasmine.getEnv().afterEach(function (done) { browser.takeScreenshot().then(function (png) { allure.createAttachment('Screenshot', function () { return new Buffer(png, 'base64'); }, 'image/png')(); done(); }); }); } };
  • 17. Allure Reporting  For Windows, Allure is available from the Scoop commandline-installer.  To install Allure, download and install Scoop and then execute in the Powershell: - scoop install allure  Also Scoop is capable of updating Allure distribution installations. To do so navigate to the Scoop installation directory and execute  bincheckver.ps1 allure -u  This will check for newer versions of Allure, and update the manifest file. Then execute - scoop update allure
  • 18. Alternate commands….  Using Allure Command Line Tool  Add the allure-commandline dependency in your current project by running the below command. - npm install allure-commandline --save-dev
  • 19. Some Useful NPM commands  Installing node modules : npm install  Downgrade npm to specific version: npm install –g npm@2  Check npm version: npm –version  Install package locally: npm install package_name  Install package locally and make an entry in package.json as dependency : npm install package_name --save  List installed packages: npm ls  Update npm: npm update  Clean npm cache: npm cache clean –f ………….