SlideShare a Scribd company logo
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

Enterprise Messaging with Apache ActiveMQ
Enterprise Messaging with Apache ActiveMQEnterprise Messaging with Apache ActiveMQ
Enterprise Messaging with Apache ActiveMQ
elliando dias
 

What's hot (20)

Introduction to Bdd and cucumber
Introduction to Bdd and cucumberIntroduction to Bdd and cucumber
Introduction to Bdd and cucumber
 
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening KeynoteClean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
 
Introduction to jest
Introduction to jestIntroduction to jest
Introduction to jest
 
Bloc Pattern - Practical Use Cases - Flutter London - 21JAN2019
Bloc Pattern - Practical Use Cases - Flutter London - 21JAN2019Bloc Pattern - Practical Use Cases - Flutter London - 21JAN2019
Bloc Pattern - Practical Use Cases - Flutter London - 21JAN2019
 
Teste de usabilidade - Materiais do teste
Teste de usabilidade - Materiais do testeTeste de usabilidade - Materiais do teste
Teste de usabilidade - Materiais do teste
 
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
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Scrum + bdd + ddd
Scrum + bdd + dddScrum + bdd + ddd
Scrum + bdd + ddd
 
JMeter JMX Script Creation via BlazeMeter
JMeter JMX Script Creation via BlazeMeterJMeter JMX Script Creation via BlazeMeter
JMeter JMX Script Creation via BlazeMeter
 
Trunk-based Development with Feature toggles
Trunk-based Development with Feature togglesTrunk-based Development with Feature toggles
Trunk-based Development with Feature toggles
 
Introduction to SOLID Principles
Introduction to SOLID PrinciplesIntroduction to SOLID Principles
Introduction to SOLID Principles
 
Enterprise Messaging with Apache ActiveMQ
Enterprise Messaging with Apache ActiveMQEnterprise Messaging with Apache ActiveMQ
Enterprise Messaging with Apache ActiveMQ
 
A Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation SlidesA Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation Slides
 
Escalando apps com React e Type Script e SOLID
Escalando apps com React e Type Script e SOLIDEscalando apps com React e Type Script e SOLID
Escalando apps com React e Type Script e SOLID
 
BDD presentation
BDD presentationBDD presentation
BDD presentation
 
WEB DEVELOPMENT USING REACT JS
 WEB DEVELOPMENT USING REACT JS WEB DEVELOPMENT USING REACT JS
WEB DEVELOPMENT USING REACT JS
 
AngularJS for Beginners
AngularJS for BeginnersAngularJS for Beginners
AngularJS for Beginners
 
Patrones de diseño en la automatización PageObject o ScreenPlay
Patrones de diseño en la automatización PageObject o ScreenPlayPatrones de diseño en la automatización PageObject o ScreenPlay
Patrones de diseño en la automatización PageObject o ScreenPlay
 
Common iOS Architecture: From MVC to VIPER, with Redux
Common iOS Architecture: From MVC to VIPER, with ReduxCommon iOS Architecture: From MVC to VIPER, with Redux
Common iOS Architecture: From MVC to VIPER, with Redux
 
BDD & Cucumber
BDD & CucumberBDD & Cucumber
BDD & Cucumber
 

Viewers also liked

Viewers also liked (11)

ScreenPlay Design Patterns for QA Automation
ScreenPlay Design Patterns for QA AutomationScreenPlay Design Patterns for QA Automation
ScreenPlay Design Patterns for QA Automation
 
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

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.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
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 

Refactoring page objects The Screenplay Pattern