serenity-js.org#SerenityJS @JanMolak
Jan Molak:
Testing modern web apps.
At scale.
serenity-js.org#SerenityJS @JanMolak
Jan Molak
consultant, trainer, mentor, geek


janmolak.com

jan.molak@smartcodeltd.co.uk

twitter.com/JanMolak
linkedin.com/in/janmolak
github.com/jan-molak
serenity-js.org#SerenityJS @JanMolak
Testing larger-scale projects
serenity-js.org#SerenityJS @JanMolak
Good automated tests
serenity-js.org#SerenityJS @JanMolak
Good automated tests are FAST
John Ferguson Smart
serenity-js.org#SerenityJS @JanMolak
Good automated tests are FAST
Fast
Actionable
Scalable
Trustworthy
serenity-js.org#SerenityJS @JanMolak
Testing a User Story
serenity-js.org#SerenityJS @JanMolak
Find the fastest route
As a commuter,

I’d like to know the fastest route between two stations,

So that I get to my destination as quickly as possible
serenity-js.org#SerenityJS @JanMolak
Find the fastest route
As a commuter,

I’d like to know the fastest route between two stations,

So that I get to my destination as quickly as possible
before? after?
serenity-js.org#SerenityJS @JanMolak
Find the fastest route
As a commuter,

I’d like to know the fastest route between two stations,

So that I get to my destination as quickly as possible
BDD
regression

testing
limited testing opportunities
UI-heavy
slow and “flaky”
verify, don’t validate
testability built in
business-focused
validate and verify
VS
serenity-js.org#SerenityJS @JanMolak
Find the fastest route
As a commuter,

I’d like to know the fastest route between two stations,

So that I get to my destination as quickly as possible
BDD
Scenario:	Connie	looks	for	the	next	train	
Given	Jubilee	line	trains	leave	Canary	Wharf	at	16:59,	17:01

	When	Connie	wants	to	travel	from	Canary	Wharf	to	Waterloo	at	17:00

	Then	she	should	be	told	about	the	train	at	17:01
serenity-js.org#SerenityJS @JanMolak
Find the fastest route
As a commuter,

I’d like to know the fastest route between two stations,

So that I get to my destination as quickly as possible
BDD
Scenario:	Connie	looks	for	the	next	train	
Given	Jubilee	line	trains	from	Stratford	leave	Canary	Wharf	at	16:59,	17:01

	When	Connie	wants	to	travel	from	Canary	Wharf	to	Waterloo	at	17:00

	Then	she	should	be	told	about	the	train	at	17:01
serenity-js.org#SerenityJS @JanMolak
Find the fastest route
As a commuter,

I’d like to know the fastest route between two stations,

So that I get to my destination as quickly as possible
BDD
Scenario:	Connie	looks	for	the	next	train	
Given	Jubilee	line	trains	from	Stratford	leave	Canary	Wharf	at	16:59,	17:01

	When	Connie	wants	to	travel	from	Canary	Wharf	to	Waterloo	at	17:00

	Then	she	should	be	told	about	the	train	at	17:01
serenity-js.org#SerenityJS @JanMolak
Find the fastest route
As a commuter,

I’d like to know the fastest route between two stations,

So that I get to my destination as quickly as possible
BDD
Scenario:	Connie	looks	for	the	next	train	
Given	Jubilee	line	trains	from	Stratford	leave	Canary	Wharf	

↪	at	16:59,	17:01,	17:03,	17:09,	17:11

	When	Connie	wants	to	travel	from	Canary	Wharf	to	Waterloo	at	17:00

	Then	she	should	be	told	about	the	trains	at	17:01,	17:03,	17:09
serenity-js.org#SerenityJS @JanMolak
“44-80%

of all software defects are caused by unclear, 

ambiguous or incorrect requirements
sources:
- 44% - “Out of Control - Why Control Systems Go Wrong and How to Prevent Failure”
- 56% - “An Information Systems Manifesto”
- 80% - “Requirements: A quick and inexpensive way to improve testing”
serenity-js.org#SerenityJS @JanMolak
Executable specifications
serenity-js.org#SerenityJS @JanMolak
System under test
The system is a black box
Tests should exercise the system as the user would
Outside-in development
serenity-js.org#SerenityJS @JanMolak
System under test
Limited testing opportunities
UI-heavy
Slow and “flaky”
serenity-js.org#SerenityJS @JanMolak
System under test
Carrier 12:00 PM
Page Title
http://www.domain.com Google
… and duplicated :-/
serenity-js.org#SerenityJS @JanMolak
Manual
“Test Pyramid”,

Mike Cohn
“Software Testing Ice Cream Cone Anti-pattern”,
Alister Scott
serenity-js.org#SerenityJS @JanMolak
How do we fix that?
serenity-js.org#SerenityJS @JanMolak
serenity-js.org#SerenityJS @JanMolak
Forget about the pyramid
¯_(ツ)_/¯
serenity-js.org#SerenityJS @JanMolak
tech business
fast

cheap
precise
slow

expensive
broad
?
feedback
audience
unit tests
acceptance

tests
end-to-end,

integration,
contract,

performance

tests
serenity-js.org#SerenityJS @JanMolak
Executable specifications

at multiple levels
serenity-js.org#SerenityJS @JanMolak
serenity-js.org#SerenityJS @JanMolak
System under test
Carrier 12:00 PM
Page Title
http://www.domain.com Google
serenity-js.org#SerenityJS @JanMolak
System under test
Carrier 12:00 PM
Page Title
http://www.domain.com Google
Web

Interface
REST

Interface
Domain

Services
serenity-js.org#SerenityJS @JanMolak
System under test
Carrier 12:00 PM
Page Title
http://www.domain.com Google
Web

Interface
REST

Interface
Domain

Services
actors interactions interfaces business logic
serenity-js.org#SerenityJS @JanMolak
System under test
Carrier 12:00 PM
Page Title
http://www.domain.com Google
Web

Interface
REST

Interface
Domain

Services
actors interactions interfaces business logic
business logic adapters
serenity-js.org#SerenityJS @JanMolak
System under test
Carrier 12:00 PM
Page Title
http://www.domain.com Google
Web

Interface
REST

Interface
Domain

Services
actors interactions interfaces business logic
serenity-js.org#SerenityJS @JanMolak
System under test
Carrier 12:00 PM
Page Title
http://www.domain.com Google
Web

Interface
REST

Interface
Domain

Services
actors interactions interfaces business logic
serenity-js.org#SerenityJS @JanMolak
System under test
Carrier 12:00 PM
Page Title
http://www.domain.com Google
Web

Interface
REST

Interface
Domain

Services
actors interactions interfaces business logic
serenity-js.org#SerenityJS @JanMolak
Scenario decomposition
serenity-js.org#SerenityJS @JanMolak
scenario decomposition
step When	Connie	wants	to	travel	from	Canary	Wharf	to	Waterloo	at	17:00
serenity-js.org#SerenityJS @JanMolak
scenario decomposition
step When	Connie	wants	to	travel	from	Canary	Wharf	to	Waterloo	at	17:00
actor Connie
serenity-js.org#SerenityJS @JanMolak
scenario decomposition
step When	Connie	wants	to	travel	from	Canary	Wharf	to	Waterloo	at	17:00
goal
actor Connie
Plan a journey
serenity-js.org#SerenityJS @JanMolak
scenario decomposition
Open the
Journey
Planner
tasks
step When	Connie	wants	to	travel	from	Canary	Wharf	to	Waterloo	at	17:00
Plan a journeygoal
actor Connie
serenity-js.org#SerenityJS @JanMolak
scenario decomposition
Open the
Journey
Planner
Choose
origin
step When	Connie	wants	to	travel	from	Canary	Wharf	to	Waterloo	at	17:00
Plan a journeygoal
actor Connie
tasks
serenity-js.org#SerenityJS @JanMolak
scenario decomposition
Open the
Journey
Planner
Choose
origin
Choose
destination
step When	Connie	wants	to	travel	from	Canary	Wharf	to	Waterloo	at	17:00
Plan a journeygoal
actor Connie
tasks
serenity-js.org#SerenityJS @JanMolak
scenario decomposition
Open the
Journey
Planner
Choose
origin
Choose
destination
Choose time
of departure
step When	Connie	wants	to	travel	from	Canary	Wharf	to	Waterloo	at	17:00
Plan a journeygoal
actor Connie
tasks
serenity-js.org#SerenityJS @JanMolak
scenario decomposition
Open the
Journey
Planner
Choose
origin
Choose
destination
Choose time
of departure
Confirm
selection
step When	Connie	wants	to	travel	from	Canary	Wharf	to	Waterloo	at	17:00
Plan a journeygoal
actor Connie
tasks
serenity-js.org#SerenityJS @JanMolak
scenario decomposition
Open the
Journey
Planner
Choose

origin
Choose
destination
Choose time

of departure
Confirm
selection
Enter
“Canary
Wharf”
Pick 

the first
suggestion
Press
[Arrow
Down]
Press
[Enter]interactions
step When	Connie	wants	to	travel	from	Canary	Wharf	to	Waterloo	at	17:00
Plan a journeygoal
actor Connie
tasks
serenity-js.org#SerenityJS @JanMolak
scenario decomposition
Open the
Journey Planner
Choose

origin
Choose
destination
Choose time

of departure
Confirm
selection
step When	Connie	wants	to	travel	from	Canary	Wharf	to	Waterloo	at	17:00
Plan a journeygoal
actor Connie
tasks
PlanAJourney.from(‘Canary	Wharf’)

				.to(‘Waterloo’)

				.departingAt(‘17:00’)
serenity-js.org#SerenityJS @JanMolak
scenario decomposition
Open the
Journey Planner
Choose

origin
tasks
OpenTheJourneyPlanner()
ChooseOrigin.of(‘Canary	Wharf’)
ChooseDestination.of(‘Waterloo’)
ChooseTime.ofDeparture(‘17:00’)
ConfirmSelection()
step When	Connie	wants	to	travel	from	Canary	Wharf	to	Waterloo	at	17:00
Plan a journeygoal
actor Connie
PlanAJourney.from(‘Canary	Wharf’)

				.to(‘Waterloo’)

				.departingAt(‘17:00’)
Choose
destination
Choose time

of departure
Confirm
selection
serenity-js.org#SerenityJS @JanMolak
scenario decomposition
Send GET
request
Request.get(‘https://api.tfl.gov.uk/

↪	Journey/JourneyResults/

↪	Canary%20Wharf/to/Waterloo

↪	?time=1700’)
step When	Connie	wants	to	travel	from	Canary	Wharf	to	Waterloo	at	17:00
Plan a journeygoal
actor Connie
tasks
PlanAJourney.from(‘Canary	Wharf’)

				.to(‘Waterloo’)

				.departingAt(‘17:00’)
serenity-js.org#SerenityJS @JanMolak
scenario decomposition
Send domain
event
JourneyPlanner.find({

		origin:	‘Canary	Wharf’,

		destination:	‘Waterloo’,

		departing_at:	’17:00’

});
step When	Connie	wants	to	travel	from	Canary	Wharf	to	Waterloo	at	17:00
Plan a journeygoal
actor Connie
PlanAJourney.from(‘Canary	Wharf’)

				.to(‘Waterloo’)

				.departingAt(‘17:00’)
tasks
serenity-js.org#SerenityJS @JanMolak
The Screenplay Pattern
serenity-js.org#SerenityJS @JanMolak
the screenplay pattern
“Page Objects Refactored”,

Antony Marcano, Andy Palmer,

John Ferguson Smart, Jan Molak
serenity-js.org#SerenityJS @JanMolak
the screenplay pattern
serenity-js.org#SerenityJS @JanMolak
the screenplay pattern
serenity-js.org#SerenityJS @JanMolak
the screenplay pattern
serenity-js.org#SerenityJS @JanMolak
the screenplay pattern
serenity-js.org#SerenityJS @JanMolak
the screenplay pattern
serenity-js.org#SerenityJS @JanMolak
the screenplay pattern
serenity-js.org#SerenityJS @JanMolak
the screenplay pattern
serenity-js.org#SerenityJS @JanMolak
the screenplay pattern
serenity-js.org#SerenityJS @JanMolak
Where does Serenity/JS fit?
serenity-js.org#SerenityJS @JanMolak
the big picture
Web AppBrowsersSelenium

WebDriver
Node.js
protractor
CLI
cucumbermocha
serenity-js
serenity-js.org#SerenityJS @JanMolak
the big picture
Web AppBrowsersSelenium

WebDriver
Node.js
protractor
CLI
cucumbermocha
serenity-js
Any external interface of the system
…
serenity-js.org#SerenityJS @JanMolak
Levels of communication
serenity-js.org#SerenityJS @JanMolak
actor tasks interfaces business logic
System under test
Web

Interface
REST

Interface
Domain

Services
serenity-js.org#SerenityJS @JanMolak
actor tasks
System under test
Web

Interface
REST

Interface
Domain

Services
scenarios
find next train
serenity-js.org#SerenityJS @JanMolak
actor
System under test
Web

Interface
REST

Interface
Domain

Services
scenarios
find next train
tasksfeatures
journey
planner
serenity-js.org#SerenityJS @JanMolak
actor
System under test
Web

Interface
REST

Interface
Domain

Services
scenarios
find next train
tasksfeatures
journey
planner
offline map
service
disruption
notifications
capabilities
plan a
journey

online
serenity-js.org#SerenityJS @JanMolak
levels of communication
10,000 ft

Release Readiness
-
+
serenity-js.org#SerenityJS @JanMolak
levels of communication
1000 ft

Capabilities and Features
-
+
serenity-js.org#SerenityJS @JanMolak
levels of communication
100 ft

Scenarios and Steps
-
+
serenity-js.org#SerenityJS @JanMolak
levels of communication
release
readiness
-
+
serenity-js.org#SerenityJS @JanMolak
levels of communication
-
+
release
readiness
capabilities
serenity-js.org#SerenityJS @JanMolak
levels of communication
-
+
release
readiness
capabilities
features
serenity-js.org#SerenityJS @JanMolak
levels of communication
-
+
release
readiness
capabilities
features
scenarios
serenity-js.org#SerenityJS @JanMolak
Key benefits
serenity-js.org#SerenityJS @JanMolak
key benefits
Focus

on the user journey
and a common
business vocabulary
Scales well

to teams with
varying levels of
experience
Good design
principles 

leading to lower
maintenance costs
Code reuse 

within and across
teams and projects
serenity-js.org#SerenityJS @JanMolak
Q&A
serenity-js.org#SerenityJS @JanMolak
Lights, camera, demo!
serenity-js.org

github.com/serenity-js

Testing modern webapps. At scale.