SlideShare a Scribd company logo
Behavior Driven
Web UI Automation
with Selenium and
Cucumber/SpecFlow
Agile Testing Days 2017, Potsdam
16th November, 2017
Gáspár Nagy
coach • trainer • bdd addict • creator of specflow
“The BDD Books: Discovery” • http://bddbooks.com
@gasparnagy • gaspar@specsolutions.eu
Copyright © Gaspar NagyCopyright © Gaspar Nagy
bdd addict
given.when.then
CAUTION!
on the stage
Gáspár Nagy
coach, trainer and bdd addict
creator of SpecFlow
gaspar@specsolutions.eu
https://specsolutions.eu
@gasparnagy
Copyright © Gaspar NagyCopyright © Gaspar Nagy
There are problems with UI test automation!
script
expressed using
UI terms
modeling gap
between UI terms and
domain model terms
sloooow
for a bigger app the
feedback loop gets
uselessly long
brittle
browsers changing,
environment changes,
cross-platform issues,
etc.
Copyright © Gaspar NagyCopyright © Gaspar Nagy
You are here*!
*hopefully
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Unclear
purpose
Code
duplication
Anti-
semantic
locators
Wrong
abstraction
Timing
issues
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Unclear
purpose
Code
duplication
Anti-
semantic
locators
Wrong
abstraction
Timing
issues
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Unclear purpose – What does it do?
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Introduce BDD (SpecFlow/Cucumber)
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Unclear
purpose
Code
duplication
Anti-
semantic
locators
Wrong
abstraction
Timing
issues
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Introduce Page Objects
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Introduce Page Objects
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Introduce Page Objects
Encapsulate interactions
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Unclear
purpose
Code
duplication
Anti-
semantic
locators
Wrong
abstraction
Timing
issues
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Anti-semantic locators
• Think about how your users identify the different information (text, data,
controls, buttons, etc.) on the page
• If the user can find them, you will also find them… be smart!
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Locating by ID is not enough!
[FindsBy(How = How.Id, Using = "cb9eb8be-71…")]
public IWebElement Khaki { get; set; }
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Do not expose internals in the locators!
[FindsBy(How = How.Id, Using = "fabric_input")]
public IWebElement Fabric { get; set; }
fabric
fabric_input
fabric_list
fabric_open
@Html.Kendo().ComboBox().Name("fabric")
These are
internal for
the control!
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Contextual semantics
[FindsBy(How = How.CssSelector, Using = "input.btn.btn-default")]
public IWebElement SubmitButton { get; set; }
The page may contain multiple forms later!
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Define your own location strategy and
implement it as a custom locator!
[FindsBy(How = How.Custom,
CustomFinderType = typeof(TableFieldLocator)]
public IWebElement UserName { get; set; }
form
This is a
generic lookup
strategy
User Name
Password
input
input
Copyright © Gaspar NagyCopyright © Gaspar Nagy
public IWebElement UserName { get; set; }
Apply conventions with decorators and find the
tester’s nirvana…
form
This is the app-
specific lookup
strategy
User Name
Password
input
input
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Unclear
purpose
Code
duplication
Anti-
semantic
locators
Wrong
abstraction
Timing
issues
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Wrong abstraction
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Concept is an idea or mental picture of a group or
class of objects formed by combining all their aspects
This
gonna
save it!
Copyright © Gaspar NagyCopyright © Gaspar Nagy
UI Concepts
Counter concept,
divs and spans
Short-text entering
concept, input
@type=text
Multi-line text
entering concept,
div+javascriptSingle-choice concept,
set of input
@type=radio Submit concept,
span+javascript
Copyright © Gaspar NagyCopyright © Gaspar Nagy
A concept-based page
express concepts
interact on concept
level
For ConceptFactory implementation see:
https://github.com/gasparnagy/Sample_BehaviorDrivenWebUIAutomation
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Unclear
purpose
Code
duplication
Anti-
semantic
locators
Wrong
abstraction
Timing
issues
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Thread.Sleep(3000);
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Why do we have this timing problem?
Copyright © Gaspar NagyCopyright © Gaspar Nagy
An example
Enter text
Post form
Working, working…
Observe result
title.SendKeys(…);
button.Click();
driver.FindElement(…);
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Let’s add some waiting to it!
Thread.Sleep(2000);
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
wait.Until(d => d.FindElement(By...));
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
...
driver.FindElement(By...);
Static waiting
Busy/active waiting
Implicit busy waiting
Copyright © Gaspar NagyCopyright © Gaspar Nagy
An example
Enter text
Post form
Working, working…
Observe result
title.SendKeys(…);
button.Click();
driver.FindElement(…);
The thing you are waiting for is here!
You are waiting here!
Your user knows* when the action is done
*hopefully
• Maybe there is a progress indicator
• Maybe they look at the browser icon
• Maybe they’ll wait till they see the end of the page
Copyright © Gaspar NagyCopyright © Gaspar Nagy
An example
Enter text
Post form
Working, working…
Observe result
title.SendKeys(…);
button.Click();
...wait for the footer
driver.FindElement(…);
Result page loaded
button.SubmitClick()
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Other conditions
• Wait until progress indicator is unloaded
• Wait until injected JavaScript signals that the operation has finished
• Wait until protractor signals
• You can even put Thread.Sleep there… only to that single place!
For all these, you need to isolate Submit/Click from other clicks
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Unclear
purpose
Code
duplication
Anti-
semantic
locators
Wrong
abstraction
Timing
issues
*maybe
Thank you!
Gáspár Nagy
coach • trainer • bdd addict • creator of specflow
“The BDD Books: Discovery” • http://bddbooks.com
@gasparnagy • gaspar@specsolutions.eu
Copyright © Gaspar NagyCopyright © Gaspar Nagy

More Related Content

Viewers also liked

Challenges faced in UI automation
Challenges faced in UI automationChallenges faced in UI automation
Challenges faced in UI automation
Srinivas Kantipudi
 

Viewers also liked (8)

UI Test Automation Effectiveness
UI Test Automation EffectivenessUI Test Automation Effectiveness
UI Test Automation Effectiveness
 
Coded UI - Test automation Practices from the Field
Coded UI - Test automation Practices from the FieldCoded UI - Test automation Practices from the Field
Coded UI - Test automation Practices from the Field
 
Introduction to UI Automation Framework
Introduction to UI Automation FrameworkIntroduction to UI Automation Framework
Introduction to UI Automation Framework
 
Effectively Using UI Automation
Effectively Using UI AutomationEffectively Using UI Automation
Effectively Using UI Automation
 
Web UI test automation instruments
Web UI test automation instrumentsWeb UI test automation instruments
Web UI test automation instruments
 
UI test automation techniques by an example of JavaFX UI
UI test automation techniques by an example of JavaFX UIUI test automation techniques by an example of JavaFX UI
UI test automation techniques by an example of JavaFX UI
 
UI Test Automation - Maximizing ROI by Minimizing Maintenance Costs
UI Test Automation - Maximizing ROI by Minimizing Maintenance CostsUI Test Automation - Maximizing ROI by Minimizing Maintenance Costs
UI Test Automation - Maximizing ROI by Minimizing Maintenance Costs
 
Challenges faced in UI automation
Challenges faced in UI automationChallenges faced in UI automation
Challenges faced in UI automation
 

Similar to Behavior Driven UI Automation (Agile Testing Days 2017, Potsdam)

Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
維佋 唐
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
Guillaume Laforge
 
Automatic Code Generation
Automatic Code GenerationAutomatic Code Generation
Automatic Code Generation
elliando dias
 

Similar to Behavior Driven UI Automation (Agile Testing Days 2017, Potsdam) (20)

Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (Qualit...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (Qualit...Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (Qualit...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (Qualit...
 
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
 
Automatic Code Generation
Automatic Code GenerationAutomatic Code Generation
Automatic Code Generation
 
Scaffolding a legacy app with BDD scenario (Agile in the City Bristol 2017)
Scaffolding a legacy app with BDD scenario (Agile in the City Bristol 2017)Scaffolding a legacy app with BDD scenario (Agile in the City Bristol 2017)
Scaffolding a legacy app with BDD scenario (Agile in the City Bristol 2017)
 
Intro To Django
Intro To DjangoIntro To Django
Intro To Django
 
Html5 Overview
Html5 OverviewHtml5 Overview
Html5 Overview
 
Scripting Oracle Develop 2007
Scripting Oracle Develop 2007Scripting Oracle Develop 2007
Scripting Oracle Develop 2007
 
Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2...
Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2...Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2...
Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2...
 
JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...
JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...
JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...
 
Introduction to Spring Boot.pdf
Introduction to Spring Boot.pdfIntroduction to Spring Boot.pdf
Introduction to Spring Boot.pdf
 
Google Gears
Google GearsGoogle Gears
Google Gears
 
Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007
 
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and DataflowHow to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
 
"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson
 
Creative Solutions to Already Solved Problems II
Creative Solutions to Already Solved Problems IICreative Solutions to Already Solved Problems II
Creative Solutions to Already Solved Problems II
 
Build, Train & Deploy Your ML Application on Amazon SageMaker
Build, Train & Deploy Your ML Application on Amazon SageMakerBuild, Train & Deploy Your ML Application on Amazon SageMaker
Build, Train & Deploy Your ML Application on Amazon SageMaker
 
Boost your testing: End-to-End with Docker and Geb
 Boost your testing: End-to-End with Docker and Geb Boost your testing: End-to-End with Docker and Geb
Boost your testing: End-to-End with Docker and Geb
 

More from Gáspár Nagy

BDD Scenarios in a Testing & Traceability Strategy (Webinar 19/02/2021)
BDD Scenarios in a Testing & Traceability Strategy (Webinar 19/02/2021)BDD Scenarios in a Testing & Traceability Strategy (Webinar 19/02/2021)
BDD Scenarios in a Testing & Traceability Strategy (Webinar 19/02/2021)
Gáspár Nagy
 
Property Based BDD Examples (ETSI UCAAT 2016, Budapest)
Property Based BDD Examples (ETSI UCAAT 2016, Budapest)Property Based BDD Examples (ETSI UCAAT 2016, Budapest)
Property Based BDD Examples (ETSI UCAAT 2016, Budapest)
Gáspár Nagy
 

More from Gáspár Nagy (16)

Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
 
BDD Scenarios in a Testing Strategy
BDD Scenarios in a Testing StrategyBDD Scenarios in a Testing Strategy
BDD Scenarios in a Testing Strategy
 
Ramp up your testing solution, ExpoQA 2023
Ramp up your testing solution, ExpoQA 2023Ramp up your testing solution, ExpoQA 2023
Ramp up your testing solution, ExpoQA 2023
 
BDD Scenarios in a Testing & Traceability Strategy (Webinar 19/02/2021)
BDD Scenarios in a Testing & Traceability Strategy (Webinar 19/02/2021)BDD Scenarios in a Testing & Traceability Strategy (Webinar 19/02/2021)
BDD Scenarios in a Testing & Traceability Strategy (Webinar 19/02/2021)
 
Fighting against technical debt (CukenFest 2020)
Fighting against technical debt (CukenFest 2020)Fighting against technical debt (CukenFest 2020)
Fighting against technical debt (CukenFest 2020)
 
Süllyedünk! Ütközés a tesztelési jégheggyel (Teszt & Tea Meeup Budapest, 2018...
Süllyedünk! Ütközés a tesztelési jégheggyel (Teszt & Tea Meeup Budapest, 2018...Süllyedünk! Ütközés a tesztelési jégheggyel (Teszt & Tea Meeup Budapest, 2018...
Süllyedünk! Ütközés a tesztelési jégheggyel (Teszt & Tea Meeup Budapest, 2018...
 
Continuous Behavior - BDD in Continuous Delivery (CoDers Who Test, Gothenburg...
Continuous Behavior - BDD in Continuous Delivery (CoDers Who Test, Gothenburg...Continuous Behavior - BDD in Continuous Delivery (CoDers Who Test, Gothenburg...
Continuous Behavior - BDD in Continuous Delivery (CoDers Who Test, Gothenburg...
 
We are sinking: Hitting the testing iceberg (CukenFest London, 2018)
We are sinking: Hitting the testing iceberg (CukenFest London, 2018)We are sinking: Hitting the testing iceberg (CukenFest London, 2018)
We are sinking: Hitting the testing iceberg (CukenFest London, 2018)
 
Testing is Difficult (Agile in the City Bristol 2017, Lightening talk)
Testing is Difficult (Agile in the City Bristol 2017, Lightening talk)Testing is Difficult (Agile in the City Bristol 2017, Lightening talk)
Testing is Difficult (Agile in the City Bristol 2017, Lightening talk)
 
A tesztelés szerepe folyamatos kihelyezést használó projektekben (Microsoft, ...
A tesztelés szerepe folyamatos kihelyezést használó projektekben (Microsoft, ...A tesztelés szerepe folyamatos kihelyezést használó projektekben (Microsoft, ...
A tesztelés szerepe folyamatos kihelyezést használó projektekben (Microsoft, ...
 
Property Based BDD Examples (ETSI UCAAT 2016, Budapest)
Property Based BDD Examples (ETSI UCAAT 2016, Budapest)Property Based BDD Examples (ETSI UCAAT 2016, Budapest)
Property Based BDD Examples (ETSI UCAAT 2016, Budapest)
 
Given/When/Then-ready sprint planning with Example Mapping (Agilia Budapest 2...
Given/When/Then-ready sprint planning with Example Mapping (Agilia Budapest 2...Given/When/Then-ready sprint planning with Example Mapping (Agilia Budapest 2...
Given/When/Then-ready sprint planning with Example Mapping (Agilia Budapest 2...
 
Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (BDD Lond...
Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (BDD Lond...Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (BDD Lond...
Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (BDD Lond...
 
Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Confere...
Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Confere...Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Confere...
Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Confere...
 
Folyamatos integráció és kódépítés (ALM Day Budapest, 24/11/2015, Hungarian)
Folyamatos integráció és kódépítés (ALM Day Budapest, 24/11/2015, Hungarian)Folyamatos integráció és kódépítés (ALM Day Budapest, 24/11/2015, Hungarian)
Folyamatos integráció és kódépítés (ALM Day Budapest, 24/11/2015, Hungarian)
 
Given/When/Then-ready sprint planning (Agile Tour Vienna 2015)
Given/When/Then-ready sprint planning (Agile Tour Vienna 2015)Given/When/Then-ready sprint planning (Agile Tour Vienna 2015)
Given/When/Then-ready sprint planning (Agile Tour Vienna 2015)
 

Recently uploaded

How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 

Recently uploaded (20)

How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdf
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 

Behavior Driven UI Automation (Agile Testing Days 2017, Potsdam)

  • 1. Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow Agile Testing Days 2017, Potsdam 16th November, 2017 Gáspár Nagy coach • trainer • bdd addict • creator of specflow “The BDD Books: Discovery” • http://bddbooks.com @gasparnagy • gaspar@specsolutions.eu
  • 2. Copyright © Gaspar NagyCopyright © Gaspar Nagy bdd addict given.when.then CAUTION! on the stage Gáspár Nagy coach, trainer and bdd addict creator of SpecFlow gaspar@specsolutions.eu https://specsolutions.eu @gasparnagy
  • 3. Copyright © Gaspar NagyCopyright © Gaspar Nagy There are problems with UI test automation! script expressed using UI terms modeling gap between UI terms and domain model terms sloooow for a bigger app the feedback loop gets uselessly long brittle browsers changing, environment changes, cross-platform issues, etc.
  • 4. Copyright © Gaspar NagyCopyright © Gaspar Nagy You are here*! *hopefully
  • 5. Copyright © Gaspar NagyCopyright © Gaspar Nagy
  • 6. Copyright © Gaspar NagyCopyright © Gaspar Nagy Unclear purpose Code duplication Anti- semantic locators Wrong abstraction Timing issues
  • 7.
  • 8. Copyright © Gaspar NagyCopyright © Gaspar Nagy Unclear purpose Code duplication Anti- semantic locators Wrong abstraction Timing issues
  • 9. Copyright © Gaspar NagyCopyright © Gaspar Nagy Unclear purpose – What does it do?
  • 10. Copyright © Gaspar NagyCopyright © Gaspar Nagy Introduce BDD (SpecFlow/Cucumber)
  • 11. Copyright © Gaspar NagyCopyright © Gaspar Nagy Unclear purpose Code duplication Anti- semantic locators Wrong abstraction Timing issues
  • 12. Copyright © Gaspar NagyCopyright © Gaspar Nagy Introduce Page Objects
  • 13. Copyright © Gaspar NagyCopyright © Gaspar Nagy Introduce Page Objects
  • 14. Copyright © Gaspar NagyCopyright © Gaspar Nagy Introduce Page Objects Encapsulate interactions
  • 15. Copyright © Gaspar NagyCopyright © Gaspar Nagy Unclear purpose Code duplication Anti- semantic locators Wrong abstraction Timing issues
  • 16. Copyright © Gaspar NagyCopyright © Gaspar Nagy
  • 17. Copyright © Gaspar NagyCopyright © Gaspar Nagy Anti-semantic locators • Think about how your users identify the different information (text, data, controls, buttons, etc.) on the page • If the user can find them, you will also find them… be smart!
  • 18. Copyright © Gaspar NagyCopyright © Gaspar Nagy Locating by ID is not enough! [FindsBy(How = How.Id, Using = "cb9eb8be-71…")] public IWebElement Khaki { get; set; }
  • 19. Copyright © Gaspar NagyCopyright © Gaspar Nagy Do not expose internals in the locators! [FindsBy(How = How.Id, Using = "fabric_input")] public IWebElement Fabric { get; set; } fabric fabric_input fabric_list fabric_open @Html.Kendo().ComboBox().Name("fabric") These are internal for the control!
  • 20. Copyright © Gaspar NagyCopyright © Gaspar Nagy Contextual semantics [FindsBy(How = How.CssSelector, Using = "input.btn.btn-default")] public IWebElement SubmitButton { get; set; } The page may contain multiple forms later!
  • 21. Copyright © Gaspar NagyCopyright © Gaspar Nagy Define your own location strategy and implement it as a custom locator! [FindsBy(How = How.Custom, CustomFinderType = typeof(TableFieldLocator)] public IWebElement UserName { get; set; } form This is a generic lookup strategy User Name Password input input
  • 22. Copyright © Gaspar NagyCopyright © Gaspar Nagy public IWebElement UserName { get; set; } Apply conventions with decorators and find the tester’s nirvana… form This is the app- specific lookup strategy User Name Password input input
  • 23.
  • 24. Copyright © Gaspar NagyCopyright © Gaspar Nagy Unclear purpose Code duplication Anti- semantic locators Wrong abstraction Timing issues
  • 25. Copyright © Gaspar NagyCopyright © Gaspar Nagy Wrong abstraction
  • 26. Copyright © Gaspar NagyCopyright © Gaspar Nagy Concept is an idea or mental picture of a group or class of objects formed by combining all their aspects
  • 28. Copyright © Gaspar NagyCopyright © Gaspar Nagy UI Concepts Counter concept, divs and spans Short-text entering concept, input @type=text Multi-line text entering concept, div+javascriptSingle-choice concept, set of input @type=radio Submit concept, span+javascript
  • 29. Copyright © Gaspar NagyCopyright © Gaspar Nagy A concept-based page express concepts interact on concept level For ConceptFactory implementation see: https://github.com/gasparnagy/Sample_BehaviorDrivenWebUIAutomation
  • 30. Copyright © Gaspar NagyCopyright © Gaspar Nagy Unclear purpose Code duplication Anti- semantic locators Wrong abstraction Timing issues
  • 31. Copyright © Gaspar NagyCopyright © Gaspar Nagy Thread.Sleep(3000);
  • 32. Copyright © Gaspar NagyCopyright © Gaspar Nagy Why do we have this timing problem?
  • 33. Copyright © Gaspar NagyCopyright © Gaspar Nagy An example Enter text Post form Working, working… Observe result title.SendKeys(…); button.Click(); driver.FindElement(…);
  • 34. Copyright © Gaspar NagyCopyright © Gaspar Nagy Let’s add some waiting to it! Thread.Sleep(2000); var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5)); wait.Until(d => d.FindElement(By...)); driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5)); ... driver.FindElement(By...); Static waiting Busy/active waiting Implicit busy waiting
  • 35. Copyright © Gaspar NagyCopyright © Gaspar Nagy An example Enter text Post form Working, working… Observe result title.SendKeys(…); button.Click(); driver.FindElement(…); The thing you are waiting for is here! You are waiting here!
  • 36. Your user knows* when the action is done *hopefully • Maybe there is a progress indicator • Maybe they look at the browser icon • Maybe they’ll wait till they see the end of the page
  • 37. Copyright © Gaspar NagyCopyright © Gaspar Nagy An example Enter text Post form Working, working… Observe result title.SendKeys(…); button.Click(); ...wait for the footer driver.FindElement(…); Result page loaded button.SubmitClick()
  • 38. Copyright © Gaspar NagyCopyright © Gaspar Nagy Other conditions • Wait until progress indicator is unloaded • Wait until injected JavaScript signals that the operation has finished • Wait until protractor signals • You can even put Thread.Sleep there… only to that single place! For all these, you need to isolate Submit/Click from other clicks
  • 39. Copyright © Gaspar NagyCopyright © Gaspar Nagy Unclear purpose Code duplication Anti- semantic locators Wrong abstraction Timing issues
  • 40.
  • 42. Thank you! Gáspár Nagy coach • trainer • bdd addict • creator of specflow “The BDD Books: Discovery” • http://bddbooks.com @gasparnagy • gaspar@specsolutions.eu
  • 43. Copyright © Gaspar NagyCopyright © Gaspar Nagy