SlideShare a Scribd company logo
1 of 21
Better End-to-End Testing With
Page Object Model
Using Protractor
Kasun Kodagoda | Team Finale
Trainee Software Engineer | 99X Technology
Overview
• Protractor
• What is it?
• Getting Up and Running
• Basic Requirements
• Page Objects
• What is it?
• Why Use it?
• A Deeper Dive..
• Demo
Protractor
What Is It?
“Protractor is an end-to-end test framework for AngularJS
applications. Protractor runs tests against your application running in
a real browser, interacting with it as a user would”
Source: Official Protractor Website
What Is It?
• Combination of powerful technologies and tools for testing
Node.js, Selenium, Jasmine, WebDriver, Cucumber, Mocha
• Wrapper for Selenium, made for Angular.js
• Uses angular specific constructs for capturing elements
Model, bindings, repeaters etc.
• Runs on real browsers as well as headless browsers
Get Up And Running..
• Install Node.js
• Install Protractor
npm install –g protractor
• Install WebDriver
webdriver-manager update
• Start WebDriver
webdriver-manager start // do this before you run the tests
Basic Requirements
• You’ll need 2 basic files to start,
• A Test/Spec file
Contains the element references, assertions
• The Configuration File
Contains the configuration options for running protractor
• Use your preferred test framework to write tests
• Jasmine – Fully Supported
• Mocha – Limited Support
• Cucumber – Limited Support
Sample Config File
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome'
},
specs: [
'specs/*Spec.js'
],
jasmineNodeOpts: {
showColors: true
}
};
Sample Test
describe('Test Home Page', function () {
it("Should display the text typed in to the input field.", function () {
browser.get('http://localhost:8080/#/');
// Type in a value to input field
var textInput = element(by.model('sampleInput'));
textInput.sendKeys('The KVK Blog');
// Check if the same value is displayed
var displayField = element(by.binding('sampleInput'));
expect(displayField.getText()).toEqual('The KVK Blog');
});
});
Conventional UI Tests
• Element references are inside tests
• Test are cluttered
• Less readable
• Very fragile
Page Objects Pattern
What Is A Page Object?
“A page object is an object-oriented class that serves as an interface to
a page of your AUT”
• Wraps a HTML page/fragment
• Provide Application Specific API
• Hides the underlying complexity
• Used to manipulate elements on page
Why Use Page Objects?
• Reduce Code Duplication
• Reusable Page Objects
• More Readable Tests
• Less Vulnerable to Break
• More Maintainable Tests
Especially in Agile Based Projects
A Deeper Dive…
Return Types
• Methods in Page Objects should return fundamental types
Strings, Dates, Booleans
• It can return other complex types as well
Promises, other Page Objects
A Deeper Dive…
• Method names can be much closer to what the user is actually doing.
var inputField = element(by.model(‘first_name’);
inputField.sendKeys(‘Kasun’);
Or
element(by.model(‘first_name’)).sendKeys(‘Kasun’);
Instead We can use
somePage.addFirstName(‘Kasun’);
A Deeper Dive…
The Dilemma
• Use of assertions
• Include Assertions inside Page Objects
• Not Include Assertions inside Page Objects
• It’s Subjective and the Choice is yours…
A Deeper Dive…
No Assertions in Page Objects for Us. Why??
• Separation of Responsibility
• Page Objects should only provide access to HTML pages
• Page Objects become longer
A Deeper Dive…
What We Believe
“If what we test changes, The assertions and the tests should change”
“If the HTML page changes, The Page Object should change”
This,
• Allows us to easily modify the tests/specs when functionality or
underlying HTML pages change overtime
http://goo.gl/MFNy9C
https://github.com/kasunkv/e2e-sample-app.git
Demo
You Have NO Questions…
Right?... ;)
Thank You
For Not Throwing Rocks At Me ^_^

More Related Content

What's hot

What's hot (20)

An Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using ProtractorAn Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using Protractor
 
Automated Web Testing using JavaScript
Automated Web Testing using JavaScriptAutomated Web Testing using JavaScript
Automated Web Testing using JavaScript
 
Automated Testing using JavaScript
Automated Testing using JavaScriptAutomated Testing using JavaScript
Automated Testing using JavaScript
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015
 
Angular UI Testing with Protractor
Angular UI Testing with ProtractorAngular UI Testing with Protractor
Angular UI Testing with Protractor
 
Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to Protractor
 
Jellyfish, JSCONF 2011
Jellyfish, JSCONF 2011Jellyfish, JSCONF 2011
Jellyfish, JSCONF 2011
 
APIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page ObjectsAPIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page Objects
 
Automation using Javascript
Automation using JavascriptAutomation using Javascript
Automation using Javascript
 
Better Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component PatternBetter Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component Pattern
 
Front-End Testing: Demystified
Front-End Testing: DemystifiedFront-End Testing: Demystified
Front-End Testing: Demystified
 
Automated Testing in Angular Slides
Automated Testing in Angular SlidesAutomated Testing in Angular Slides
Automated Testing in Angular Slides
 
Testing Code.org's Interactive CS Curriculum
Testing Code.org's Interactive CS CurriculumTesting Code.org's Interactive CS Curriculum
Testing Code.org's Interactive CS Curriculum
 
Join the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.jsJoin the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.js
 
Testing nightwatch, by David Torroija
Testing nightwatch, by David TorroijaTesting nightwatch, by David Torroija
Testing nightwatch, by David Torroija
 
How to Use Selenium, Successfully
How to Use Selenium, SuccessfullyHow to Use Selenium, Successfully
How to Use Selenium, Successfully
 
Selenium for Jobseekers
Selenium for JobseekersSelenium for Jobseekers
Selenium for Jobseekers
 
Automated Smoke Tests with Protractor
Automated Smoke Tests with ProtractorAutomated Smoke Tests with Protractor
Automated Smoke Tests with Protractor
 
Intro to Service Worker API and its use cases
Intro to Service Worker API and its use casesIntro to Service Worker API and its use cases
Intro to Service Worker API and its use cases
 
Selenium with protractor
Selenium with protractorSelenium with protractor
Selenium with protractor
 

Viewers also liked

интернет в социологии важнейшие информационные сайты дадададад)))
интернет в социологии   важнейшие информационные сайты дадададад)))интернет в социологии   важнейшие информационные сайты дадададад)))
интернет в социологии важнейшие информационные сайты дадададад)))
faqMEN
 
Presentation_Protractor
Presentation_ProtractorPresentation_Protractor
Presentation_Protractor
Umesh Randhe
 

Viewers also liked (19)

Protractor: Tips & Tricks
Protractor: Tips & TricksProtractor: Tips & Tricks
Protractor: Tips & Tricks
 
Sharing the pain using Protractor
Sharing the pain using ProtractorSharing the pain using Protractor
Sharing the pain using Protractor
 
Test Data - Food for your Test Automation Framework
Test Data - Food for your Test Automation FrameworkTest Data - Food for your Test Automation Framework
Test Data - Food for your Test Automation Framework
 
Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to Protractor
 
Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSIntro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJS
 
Testing Backbone applications with Jasmine
Testing Backbone applications with JasmineTesting Backbone applications with Jasmine
Testing Backbone applications with Jasmine
 
Jasmine framework
Jasmine frameworkJasmine framework
Jasmine framework
 
интернет в социологии важнейшие информационные сайты дадададад)))
интернет в социологии   важнейшие информационные сайты дадададад)))интернет в социологии   важнейшие информационные сайты дадададад)))
интернет в социологии важнейшие информационные сайты дадададад)))
 
Automated Acceptance Testing Example
Automated Acceptance Testing ExampleAutomated Acceptance Testing Example
Automated Acceptance Testing Example
 
The sweet smell of jasmine for testing JavaScript
The sweet smell of jasmine for testing JavaScriptThe sweet smell of jasmine for testing JavaScript
The sweet smell of jasmine for testing JavaScript
 
Advanced Jasmine
Advanced JasmineAdvanced Jasmine
Advanced Jasmine
 
Testing Angular 2 Applications - HTML5 Denver 2016
Testing Angular 2 Applications - HTML5 Denver 2016Testing Angular 2 Applications - HTML5 Denver 2016
Testing Angular 2 Applications - HTML5 Denver 2016
 
20150128 angular js_headless_testing
20150128 angular js_headless_testing20150128 angular js_headless_testing
20150128 angular js_headless_testing
 
Thinking outside the box (SOX)
Thinking outside the box (SOX)Thinking outside the box (SOX)
Thinking outside the box (SOX)
 
10 Tips For Serverless Backends With NodeJS and AWS Lambda
10 Tips For Serverless Backends With NodeJS and AWS Lambda10 Tips For Serverless Backends With NodeJS and AWS Lambda
10 Tips For Serverless Backends With NodeJS and AWS Lambda
 
Angular Testing
Angular TestingAngular Testing
Angular Testing
 
Presentation_Protractor
Presentation_ProtractorPresentation_Protractor
Presentation_Protractor
 
ProtractorJS for automated testing of Angular 1.x/2.x applications
ProtractorJS for automated testing of Angular 1.x/2.x applicationsProtractorJS for automated testing of Angular 1.x/2.x applications
ProtractorJS for automated testing of Angular 1.x/2.x applications
 
Protractor powerpoint
Protractor powerpointProtractor powerpoint
Protractor powerpoint
 

Similar to Better End-to-End Testing with Page Objects Model using Protractor

Similar to Better End-to-End Testing with Page Objects Model using Protractor (20)

DSL, Page Object and WebDriver – the path to reliable functional tests.pptx
DSL, Page Object and WebDriver – the path to reliable functional tests.pptxDSL, Page Object and WebDriver – the path to reliable functional tests.pptx
DSL, Page Object and WebDriver – the path to reliable functional tests.pptx
 
DSL, Page Object и WebDriver – путь к надежным функциональным тестам
DSL, Page Object и WebDriver – путь к надежным функциональным тестамDSL, Page Object и WebDriver – путь к надежным функциональным тестам
DSL, Page Object и WebDriver – путь к надежным функциональным тестам
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
 
Mastering react with redux
Mastering react with reduxMastering react with redux
Mastering react with redux
 
Better Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component PatternBetter Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component Pattern
 
AngularJS One Day Workshop
AngularJS One Day WorkshopAngularJS One Day Workshop
AngularJS One Day Workshop
 
Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014
 
Quick start with AngularJS
Quick start with AngularJSQuick start with AngularJS
Quick start with AngularJS
 
Become a Full Stack Web Developer (.NET) - Thisiswali
Become a Full Stack Web Developer (.NET) - ThisiswaliBecome a Full Stack Web Developer (.NET) - Thisiswali
Become a Full Stack Web Developer (.NET) - Thisiswali
 
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
 
Galen Framework - Responsive Design Automation
Galen Framework - Responsive Design AutomationGalen Framework - Responsive Design Automation
Galen Framework - Responsive Design Automation
 
Galenframework
GalenframeworkGalenframework
Galenframework
 
Galenframework
GalenframeworkGalenframework
Galenframework
 
Selenium Online Training
Selenium  Online TrainingSelenium  Online Training
Selenium Online Training
 
Testing-Tools-Magnitia-Content.pdf
Testing-Tools-Magnitia-Content.pdfTesting-Tools-Magnitia-Content.pdf
Testing-Tools-Magnitia-Content.pdf
 
Selenium-with-Java-Course-Content-Magnitia.pdf
Selenium-with-Java-Course-Content-Magnitia.pdfSelenium-with-Java-Course-Content-Magnitia.pdf
Selenium-with-Java-Course-Content-Magnitia.pdf
 
Selenium-with-Java-Course-Content-Magnitia.pdf
Selenium-with-Java-Course-Content-Magnitia.pdfSelenium-with-Java-Course-Content-Magnitia.pdf
Selenium-with-Java-Course-Content-Magnitia.pdf
 
Selenium Online Training
Selenium Online Training Selenium Online Training
Selenium Online Training
 
Angular patterns
Angular patternsAngular patterns
Angular patterns
 
Kevin Whinnery: Write Better JavaScript
Kevin Whinnery: Write Better JavaScriptKevin Whinnery: Write Better JavaScript
Kevin Whinnery: Write Better JavaScript
 

More from Kasun Kodagoda

More from Kasun Kodagoda (15)

Using GitHub Actions to Deploy your Workloads to Azure
Using GitHub Actions to Deploy your Workloads to AzureUsing GitHub Actions to Deploy your Workloads to Azure
Using GitHub Actions to Deploy your Workloads to Azure
 
Feature Toggle for .Net Core Apps on Azure with Azure App Configuration Featu...
Feature Toggle for .Net Core Apps on Azure with Azure App Configuration Featu...Feature Toggle for .Net Core Apps on Azure with Azure App Configuration Featu...
Feature Toggle for .Net Core Apps on Azure with Azure App Configuration Featu...
 
Get On Top of Azure Resource Security Using Secure DevOps Kit for Azure
Get On Top of Azure Resource Security Using Secure DevOps Kit for AzureGet On Top of Azure Resource Security Using Secure DevOps Kit for Azure
Get On Top of Azure Resource Security Using Secure DevOps Kit for Azure
 
Centralized Configuration Management for the Cloud with Azure App Configuration
Centralized Configuration Management for the Cloud with Azure App ConfigurationCentralized Configuration Management for the Cloud with Azure App Configuration
Centralized Configuration Management for the Cloud with Azure App Configuration
 
Serverless in the Azure World
Serverless in the Azure WorldServerless in the Azure World
Serverless in the Azure World
 
Role of Test Automation in Modern Software Delivery Pipelines
Role of Test Automation in Modern Software Delivery PipelinesRole of Test Automation in Modern Software Delivery Pipelines
Role of Test Automation in Modern Software Delivery Pipelines
 
Demystifying Azure Certifications
Demystifying Azure CertificationsDemystifying Azure Certifications
Demystifying Azure Certifications
 
Good Bye Credentials in Code, Welcome Azure Managed Identities
Good Bye Credentials in Code, Welcome Azure Managed IdentitiesGood Bye Credentials in Code, Welcome Azure Managed Identities
Good Bye Credentials in Code, Welcome Azure Managed Identities
 
DevOps: Why Should We Care?
DevOps: Why Should We Care?DevOps: Why Should We Care?
DevOps: Why Should We Care?
 
Introduction to Microsoft Azure
Introduction to Microsoft AzureIntroduction to Microsoft Azure
Introduction to Microsoft Azure
 
Building Custom Visual Studio Team Service Build Tasks With VSTS DevOps Task SDK
Building Custom Visual Studio Team Service Build Tasks With VSTS DevOps Task SDKBuilding Custom Visual Studio Team Service Build Tasks With VSTS DevOps Task SDK
Building Custom Visual Studio Team Service Build Tasks With VSTS DevOps Task SDK
 
Building a Continuous Delivery Pipeline With Visual Studio
Building a Continuous Delivery Pipeline With Visual StudioBuilding a Continuous Delivery Pipeline With Visual Studio
Building a Continuous Delivery Pipeline With Visual Studio
 
Going Serverless with Azure Functions #1 - Introduction to Azure Functions
Going Serverless with Azure Functions #1 - Introduction to Azure FunctionsGoing Serverless with Azure Functions #1 - Introduction to Azure Functions
Going Serverless with Azure Functions #1 - Introduction to Azure Functions
 
Making Money with Technology
Making Money with TechnologyMaking Money with Technology
Making Money with Technology
 
Monetizing Windows Phone Apps
Monetizing Windows Phone AppsMonetizing Windows Phone Apps
Monetizing Windows Phone Apps
 

Recently uploaded

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
 

Better End-to-End Testing with Page Objects Model using Protractor

  • 1. Better End-to-End Testing With Page Object Model Using Protractor Kasun Kodagoda | Team Finale Trainee Software Engineer | 99X Technology
  • 2. Overview • Protractor • What is it? • Getting Up and Running • Basic Requirements • Page Objects • What is it? • Why Use it? • A Deeper Dive.. • Demo
  • 4. What Is It? “Protractor is an end-to-end test framework for AngularJS applications. Protractor runs tests against your application running in a real browser, interacting with it as a user would” Source: Official Protractor Website
  • 5. What Is It? • Combination of powerful technologies and tools for testing Node.js, Selenium, Jasmine, WebDriver, Cucumber, Mocha • Wrapper for Selenium, made for Angular.js • Uses angular specific constructs for capturing elements Model, bindings, repeaters etc. • Runs on real browsers as well as headless browsers
  • 6. Get Up And Running.. • Install Node.js • Install Protractor npm install –g protractor • Install WebDriver webdriver-manager update • Start WebDriver webdriver-manager start // do this before you run the tests
  • 7. Basic Requirements • You’ll need 2 basic files to start, • A Test/Spec file Contains the element references, assertions • The Configuration File Contains the configuration options for running protractor • Use your preferred test framework to write tests • Jasmine – Fully Supported • Mocha – Limited Support • Cucumber – Limited Support
  • 8. Sample Config File exports.config = { seleniumAddress: 'http://localhost:4444/wd/hub', capabilities: { 'browserName': 'chrome' }, specs: [ 'specs/*Spec.js' ], jasmineNodeOpts: { showColors: true } };
  • 9. Sample Test describe('Test Home Page', function () { it("Should display the text typed in to the input field.", function () { browser.get('http://localhost:8080/#/'); // Type in a value to input field var textInput = element(by.model('sampleInput')); textInput.sendKeys('The KVK Blog'); // Check if the same value is displayed var displayField = element(by.binding('sampleInput')); expect(displayField.getText()).toEqual('The KVK Blog'); }); });
  • 10. Conventional UI Tests • Element references are inside tests • Test are cluttered • Less readable • Very fragile
  • 12. What Is A Page Object? “A page object is an object-oriented class that serves as an interface to a page of your AUT” • Wraps a HTML page/fragment • Provide Application Specific API • Hides the underlying complexity • Used to manipulate elements on page
  • 13. Why Use Page Objects? • Reduce Code Duplication • Reusable Page Objects • More Readable Tests • Less Vulnerable to Break • More Maintainable Tests Especially in Agile Based Projects
  • 14. A Deeper Dive… Return Types • Methods in Page Objects should return fundamental types Strings, Dates, Booleans • It can return other complex types as well Promises, other Page Objects
  • 15. A Deeper Dive… • Method names can be much closer to what the user is actually doing. var inputField = element(by.model(‘first_name’); inputField.sendKeys(‘Kasun’); Or element(by.model(‘first_name’)).sendKeys(‘Kasun’); Instead We can use somePage.addFirstName(‘Kasun’);
  • 16. A Deeper Dive… The Dilemma • Use of assertions • Include Assertions inside Page Objects • Not Include Assertions inside Page Objects • It’s Subjective and the Choice is yours…
  • 17. A Deeper Dive… No Assertions in Page Objects for Us. Why?? • Separation of Responsibility • Page Objects should only provide access to HTML pages • Page Objects become longer
  • 18. A Deeper Dive… What We Believe “If what we test changes, The assertions and the tests should change” “If the HTML page changes, The Page Object should change” This, • Allows us to easily modify the tests/specs when functionality or underlying HTML pages change overtime
  • 20. You Have NO Questions… Right?... ;)
  • 21. Thank You For Not Throwing Rocks At Me ^_^