SlideShare a Scribd company logo
1 of 48
The
Screenplay
Pattern
A SOLID alternative
@AntonyMarcano
riverglide.com
Contributions, quotations & references in:
2
All code is…
Seriously
Hindered
In
Testing?
Inspired by Simon Stewart’s opening keynote at Selenium Conf 2016…
Knowledge of programming
All code is…
Seriously
Hindered
In
Translation?
Inspired by Simon Stewart’s opening keynote at Selenium Conf 2016…
Expressing intent
All code is…
Seriously
Hindered
In
Transformation?
Inspired by Simon Stewart’s opening keynote at Selenium Conf 2016…
Ease of refactoring
Just enough to give confidence
that the product hangs together
for the key usage examples
DON’T try to prove that
absolutely everything
works together in
absolutely every way
that the whole product
is supposed to
The Screenplay pattern is as a way of
separating any kind of interactions with your
product, including RESTful APIs, Web or
any form of interaction.
For the purposes of this talk, we’re going to
focus on page objects…
http://bit.ly/rg-todomvc
Support code using Page
Objects
Todo List Page
newTodo
todoItems
todosRemaining
toggleAllButton
clearCompletedButton
filterTodos
…
addATodoItem()
addTodoItems()
toggleAllCompleted()
filterItems()
…
Responsibilities
How to find page elements
How a user completes given tasks
Let’s go back in
time…
“Selenium is not unstable, and your tests
don’t need to be flaky. […] When your tests
are flaky, do some root cause analysis to
understand why they’re flaky. It’s very
seldom because you’ve uncovered a bug in
the test framework.”
-Simon Stewart, Google Testing Blog 2009, “My Selenium Tests Aren't
Stable!”
http://bit.ly/rg-pageobject-example
What’s wrong with this?
“A code smell is a surface indication that
usually corresponds to a deeper problem in
the system. The term was first coined by
Kent Beck while helping me with my
Refactoring book.”
-Martin Fowler
Code Smell:
“Large Class”
What can help us refactor
to a better design?
SOLID
Single Responsibility Principle
Open Closed Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
Let’s focus on…
Single Responsibility Principle
Open Closed Principle
Single Responsibility Principle
“If a class has more than one responsibility,
then the responsibilities become coupled.
Changes to one responsibility may impair or
inhibit the class’ ability to meet the others.
This kind of coupling leads to fragile designs
that break in unexpected ways when
changed.”
-Robert Martin, Agile Principles, Patterns & Practices
Open Closed Principle
The Open Closed Principle (coined by
Bertrand Meyer in Object-Oriented Software
Construction) states that a class should be
open for extension, but closed for
modification. This means that it should be
possible to extend behaviour by writing a
new class without changing existing,
working code.
http://bit.ly/rg-todomvc
Todo List Page
newTodo
todoItems
todosRemaining
toggleAllButton
clearCompletedButton
filterTodos
…
addATodoItem()
addTodoItems()
toggleAllCompleted()
filterItems()
…
Responsibilities
How to find page elements
How a user completes given tasks
Todo List Page
newTodo
todoItems
todosRemaining
toggleAllButton
clearCompletedButton
filterTodos
…
addATodoItem()
addTodoItems()
toggleAllCompleted()
filterItems()
…
TodoListPage
newTodo
todoItems
todosRemaining
toggleAllButton
clearCompletedButton
filterTodos
…
TodoListTasks
addATodoItem()
addTodoItems()
toggleAllCompleted()
filterItems()
…
Extract Class
Extract Class
Todo List Page
newTodo
todoItems
todosRemaining
toggleAllButton
clearCompletedButton
filterTodos
…
addATodoItem()
addTodoItems()
toggleAllCompleted()
filterItems()
…
AddNewTodo
newTodo
addTodoItem ()
addTodoItems()
MaintainTodos
toggleAllButton
clearCompletedButton
toggleAllCompleted()
clearAllCompletedTodos()
Extract Class
Extract Class
Todo List Page
newTodo
todoItems
todosRemaining
toggleAllButton
clearCompletedButton
filterTodos
…
addATodoItem()
addTodoItems()
toggleAllCompleted()
filterItems()
…
TodoListPage
newTodo
todoItems
todosRemaining
toggleAllButton
clearCompletedButton
filterTodos
…
AddATodoItem
perform()
Extract Class
Replace Method
with Method Object
AddTodoItems
perform()
ToggleAllCompleted
perform()
What are we modeling?
Modelling the problem
Not the solution
The Screenplay Pattern
There are actors.
Actors have abilities.
Actors perform tasks…
Tasks involve ‘actions’
Things we interact with are just data
Instead of a few
large classes,
you have more
smaller classes.
When you identify
a new task an
actor must
perform, just add
a new task class.
You don’t have to use cucumber for this either…
Example using Screenplay implementation in Serenity-BDD
Your scenario is a narrative for a cast of
actors, each playing a different role. Each
actor has the task of performing action to
the best of their ability…
The Screenplay Pattern
The Screenplay Pattern
Before you begin
Don’t aim to refactor all of your support
code.
Try an experiment alongside what you have.
See how it feels and if you like it, look at
how to use the approach with new
scenarios.
In Summary
• As any support code grows, ask first “are
we testing too much here?”
• Big classes with interaction methods (like
PageObjects) are useful as training
wheels
• As we try to go faster, training wheels
make us less stable
• The Screenplay Pattern allows us to ride
more safely, at speed, from the start
Links
Full article: bit.ly/rg-screenplay
Examples on Github: bit.ly/rg-serenity-eg
using Serenity
Acknowledgements
Andy Palmer
John Ferguson Smart & Jan Molak
Contact: antony@riverglide.com
http://antonymarcano.com/blog
@AntonyMarcano
Materials created with the time, love and attention of
Antony Marcano and Andy Palmer

More Related Content

What's hot

Strategic Appplication Development with Domain-Driven Design (DDD)
Strategic Appplication Development with Domain-Driven Design (DDD)Strategic Appplication Development with Domain-Driven Design (DDD)
Strategic Appplication Development with Domain-Driven Design (DDD)
Dennis Traub
 

What's hot (20)

Strategic Appplication Development with Domain-Driven Design (DDD)
Strategic Appplication Development with Domain-Driven Design (DDD)Strategic Appplication Development with Domain-Driven Design (DDD)
Strategic Appplication Development with Domain-Driven Design (DDD)
 
Node js Modules and Event Emitters
Node js Modules and Event EmittersNode js Modules and Event Emitters
Node js Modules and Event Emitters
 
Programmazione funzionale e Stream in Java
Programmazione funzionale e Stream in JavaProgrammazione funzionale e Stream in Java
Programmazione funzionale e Stream in Java
 
jQuery Effects
jQuery EffectsjQuery Effects
jQuery Effects
 
Optimizing Magento by Preloading Data
Optimizing Magento by Preloading DataOptimizing Magento by Preloading Data
Optimizing Magento by Preloading Data
 
Specification-By-Example with Gherkin
Specification-By-Example with GherkinSpecification-By-Example with Gherkin
Specification-By-Example with Gherkin
 
The Screenplay Pattern: Better Interactions for Better Automation
The Screenplay Pattern: Better Interactions for Better AutomationThe Screenplay Pattern: Better Interactions for Better Automation
The Screenplay Pattern: Better Interactions for Better Automation
 
Drools
DroolsDrools
Drools
 
메타버스 서비스에 Android 개발자가 할 일이 있나요?
메타버스 서비스에 Android 개발자가 할 일이 있나요?메타버스 서비스에 Android 개발자가 할 일이 있나요?
메타버스 서비스에 Android 개발자가 할 일이 있나요?
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Docker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | Edureka
Docker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | EdurekaDocker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | Edureka
Docker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | Edureka
 
自動車ってどうやってハッキングするんですか? @IoTSecJP #2 by @_tokina23
自動車ってどうやってハッキングするんですか? @IoTSecJP #2 by @_tokina23自動車ってどうやってハッキングするんですか? @IoTSecJP #2 by @_tokina23
自動車ってどうやってハッキングするんですか? @IoTSecJP #2 by @_tokina23
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
레퍼런스만 알면 언리얼 엔진이 제대로 보인다
레퍼런스만 알면 언리얼 엔진이 제대로 보인다레퍼런스만 알면 언리얼 엔진이 제대로 보인다
레퍼런스만 알면 언리얼 엔진이 제대로 보인다
 
Corso js and angular
Corso js and angularCorso js and angular
Corso js and angular
 
A journey beyond the page object pattern
A journey beyond the page object patternA journey beyond the page object pattern
A journey beyond the page object pattern
 
Rule Engine & Drools
Rule Engine & DroolsRule Engine & Drools
Rule Engine & Drools
 
상상을 현실로 만드는, 이미지 생성 모델을 위한 엔지니어링
상상을 현실로 만드는, 이미지 생성 모델을 위한 엔지니어링상상을 현실로 만드는, 이미지 생성 모델을 위한 엔지니어링
상상을 현실로 만드는, 이미지 생성 모델을 위한 엔지니어링
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#
 

Viewers also liked

Viewers also liked (10)

Serenity and the Journey Pattern
Serenity and the Journey PatternSerenity and the Journey Pattern
Serenity and the Journey Pattern
 
Using The Page Object Pattern
Using The Page Object PatternUsing The Page Object Pattern
Using The Page Object Pattern
 
Out of box page object design pattern, java
Out of box page object design pattern, javaOut of box page object design pattern, java
Out of box page object design pattern, java
 
Beyond Page Objects
Beyond Page ObjectsBeyond Page Objects
Beyond Page Objects
 
Webium: Page Objects In Python (Eng)
Webium: Page Objects In Python (Eng)Webium: Page Objects In Python (Eng)
Webium: Page Objects In Python (Eng)
 
Page Objects Done Right - selenium conference 2014
Page Objects Done Right - selenium conference 2014Page Objects Done Right - selenium conference 2014
Page Objects Done Right - selenium conference 2014
 
Perils of Page-Object Pattern
Perils of Page-Object PatternPerils of Page-Object Pattern
Perils of Page-Object Pattern
 
Node.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java sideNode.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java side
 
Patterns in Test Automation
Patterns in Test AutomationPatterns in Test Automation
Patterns in Test Automation
 
Test Automation Framework Designs
Test Automation Framework DesignsTest Automation Framework Designs
Test Automation Framework Designs
 

Similar to Refactoring page objects The Screenplay Pattern

Design pattern in an expressive language java script
Design pattern in an expressive language java scriptDesign pattern in an expressive language java script
Design pattern in an expressive language java script
Amit Thakkar
 
Recipe of a rockstar developer
Recipe of a rockstar developerRecipe of a rockstar developer
Recipe of a rockstar developer
Topu Newaj
 

Similar to Refactoring page objects The Screenplay Pattern (20)

Writing Quality Code
Writing Quality CodeWriting Quality Code
Writing Quality Code
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Agile design pattern
Agile design patternAgile design pattern
Agile design pattern
 
Creativity vs Best Practices
Creativity vs Best PracticesCreativity vs Best Practices
Creativity vs Best Practices
 
Design pattern in an expressive language java script
Design pattern in an expressive language java scriptDesign pattern in an expressive language java script
Design pattern in an expressive language java script
 
Design principle vs design patterns
Design principle vs design patternsDesign principle vs design patterns
Design principle vs design patterns
 
Recipe of a rockstar developer
Recipe of a rockstar developerRecipe of a rockstar developer
Recipe of a rockstar developer
 
Are You a SOLID Coder?
Are You a SOLID Coder?Are You a SOLID Coder?
Are You a SOLID Coder?
 
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
 
Software design principles - jinal desai
Software design principles - jinal desaiSoftware design principles - jinal desai
Software design principles - jinal desai
 
Selenium Design Patterns
Selenium Design PatternsSelenium Design Patterns
Selenium Design Patterns
 
Object Oriented Concepts in Real Projects
Object Oriented Concepts in Real ProjectsObject Oriented Concepts in Real Projects
Object Oriented Concepts in Real Projects
 
GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural Patterns
 
Solid
SolidSolid
Solid
 
Design Principles to design Patterns
Design Principles to design PatternsDesign Principles to design Patterns
Design Principles to design Patterns
 
How I ended up contributing to Magento core
How I ended up contributing to Magento coreHow I ended up contributing to Magento core
How I ended up contributing to Magento core
 
Practical Enterprise Application Development
Practical Enterprise Application DevelopmentPractical Enterprise Application Development
Practical Enterprise Application Development
 
Cinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patternsCinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patterns
 
Building resuable and customizable Vue components
Building resuable and customizable Vue componentsBuilding resuable and customizable Vue components
Building resuable and customizable Vue components
 
Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
 

Recently uploaded

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Recently uploaded (20)

WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
THE BEST IPTV in GERMANY for 2024: IPTVreel
THE BEST IPTV in  GERMANY for 2024: IPTVreelTHE BEST IPTV in  GERMANY for 2024: IPTVreel
THE BEST IPTV in GERMANY for 2024: IPTVreel
 

Refactoring page objects The Screenplay Pattern