1
Browser Test Automation (in 2018)
@
ColinBendell
CTO Office,
Cloudinary
Slide 2
Slide 3
Agenda
Te s t M e t h o d o l o g i e s
We bDr i ve r. i o
Mocha tests
How Browsers Work & Browser APIs
We b Pl at for m Te st
Mobile & Device Emulation
Accessibility
Operational: DNS, Paralyzing, CI
Real User Testing
9:00 AM
Welcome |
10:30 AM
Break |
12:00 AM
Lunch |
2:30 PM
Break |
4:00 PM
Wrap
up & Q&A
Slide 4
Cloudinary's
Two Probl ems
Felix
Zilber
New Digital
Asset
Management Front
End
Automating CDN Changes
Slide 5
5
Why Do We Test?
Slide 6
Slide 7
Slide 8
Slide 9
Slide 10
10
Te s t i n g : P r e p a r e f o r t h e U n e x p e c t e d
Slide 11
“I just want to buy my Mom’s
birthday present.”
“I just want to know if it will rain
today.”
“I just want to share pictures of
my vacation”
Slide 12
Te s t i n g = = = M e e t i n g U s e r E x p e c t a t i o n s
Slide 13
Te s t i n g M o d e l s
Slide 14
Kinds of Testing
https://
stackoverflow.com
/questions/2741832/unit
tests
vs
functional
tests
Slide 15
Functional v. Non
Functional
Slide 16
Unit Testing
•
Smallest testable component
•
Usually simple inputs and outputs
•
Moch
objects v. skeleton dev services
Slide 17
Unit Testing
const
expect
require(
"chai"
).expect;
const
converter
require(
"../app/converter"
);
describe(
"Color Code Converter"
,
function
()
{
describe(
"RGB to Hex conversion"
,
function
()
{
it(
"converts the basic colors"
,
function
()
{
var
redHex
Unit Testing
•
Blurred line to integration tests
•
Encourages small component logic v. monoliths
•
Large volume of Tests
Slide 19
Integration Tests
Slide 20
Integration Tests
describe(
"Color Code Converter API"
,
function
()
{
describe(
"RGB to Hex conversion"
,
function
()
{
let
url
"http://localhost:3000/
rgbToHex?red
=255&green=255&blue=255"
;
it(
"returns status 200"
,
function
()
{});
it(
"returns the color in hex"
,
function
()
{});
});
describe(
"Hex to RGB conversion"
,
function
()
{
let
url
= "http://localhost:3000/
hexToRgb?hex
=00ff00"
;
it(
"returns status 200"
,
function
()
{});
it(
"returns the color in RGB"
,
function
()
{});
});
});
Slide 21
System Tests
•
Does it match design?
•
Meet expectations of design
•
Often focused on workflows
•
Vol ume, l oad, stress, securi ty
•
Usability, Accessibility
Slide 22
System Tests
Slide 23
Slide 24
Acceptance Tests
•
Meet business objectives
•
End
to
End
•
Can the end user accomplish what we wanted it to do?
•
Alpha/Beta Feedback cycle
Slide 25
Kinds of Testing
Slide 26
“We develop in the Zoo,
But release in the Jungle”
Melanie
Cey
Slide 27
Kinds of Testing
https://
stackoverflow.com
/questions/2741832/unit
tests
vs
functional
tests
Slide 28
Why do we need browser testing
•
Functional User experience
•
Wo r k f l o ws
•
Design & Layout
•
Preserve Presentation
•
Above the fold, responsive web
•
Mobi l e experi ences v. Watch v. ??
•
Accessibility
•
Screen readers
•
audits
•
Performance measurement
•
Performance budgets
•
Request flows
“…25% of new Android phones
have only 512MB of RAM.
”
Jen Fitzpatrick
VP of product management for Google Maps
Slide 38
Browser Based
Te s t i n g
Slide 39
How do we test the Browser?
•
Checklists
•
Support
tickets
•
Screen capture
•
Pixel comparison
•
Programmatic control
•
RUM Beacons
Slide 40
#1 reason checklists fail to
catch browser regression:
Humans
Slide 41
open
a Safari https://
cloudinary.com
killall
Safari
screencapture
x
testoutput.png
compare
identify
metric MAE
baseline.png
testoutput.png
null
same1.png[0] PNG 640x400 640x400+0+0 8
bit
DirectClass
1.64KB 0.010u 0:00.019
same2.jpg[0] JPEG 640x400 640x400+0+0 8
bit
DirectClass
3.65KB 0.000u 0:00.009
0.196766 (3.00245e
Slide 42
open
a Safari https://
cloudinary.com
killall
Safari
screencapture
x
testoutput.png
compare
identify
metric MAE
baseline.png
testoutput.png
null
same1.png[0] PNG 640x400 640x400+0+0 8
bit
DirectClass
1.64KB 0.010u 0:00.019
same2.jpg[0] JPEG 640x400 640x400+0+0 8
bit
DirectClass
3.65KB 0.000u 0:00.009
0.196766 (3.00245e
Slide 43
open
a Safari https://
cloudinary.com
killall
Safari
screencapture
x
testoutput.png
compare
identify
metric MAE
baseline.png
testoutput.png
null
same1.png[0] PNG 640x400 640x400+0+0 8
bit
DirectClass
1.64KB 0.010u 0:00.019
same2.jpg[0] JPEG 640x400 640x400+0+0 8
bit
DirectClass
3.65KB 0.000u 0:00.009
0.196766 (3.00245e
Slide 44
open
a Safari https://
cloudinary.com
killall
Safari
screencapture
x
testoutput.png
compare
identify
metric MAE
baseline.png
testoutput.png
null
same1.png[0] PNG 640x400 640x400+0+0 8
bit
DirectClass
1.64KB 0.010u 0:00.019
same2.jpg[0] JPEG 640x400 640x400+0+0 8
bit
DirectClass
3.65KB 0.000u 0:00.009
0.196766 (3.00245e
Slide 45
Slide 46
How do we test the Browser?
•
Checklists
•
Support
tickets
•
Screen capture
•
Pixel comparison
•
Programmatic control
•
RUM Beacons
Slide 47
OS API application control
•
Access the window model directly
•
Simulate Keyboard strokes and mouse movements
•
Interact with any application like a human
•
Screen Readers use this approach to supersede the OS accessibility features
Slide 48
Programmatic Control
Slide 49
How do we test the Browser?
•
Checklists
•
Support
tickets
•
Screen capture
•
Pixel comparison
•
Programmatic control
•
RUM Beacons
Slide 50
Slide 51
Slide 52
Slide 53
Slide 54
Slide 55
Selenium Evolution
•
Selenium
•
Selenium Core
•
Selenium RC
Selenium 1
•
Selenium WebDriver
Selenium 2
•
We b D r i v e r
Selenium 3
Gecko Driver (+Marionette)
Chrome Driver
EdgeDriver
Apple Safari Driver
Firefox Driver
Safari Driver
…
https://
www.seleniumhq.org
/download/
We bDr i ve r. i o
We b Dr i ve r
(or Selenium Grid)
ChromeDriver
GeckoDriver
SafariDriver
EdgeDriver
OperaDriver
Browsers
Chrome
Firefox
Safari
Edge
Opera
WebDriver
Wire Protocol
HTTP
HTTP
NodeJS
?
Where do you want to execute your tests?
On my local machine
?
Which framework do you want to use?
mocha
?
Shall I install the framework adapter for you?
Yes
?
Where are your test specs located?
./
src
/**/*_
spec.js
?
Which reporter do you want to use?
dot,
allure
?
Shall I install the reporter library for you?
Yes
?
Do you want to add a service to your test setup?
Chromedriver
?
Shall I install the services for you?
Yes
?
Level of logging verbosity
error
?
In which directory should screenshots gets saved if a command
fails?
./
errorShots
/
?
What is the base
url
?
http://localhost
Slide 87
Exercise 2:
Wo r k f l o w
Te s t
Adding
TODO spec
Install mocha, chai, allure
create
wdio.conf.js
Navigate to
todomvc.com
Using Angular implementation:
•
add a
To D o
•
marking it complete
•
clear the list
Slide 88
Slide 89
Slide 90
Slide 91
Slide 92
Exercise 3:
POM spec
Repeat Exercise 2
Use Page Object Model
Simplify Allure output with
wdio
allure
ts
Slide 93
Ta ke A c t i o n
•
Create workflows easily with mocha
•
Use a Page
Object
Model to abstract selectors for reduced maintenance
•
Create good & actionable outputs
Slide 94
How Browsers Work
Slide 95
How
Browsers Are
Supposed
to work
Slide 96
Slide 97
Slide 98
Page Load Time: Seconds
Slide 99
Slide 100
2 Second Magic Number
Page Load Time: Seconds
Slide 101
Slide 102
!
"
!
50ms
DNS Lookup
100ms
ShoesByColin.com
8.8.8.8
Slide 103
!
"
!
50ms
DNS Lookup
100ms
ShoesByColin.com
8.8.8.8
HTML
DOM
JavaScript
CSS
Render
Tr e e
Layout
Paint
CSSOM
Images
Video
JS Exec
Slide 110
Browser APIs
Slide 111
Real User Monitoring: JavaScript Timers
Steve
Souders
Philip
Te l l i s
https://
github.com
/
stevesouders
/episodes
https://
github.com
/lognormal/boomerang
Slide 112
Slide 113
https://www.w3.org/wiki/
We b_ Pe r fo r manc e
/Publications
let
url
= “https://
bendell.ca
/
logo.png
”;
let me =
performance.getEntriesByName
(
url
)[0];
let timings = {
loadTime
:
me.
duration
,
dns
:
me.
domainLookupEnd
me.
domainLookupStart
,
tcp
:
me.
connectEnd
me.
connectStart
,
waiting:
me.
responseStart
me.
requestStart
,
fetch:
me.
responseEnd
me.
responseStart
}
Slide 125
200 OK HTTP/1.1
Timing
Allow
Origin: *
Content
Type: application/
javascript
Content
Length: 1234
Slide 126
•
Slowest resources
•
Time to first image
•
Response time by domain
•
Time a group of assets
•
Response time by initiator type (element type)
•
Browser cache
hit ratio for resources
•
Resource Timing API
•
Other Uses
More:
http://www.slideshare.net/bluesmoon/beyond
page
level
metrics
Slide 127
Slide 128
How long does it
take to display the
main product
image on my site?
Slide 129
function
loadTemplate
() {
performance.mark
(“
startTask
”);
doTemplateStuff
() //do stuff (assumes promise())
.then(() => {
performance.mark
(“
stopTask
”);
//Measure the duration between the two marks
performance.measure
(“
taskDuration
”,
“
startTask
”,“
stopTask
”);
});
}
Exercise 4:
performance
budget
Navigate to
amazon.com
Calculate the total bytes downloaded
Ensure that the page load time < 2s
and bytes < 2MiB
Repeat with
Disney.com
Slide 140
Ta ke A c t i o n
•
Add
performance.mark
() to measure YOUR key metrics
•
Eg
: Hero Image, Product Image, Sport Scores
•
Keep
performance.mark
() in production code!
•
Define Hard and Soft targets that synthetic tests should hit
•
BHAG: 2s & 1MiB
Ta ke A c t i o n
•
Run Tests in different viewport configurations to test RWD
•
Experiment with different Network Conditions
•
Similarly with different CPU throttling
Exercise 5:
WPT
Implement Responsive Images
and Test the
naturalWidth
Slide 156
A11y
with AXE
Léonie
Watson
Marcy Sutton
Katie
Sylor
Miller
Slide 157
“Websites, tools, and technologies are
designed and developed so that people with
disabilities can use them
.”
ACCESSIBILITY (a11y
)
W3C Web Accessibility Initiative
Slide 158
THE AMERICANS WITH DISABILITIES ACT (ADA)
“No individual shall be discriminated against on
the basis of disability in the full and equal
enjoyment of the goods, services, facilities,
privileges, advantages, or accommodations of any
place of
public accommodation
”
ADA Sec. 12182 (a)
Slide 159
AMERICANS WITH A DISABILITY
UNITED STATES CENSUS REPORT, JULY 2012
57 M
19%
Slide 160
Slide 161
Slide 162
The Basics
•
We b Conte nt Ac c e s s i bi l i t y Gui de l i ne s ( WCAG 2. 0)
•
Developed by the W3C Web Accessibility Three levels of compliance
A, AA, AAA
Slide 163
Slide 164
Slide 165
Exercise 6:
A11y
Add axe
core
npm
Load 3 news websites
Compare the violations
Create a test case to fail on a11y
violations
Slide 166
Ta ke A c t i o n
•
Good Usability === Good Accessibility
•
Use Semantic HTML (also great for SEO)
•
Add alt and description tags to media and anchors
•
Te s t y o u r s i t e ( a x e
Synthetic
Real
•
Consistent
•
Precise CPU,
Network use
•
Availability
•
Engagement
•
Business
Metrics (Rev)
•
Market Segment
•
Layout
•
Design
Slide 175
Slide 176
Slide 177
Slide 178
Ta ke A c t i o n
•
Collect Real
User browser
exerpiences
•
Audit user experience (load time, downloaded content)
•
Periodically run tests in the wild
•
Add
window.addEventListener
(‘error’) to capture console errors
•
Use Beacon API to ensure metrics are returned
Slide 179
Summary
•
Browser testing is easy!
•
Synthetic testing with:
•
We b Dr i ve r. i o
for easy functional testing
•
We b Pa ge Te st . org
to augment performance testing
•
Use
We bPl at for mTe st
for direct platform tests
•
Don’t just test workflows:
Design, Performance, and Accessibility
•
Use Real
User feedback to compare tests in the wild
Slide 180
@
ColinBendell
Slide 181
Further Reading
•
http://
webdri ver. i o
/
api.html
•
https://
github.com
/
cloudinary
/
wdi o
allure
ts
•
https://
github.com
/
cloudinary
/
wdi o
allure
ts
example
•
https://
www.npmjs.com
/package/
webdri ver
manager
•
http://
blog.kevinlamping.com
/testing
your
login
an
in
depth
webdri veri o
tutorial/
•
https://
www.browserstack.com
/automate/
webdri veri o
•
https://
medi um. com
/@
boriscoder
/setting
up
selenium
tests
wi th
webdri ver
io
cc7fc3c86629
•
https://w3c.github.io/
webdri ver
/
•
https://
www.slideshare.net
/
LinkMeSrl
/
webdri veri o?qi d
=8cdf045d
Agenda
Te s t M e t h o d o l o g i e s
We bDr i ve r. i o
Mocha tests
How Browsers Work & Browser APIs
We b Pl at for m Te st
Mobile & Device Emulation
Accessibility
Operational: DNS, Paralyzing, CI
Real User Testing
9:00 AM
Welcome |
10:30 AM
Break |
12:00 AM
Lunch |
2:30 PM
Break |
4:00 PM
Wrap
up & Q&A
Slide 183
Break
10:30
10:45 AM
183
Slide 184
Lunch
11:50 AM
–
12:30 AM
184
Lunch
12:00 PM
–
1:00PM