SlideShare a Scribd company logo
UI Testing with Protractor
Andrew Eisenberg
Tasktop Technologies
• Sr. Software Engineer @
Tasktop Technologies
• PhD from UBC in programming
languages & IDEs
A Cautionary Tale
100% Code Coverage!!!
…but I was playing the wrong game.
Testing an app in 7+ easy steps
1. Installing and running Protractor
2. First tests
3. Creating test scenarios
4. Real tests
5. Synchronicity and Asynchronicity
6. Page object pattern
7. Debugging, screen capture, and other tips
8. Discussion items and gotchas
BACKGROUND
Step 0
Kinds of testing
• Unit testing
• Integration testing
• System testing (or Functional testing)
– UI Testing Using Protractor
A simplification!
What is Protractor?
• “End-to-End testing”
– Well, not really. Just UI testing
• Built to work with AngularJS
• Built on top of Selenium
• Is a node app
http://www.thoughtwo
rks.com/insights/blog/
testing-angularjs-apps-
protractor
When should I use Protractor?
• UI stable
• Use cases well
established
• Already unit-tested
• Uses AngularJS
• UI unstable
• Use cases in flux
• Not unit-tested
• Doesn’t use
AngularJS
Do it Avoid
INSTALLING AND RUNNING
PROTRACTOR
Step 1
Installing and running Protractor
• Install node/npm from https://nodejs.org/
• Install protractor, grunt
– npm install -g protractor
– npm install -g grunt-cli
• Update webdriver
– webdriver-manager update
Getting tutorial code
• git clone https://github.com/aeisenberg/angular-app.git
• cd angular-app
• git checkout qia-step-1
• Open file: Quality-in-Agile-Protractor-Tutorial.md
• Follow instructions in file
Run the app and play
user: andrew.eisenberg@gmail.com
pass: nuthing
FIRST TESTS
Step 2
Protractor & Jasmine
describe('Home Page', function () {
it('should be the default page',
function () {
browser.get(browser.baseUrl);
expect(browser.getCurrentUrl())
.toEqual(browser.baseUrl +
'projectsinfo');
});
});
Let’s Code!
• Getting started
– git checkout qia-step-2-before
• If you get stuck:
– git checkout qia-step-2-after
SKETCHING TEST SCENARIOS
Step 3
Authentication
User
management
Project
management
Backlog
management
Sprint
management
USE CASE-BASED TEST SCENARIOS
Step 4
ElementFinder
element(by.css(‘#run-command’));
element(by.css(‘#run-command’)).isPresent();
element(by.css(‘button.command’)).click();
element.all(by.css(‘button.command’))
.click();
element(by.css(‘#my-input’)).getText();
element(by.cssContainingText
(‘button.command’, ‘Run’)).click();
browser.waitForAngular();
Let’s Code!
• Getting started
– git checkout qia-step-4-before
• If you get stuck:
– git checkout qia-step-4-after
MORE COMPLEX TEST
Step 5
Secretly, everything is a promise
This throws an exception:
This does not:
var text = element(
by.css(‘#my-input’)).getText();
expect(text.split(‘,’)[0]).toBe(‘sumthin’);
var text = element(
by.css(‘#my-input’)).getText();
expect(text).toContain(‘sumthin’);
JavaScript Promises
• (Eventually) contains result of computation
• Asynchronous programming
• Composable, chainable, and…FUN!
• A standard
promise.then(function(result) {
verify(result);
}).then(function(result) {
display(result);
});
ElementFinder returns promise
element(by.css(‘#my-input’))
.sendKeys(‘Hello’)
.getText()
.then(function(text) {
console.log(text);
});
All ElementFinder methods return promises
element(by.css(‘#my-button’)).click();
element(by.css(‘#my-button’))
.isDisplayed();
element(by.css(‘#my-button’))
.click()
.isDisplayed();
element(by.css(‘#my-button’))
.click().then(function() {
element(by.css(‘#my-button’))
.isDisplayed();
});
Protractor and `expect`
• expect accepts promises
– delays execution until promise is resolved
var text = element(
by.css(‘#my-input’)).getText();
expect(text.split(‘,’)[0]).toBe(‘sumthin’);
var text = element(
by.css(‘#my-input’)).getText();
expect(text).toContain(‘sumthin’);
Let’s Code!
• Getting started
– git checkout qia-step-5-before
• If you get stuck:
– git checkout qia-step-5-after
PAGEOBJECT PATTERN
Step 6
The PageObject pattern
• Readable DSL for tests
• Promotes reuse
• Centralizes UI coupling
PageObject Big Idea
• Extract CSS ugliness
– element(by.css('#login')).click();
• Into semantically meaningful actions
– loginPage.openDialog();
Tests do not touch DOM directly
var loginPage = new require(‘./LoginPage)();
loginPage.login(‘a.b@gmail.com’, ‘secret’);
expect(loginPage.isLoggedIn().toBeTruthy();
loginPage.logout();
Let’s Code!
• Page Object Skeleton
– git checkout qia-step-6-before
• Getting started
– git checkout qia-step-6-middle
• If you get stuck:
– git checkout qia-step-6-after
DEBUGGING AND OTHER FUN
THINGS
Step 7
Let’s Code!
• Getting started
– git checkout qia-step-7
Focused tests
• fit & fdescribe
• Focus protractor
– on a single test or set of tests
Debug mode
• protractor debug protractor.conf.js
• Enter node’s debugger
– debugger;
• Enter debugger (webdriver aware)
– browser.debugger();
• Enter debugger (new feature doesn’t work too
well)
– browser.pause();
Element Explorer
• protractor --elementExplorer
• Interactive invoking of webdriver commands
Interactive login
> element(by.css('#login')).click()
>
> element(by.css('#login-email')
.sendKeys(’a.b@gmail.com')
>
> element(by.css('#login-password')
.sendKeys(’nuthin')
>
> element(by.css('#do-login')).click()
Screenshots
browser.takeScreenshot().then(function(png) {
var stream = fs.createWriteStream(filename);
stream.write(new Buffer(png, 'base64'));
stream.end();
});
Jasmine reporters
• Hook into jasmine spec lifecycle
– before/after test/suite/jasmine
• Things to do
– Format test results
– Grab screenshot on failure
– Cleanup before/after tests
– Start/stop resources
– …
Do something on failure
jasmine.getEnv().addReporter({
specDone: function(result) {
if (result.failedExpectations
.length > 0) {
console.log(‘I am a failure…’);
}
}
});
SOME PHILOSOPHICAL QUESTIONS
What should be unit
tested?
What should be UI
tested?
How much refactoring
in production code is
appropriate?
Should test use id
attributes or complex
CSS expressions?
THE TRUTH BEHIND PROTRACTOR
It ain’t perfect
• Timing problems
• Difficult to debug
• Inconsistent behavior
• Failures hard to reproduce
• Expensive to maintain
• Tests can be slow
Protractor is appropriate
• When…
– Using AngularJS
– UI is mature
– Front end is well unit-tested
– Use cases well described
• Until then…
…use manual automation
Protractor is…
• For UI testing
• AngularJS-aware
• Secretly powered by Selenium
• Asynchronous and event-based
• A powerful and clean way to test UI
But…
• Expensive to maintain
Questions?
• andrew.eisenberg@gmail.com
• twitter: @werdnagreb
• https://github.com/aeisenberg/angular-app

More Related Content

What's hot (20)

PPTX
Protractor survival guide
László Andrási
 
PDF
Join the darkside: Selenium testing with Nightwatch.js
Seth McLaughlin
 
PPTX
Better End-to-End Testing with Page Objects Model using Protractor
Kasun Kodagoda
 
PPTX
Browser Automated Testing Frameworks - Nightwatch.js
Luís Bastião Silva
 
PPTX
Automated Smoke Tests with Protractor
🌱 Dale Spoonemore
 
DOCX
Protractor end-to-end testing framework for angular js
codeandyou forums
 
PDF
Testing nightwatch, by David Torroija
David Torroija
 
KEY
Jellyfish, JSCONF 2011
Adam Christian
 
PDF
Front-End Testing: Demystified
Seth McLaughlin
 
PPTX
Automated Testing using JavaScript
Simon Guest
 
PDF
Introduction to Protractor
Florian Fesseler
 
ZIP
Automated Frontend Testing
Neil Crosby
 
PPTX
Nightwatch JS for End to End Tests
Sriram Angajala
 
PDF
Automated Testing in Angular Slides
Jim Lynch
 
PPTX
Automation using Javascript
khanhdang1214
 
PPTX
Using protractor to build automated ui tests
🌱 Dale Spoonemore
 
PDF
Nightwatch at Tilt
Dave King
 
PPT
Testing in AngularJS
Peter Drinnan
 
PDF
Unit-testing and E2E testing in JS
Michael Haberman
 
PDF
Testing Web Applications
Seth McLaughlin
 
Protractor survival guide
László Andrási
 
Join the darkside: Selenium testing with Nightwatch.js
Seth McLaughlin
 
Better End-to-End Testing with Page Objects Model using Protractor
Kasun Kodagoda
 
Browser Automated Testing Frameworks - Nightwatch.js
Luís Bastião Silva
 
Automated Smoke Tests with Protractor
🌱 Dale Spoonemore
 
Protractor end-to-end testing framework for angular js
codeandyou forums
 
Testing nightwatch, by David Torroija
David Torroija
 
Jellyfish, JSCONF 2011
Adam Christian
 
Front-End Testing: Demystified
Seth McLaughlin
 
Automated Testing using JavaScript
Simon Guest
 
Introduction to Protractor
Florian Fesseler
 
Automated Frontend Testing
Neil Crosby
 
Nightwatch JS for End to End Tests
Sriram Angajala
 
Automated Testing in Angular Slides
Jim Lynch
 
Automation using Javascript
khanhdang1214
 
Using protractor to build automated ui tests
🌱 Dale Spoonemore
 
Nightwatch at Tilt
Dave King
 
Testing in AngularJS
Peter Drinnan
 
Unit-testing and E2E testing in JS
Michael Haberman
 
Testing Web Applications
Seth McLaughlin
 

Viewers also liked (10)

PPTX
Angles and Measuring (degrees quiz)
Karen N. Jackson Ed.D
 
PPTX
Angles: Classifications; Measuring; and Drawing
James Smith
 
PPT
Protractor powerpoint
lindarousselle
 
PDF
Protractor: Tips & Tricks
Sergey Bolshchikov
 
PDF
Introduction to Protractor
Jie-Wei Wu
 
PPT
Angle Relationships Power Point
malissatrotter
 
PDF
Angles powerpoint
guestdd350
 
PPTX
Lines and angles
Soumya Sankar Modak
 
PPTX
Using a protractor
fknights
 
PPS
Line And Angle Relationships
sedanor
 
Angles and Measuring (degrees quiz)
Karen N. Jackson Ed.D
 
Angles: Classifications; Measuring; and Drawing
James Smith
 
Protractor powerpoint
lindarousselle
 
Protractor: Tips & Tricks
Sergey Bolshchikov
 
Introduction to Protractor
Jie-Wei Wu
 
Angle Relationships Power Point
malissatrotter
 
Angles powerpoint
guestdd350
 
Lines and angles
Soumya Sankar Modak
 
Using a protractor
fknights
 
Line And Angle Relationships
sedanor
 
Ad

Similar to Protractor Tutorial Quality in Agile 2015 (20)

PPTX
Mobile developer is Software developer
Eugen Martynov
 
PPTX
Testing Ext JS and Sencha Touch
Mats Bryntse
 
PDF
Top100summit 谷歌-scott-improve your automated web application testing
drewz lin
 
PPTX
Testing ASP.NET - Progressive.NET
Ben Hall
 
PDF
UI Testing Best Practices - An Expected Journey
Oren Farhi
 
PDF
React Native: The Development Flow
Ritesh Kumar
 
PDF
Detecting headless browsers
Sergey Shekyan
 
PDF
Angular Application Testing
Troy Miles
 
PDF
Automating Django Functional Tests Using Selenium on Cloud
Jonghyun Park
 
PPTX
Automation - web testing with selenium
Tzirla Rozental
 
PDF
Android UI Testing with Espresso
Gary Cheng
 
PPTX
Java script unit testing
Mats Bryntse
 
PDF
TDD: Develop, Refactor and Release With Confidence
Mehdi Valikhani
 
PDF
O365Con18 - Implementing Automated UI Testing for SharePoint Solutions - Elio...
NCCOMMS
 
PPTX
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Roy de Kleijn
 
KEY
Javascript unit testing, yes we can e big
Andy Peterson
 
PPTX
Cross Platform Appium Tests: How To
GlobalLogic Ukraine
 
PDF
CBDW2014 - MockBox, get ready to mock your socks off!
Ortus Solutions, Corp
 
PDF
Web UI test automation instruments
Artem Nagornyi
 
PPTX
[NDC 2019] Enterprise-Grade Serverless
KatyShimizu
 
Mobile developer is Software developer
Eugen Martynov
 
Testing Ext JS and Sencha Touch
Mats Bryntse
 
Top100summit 谷歌-scott-improve your automated web application testing
drewz lin
 
Testing ASP.NET - Progressive.NET
Ben Hall
 
UI Testing Best Practices - An Expected Journey
Oren Farhi
 
React Native: The Development Flow
Ritesh Kumar
 
Detecting headless browsers
Sergey Shekyan
 
Angular Application Testing
Troy Miles
 
Automating Django Functional Tests Using Selenium on Cloud
Jonghyun Park
 
Automation - web testing with selenium
Tzirla Rozental
 
Android UI Testing with Espresso
Gary Cheng
 
Java script unit testing
Mats Bryntse
 
TDD: Develop, Refactor and Release With Confidence
Mehdi Valikhani
 
O365Con18 - Implementing Automated UI Testing for SharePoint Solutions - Elio...
NCCOMMS
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Roy de Kleijn
 
Javascript unit testing, yes we can e big
Andy Peterson
 
Cross Platform Appium Tests: How To
GlobalLogic Ukraine
 
CBDW2014 - MockBox, get ready to mock your socks off!
Ortus Solutions, Corp
 
Web UI test automation instruments
Artem Nagornyi
 
[NDC 2019] Enterprise-Grade Serverless
KatyShimizu
 
Ad

Recently uploaded (20)

PDF
Top 10 Testing Procedures to Ensure Your Magento to Shopify Migration Success...
CartCoders
 
PPTX
Metaphysics_Presentation_With_Visuals.pptx
erikjohnsales1
 
PDF
Enhancing Parental Roles in Protecting Children from Online Sexual Exploitati...
ICT Frame Magazine Pvt. Ltd.
 
PDF
Cleaning up your RPKI invalids, presented at PacNOG 35
APNIC
 
PDF
The Internet - By the numbers, presented at npNOG 11
APNIC
 
PPTX
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
PDF
Boardroom AI: The Next 10 Moves | Cerebraix Talent Tech
ssuser73bdb11
 
PPTX
Networking_Essentials_version_3.0_-_Module_3.pptx
ryan622010
 
PDF
BRKACI-1001 - Your First 7 Days of ACI.pdf
fcesargonca
 
PDF
FutureCon Seattle 2025 Presentation Slides - You Had One Job
Suzanne Aldrich
 
PPTX
Networking_Essentials_version_3.0_-_Module_5.pptx
ryan622010
 
PDF
BRKSP-2551 - Introduction to Segment Routing.pdf
fcesargonca
 
PPTX
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
PPTX
西班牙巴利阿里群岛大学电子版毕业证{UIBLetterUIB文凭证书}文凭复刻
Taqyea
 
PPTX
Orchestrating things in Angular application
Peter Abraham
 
PPTX
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
PDF
BRKACI-1003 ACI Brownfield Migration - Real World Experiences and Best Practi...
fcesargonca
 
PPTX
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
PPTX
PHIPA-Compliant Web Hosting in Toronto: What Healthcare Providers Must Know
steve198109
 
PPTX
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
Top 10 Testing Procedures to Ensure Your Magento to Shopify Migration Success...
CartCoders
 
Metaphysics_Presentation_With_Visuals.pptx
erikjohnsales1
 
Enhancing Parental Roles in Protecting Children from Online Sexual Exploitati...
ICT Frame Magazine Pvt. Ltd.
 
Cleaning up your RPKI invalids, presented at PacNOG 35
APNIC
 
The Internet - By the numbers, presented at npNOG 11
APNIC
 
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
Boardroom AI: The Next 10 Moves | Cerebraix Talent Tech
ssuser73bdb11
 
Networking_Essentials_version_3.0_-_Module_3.pptx
ryan622010
 
BRKACI-1001 - Your First 7 Days of ACI.pdf
fcesargonca
 
FutureCon Seattle 2025 Presentation Slides - You Had One Job
Suzanne Aldrich
 
Networking_Essentials_version_3.0_-_Module_5.pptx
ryan622010
 
BRKSP-2551 - Introduction to Segment Routing.pdf
fcesargonca
 
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
西班牙巴利阿里群岛大学电子版毕业证{UIBLetterUIB文凭证书}文凭复刻
Taqyea
 
Orchestrating things in Angular application
Peter Abraham
 
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
BRKACI-1003 ACI Brownfield Migration - Real World Experiences and Best Practi...
fcesargonca
 
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
PHIPA-Compliant Web Hosting in Toronto: What Healthcare Providers Must Know
steve198109
 
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 

Protractor Tutorial Quality in Agile 2015