SlideShare a Scribd company logo
Behavior Driven
Web UI
Automation
with Selenium and
Cucumber/SpecFlow
BDDx, London
11th November 2016
Gáspár Nagy
coach • trainer • bdd addict • creator of specflow
@gasparnagy • gaspar@specsolutions.eu
Copyright © Gaspar NagyCopyright © Gaspar Nagy
bddaddict.com
bdd addict
given.when.then
CAUTION!
on the stage
Copyright © Gaspar NagyCopyright © Gaspar Nagy
There are problems with UI testing!
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
A decent app
Copyright © Gaspar NagyCopyright © Gaspar Nagy
With an ugly test…
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx London, 11/11/2016)
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Unclear
purpose
Code
duplication
Anti-
semantic
locators
Wrong
abstraction
Timing
issues
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Unclear purpose – BDD
• Automated tests are investments for the future
• Tests without clearly specified goal are only good until they pass
• BDD/SpecFlow/Cucumber are great tools for helping you to connect
purpose for the automation steps
• Scenario title – defines the goal (“The one where …”)
• Scenario steps – provide a functional grouping for the automation steps
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Introduce SpecFlow/Cucumber
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Introduce SpecFlow/Cucumber
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Code duplication – Page Objects
• A small change in the application should only make a small impact on the
automation solution
• Automated tests should support you for applying changes and not hold
you back
• Page Objects can help you to encapsulate the automation logic for
particular UI elements
• Page Objects mirror the page structure
• They represent an automation layer below the step definitions
• Driver pattern is a generalization of the page object pattern for non-UI automation
tasks
• They can serve as the interface for switching from UI automation to API-level
automation
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Introduce Page Objects
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Introduce Page Objects
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Introduce Page Objects
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
Locators – Match your solution to the
domain
• If the solution is modeled on the basis of the problem space, the elements
will have semantic identification
• Question title – title column in DB – Title property in code - #Title
[FindsBy(How = How.Id)]
public IWebElement Title { get; set; }
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Problem vs. solution domain
Concept by Matt Wynne, see also http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
Problem Domain Solution Domain
Tweet
• Tweet
• Retweet
Message
• Send
• Forward
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Locating by ID is not enough!
[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
Locating by ID is not enough!
[FindsBy(How = How.Id, Using = "cb9eb8be-71…")]
public IWebElement Khaki { get; set; }
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Be careful with Selenium IDE
[FindsBy(How = How.CssSelector, Using = "input.btn.btn-default")]
public IWebElement Fabric { get; set; }
There was only one button on the page that time!
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
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx London, 11/11/2016)
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
Encapsulate automation logic of UI
concepts
• Selenium’s PageFactory can only map IWebElement or
List<IWebElement>
• Defining a static helper method is already a good solution
• like FillInTextBox(IWebElement elm, string value)
• A factory infrastructure, similar to the PageFactory makes it even better
Copyright © Gaspar NagyCopyright © Gaspar Nagy
A concept-based page
express concepts
interact on concept
level
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!
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Waiting at the observation step…
• Establishes an implicit dependency between the automation code
triggering the action (Click) and the assertion (FindElement)
• This makes the code brittle, because
• you cannot compose new tests easily from the automation steps (e.g. the same
assertion after another action)
• the code will be sensitive to the order of the assertions
• tests will be slowed down unnecessarily
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.SubmitClick();
driver.FindElement(…);
Result page loaded
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Define the waiting conditions for the
interactions of the UI concepts!
This is an example…
• Submit concept – a concept that can trigger a server-side processing and
results either in an error or a success
• Success is indicated by a fully loaded page with a success message
• Error is indicated by …
• Fully loaded page means that the footer is visible
• Solution: Implement SubmitConcept.Click() in a way that it clicks the
button and is waiting either for the success or the error condition
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
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx London, 11/11/2016)
*maybe
Gáspár Nagy
coach • trainer • bdd addict • creator of specflow
@gasparnagy • gaspar@specsolutions.eu
Gáspár Nagy
coach • trainer • bdd addict • creator of specflow
@gasparnagy • gaspar@specsolutions.eu
Thank you!

More Related Content

What's hot (20)

PPTX
CUCUMBER - Making BDD Fun
SQABD
 
PPTX
Behaviour driven development aka bdd
Prince Gupta
 
PDF
Behavior-Driven Development and Automation Testing Using Cucumber Framework W...
KMS Technology
 
PPTX
Test automation with Cucumber-JVM
Alan Parkinson
 
PDF
Behavior Driven Development with Cucumber
Asheesh Mehdiratta
 
PPTX
Bdd – with cucumber and gherkin
Arati Joshi
 
PPTX
Cucumber BDD
Pravin Dsilva
 
PPTX
ScreenPlay Design Patterns for QA Automation
COMAQA.BY
 
PPTX
Behavior driven development - cucumber, Junit and java
Naveen Kumar Singh
 
PDF
greach 2014 marco vermeulen bdd using cucumber jvm and groovy
Jessie Evangelista
 
PDF
Ruby onrails cucumber-rspec-capybara
Bindesh Vijayan
 
PPTX
Refactoring page objects The Screenplay Pattern
RiverGlide
 
PPTX
BDD, Behat & Drupal
Bozhidar Boshnakov
 
PPTX
API Test Automation Using Karate (Anil Kumar Moka)
Peter Thomas
 
PDF
Building a Cerberus App Without Losing Our Heads: The Passage to a Cross-Plat...
Atlassian
 
PDF
Behavior Driven Development - How To Start with Behat
imoneytech
 
PDF
Crash Course in AngularJS + Ionic (Deep dive)
ColdFusionConference
 
PDF
Discover the Possibilities of the Jira Cloud Asset API
Atlassian
 
PDF
Spec-first API Design for Speed and Safety
Atlassian
 
PDF
Lambdaless and AWS CDK
MooYeol Lee
 
CUCUMBER - Making BDD Fun
SQABD
 
Behaviour driven development aka bdd
Prince Gupta
 
Behavior-Driven Development and Automation Testing Using Cucumber Framework W...
KMS Technology
 
Test automation with Cucumber-JVM
Alan Parkinson
 
Behavior Driven Development with Cucumber
Asheesh Mehdiratta
 
Bdd – with cucumber and gherkin
Arati Joshi
 
Cucumber BDD
Pravin Dsilva
 
ScreenPlay Design Patterns for QA Automation
COMAQA.BY
 
Behavior driven development - cucumber, Junit and java
Naveen Kumar Singh
 
greach 2014 marco vermeulen bdd using cucumber jvm and groovy
Jessie Evangelista
 
Ruby onrails cucumber-rspec-capybara
Bindesh Vijayan
 
Refactoring page objects The Screenplay Pattern
RiverGlide
 
BDD, Behat & Drupal
Bozhidar Boshnakov
 
API Test Automation Using Karate (Anil Kumar Moka)
Peter Thomas
 
Building a Cerberus App Without Losing Our Heads: The Passage to a Cross-Plat...
Atlassian
 
Behavior Driven Development - How To Start with Behat
imoneytech
 
Crash Course in AngularJS + Ionic (Deep dive)
ColdFusionConference
 
Discover the Possibilities of the Jira Cloud Asset API
Atlassian
 
Spec-first API Design for Speed and Safety
Atlassian
 
Lambdaless and AWS CDK
MooYeol Lee
 

Viewers also liked (20)

PDF
Property Based BDD Examples (ETSI UCAAT 2016, Budapest)
Gáspár Nagy
 
PDF
Given/When/Then-ready sprint planning with Example Mapping (Agilia Budapest 2...
Gáspár Nagy
 
PPTX
Ui automation kms_tech_con2014
ducminhduydo
 
PDF
Nov 26 Chinese and English Infosession
Alice Lam
 
PPTX
Specflow
Larry Nung
 
PPTX
selenium-cucumber
Sameer Sawant
 
PPTX
Nasdanika WebTest - Modular functional testing of Web and Mobile Applications
Pavel Vlasov
 
PPTX
Selenium and Cucumber Automation Services
LMS Solutions (India) Pvt.Ltd.
 
PPTX
Future of UI Automation testing and JDI
COMAQA.BY
 
PDF
Given/When/Then-ready sprint planning (Agile Tour Vienna 2015)
Gáspár Nagy
 
PDF
The Power of Visuals
Ádám Nagy
 
PDF
Folyamatos integráció és kódépítés (ALM Day Budapest, 24/11/2015, Hungarian)
Gáspár Nagy
 
PDF
Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2...
Gáspár Nagy
 
PDF
Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Confere...
Gáspár Nagy
 
PDF
NDC 2011 - SpecFlow: Pragmatic BDD for .NET
jbandi
 
PPTX
Coded UI - Test automation Practices from the Field
Clemens Reijnen
 
PDF
SpecFlow and some things I've picked up
Marcus Hammarberg
 
PPTX
Hybrid automation framework
doai tran
 
PPTX
Specflow - Criando uma ponte entre desenvolvedores.
Franklin Araujo SMAC™ ASTAC™ SFC™
 
Property Based BDD Examples (ETSI UCAAT 2016, Budapest)
Gáspár Nagy
 
Given/When/Then-ready sprint planning with Example Mapping (Agilia Budapest 2...
Gáspár Nagy
 
Ui automation kms_tech_con2014
ducminhduydo
 
Nov 26 Chinese and English Infosession
Alice Lam
 
Specflow
Larry Nung
 
selenium-cucumber
Sameer Sawant
 
Nasdanika WebTest - Modular functional testing of Web and Mobile Applications
Pavel Vlasov
 
Selenium and Cucumber Automation Services
LMS Solutions (India) Pvt.Ltd.
 
Future of UI Automation testing and JDI
COMAQA.BY
 
Given/When/Then-ready sprint planning (Agile Tour Vienna 2015)
Gáspár Nagy
 
The Power of Visuals
Ádám Nagy
 
Folyamatos integráció és kódépítés (ALM Day Budapest, 24/11/2015, Hungarian)
Gáspár Nagy
 
Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2...
Gáspár Nagy
 
Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Confere...
Gáspár Nagy
 
NDC 2011 - SpecFlow: Pragmatic BDD for .NET
jbandi
 
Coded UI - Test automation Practices from the Field
Clemens Reijnen
 
SpecFlow and some things I've picked up
Marcus Hammarberg
 
Hybrid automation framework
doai tran
 
Specflow - Criando uma ponte entre desenvolvedores.
Franklin Araujo SMAC™ ASTAC™ SFC™
 
Ad

Similar to Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx London, 11/11/2016) (20)

PDF
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (Qualit...
Gáspár Nagy
 
PDF
Behavior Driven UI Automation (Agile Testing Days 2017, Potsdam)
Gáspár Nagy
 
KEY
Intro To Django
Udi Bauman
 
PDF
Scaffolding a legacy app with BDD scenario (Agile in the City Bristol 2017)
Gáspár Nagy
 
PDF
Top 13 best front end web development tools to consider in 2021
Samaritan InfoTech
 
PDF
WebRTC Live Q&A Session #5 - JavaScript Promises and WebRTC Interoperability ...
Amir Zmora
 
ODP
Managing Creativity
kamaelian
 
PPTX
INTERNSHIP PPT - INFOLABZ.pptx
DevChaudhari15
 
PPTX
216170316007.pptx
DevChaudhari15
 
PDF
Web Pages Visual Similarity - Search Central Live Zurich 2024
Giacomo Zecchini
 
PPTX
Introduction to GluonCV
Apache MXNet
 
PDF
BDD Scenarios in a Testing & Traceability Strategy (Webinar 19/02/2021)
Gáspár Nagy
 
PPTX
Design patterns
nisheesh
 
PDF
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Vadym Kazulkin
 
PDF
Developing for LinkedIn's Application Platform
Taylor Singletary
 
DOCX
Ramesh Babu Resume Latest
Ramesh Babu
 
PDF
BDD Scenarios in a Testing Strategy
Gáspár Nagy
 
PPTX
Automated perf optimization - jQuery Conference
Matthew Lancaster
 
PDF
wt mod3.pdf
VinayKumarV24
 
PDF
JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...
Yusuke Yamamoto
 
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (Qualit...
Gáspár Nagy
 
Behavior Driven UI Automation (Agile Testing Days 2017, Potsdam)
Gáspár Nagy
 
Intro To Django
Udi Bauman
 
Scaffolding a legacy app with BDD scenario (Agile in the City Bristol 2017)
Gáspár Nagy
 
Top 13 best front end web development tools to consider in 2021
Samaritan InfoTech
 
WebRTC Live Q&A Session #5 - JavaScript Promises and WebRTC Interoperability ...
Amir Zmora
 
Managing Creativity
kamaelian
 
INTERNSHIP PPT - INFOLABZ.pptx
DevChaudhari15
 
216170316007.pptx
DevChaudhari15
 
Web Pages Visual Similarity - Search Central Live Zurich 2024
Giacomo Zecchini
 
Introduction to GluonCV
Apache MXNet
 
BDD Scenarios in a Testing & Traceability Strategy (Webinar 19/02/2021)
Gáspár Nagy
 
Design patterns
nisheesh
 
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Vadym Kazulkin
 
Developing for LinkedIn's Application Platform
Taylor Singletary
 
Ramesh Babu Resume Latest
Ramesh Babu
 
BDD Scenarios in a Testing Strategy
Gáspár Nagy
 
Automated perf optimization - jQuery Conference
Matthew Lancaster
 
wt mod3.pdf
VinayKumarV24
 
JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...
Yusuke Yamamoto
 
Ad

More from Gáspár Nagy (9)

PDF
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Gáspár Nagy
 
PDF
Ramp up your testing solution, ExpoQA 2023
Gáspár Nagy
 
PDF
Fighting against technical debt (CukenFest 2020)
Gáspár Nagy
 
PDF
Süllyedünk! Ütközés a tesztelési jégheggyel (Teszt & Tea Meeup Budapest, 2018...
Gáspár Nagy
 
PDF
Continuous Behavior - BDD in Continuous Delivery (CoDers Who Test, Gothenburg...
Gáspár Nagy
 
PDF
We are sinking: Hitting the testing iceberg (CukenFest London, 2018)
Gáspár Nagy
 
PDF
Testing is Difficult (Agile in the City Bristol 2017, Lightening talk)
Gáspár Nagy
 
PDF
A tesztelés szerepe folyamatos kihelyezést használó projektekben (Microsoft, ...
Gáspár Nagy
 
PDF
Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (BDD Lond...
Gáspár Nagy
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Gáspár Nagy
 
Ramp up your testing solution, ExpoQA 2023
Gáspár Nagy
 
Fighting against technical debt (CukenFest 2020)
Gáspár Nagy
 
Süllyedünk! Ütközés a tesztelési jégheggyel (Teszt & Tea Meeup Budapest, 2018...
Gáspár Nagy
 
Continuous Behavior - BDD in Continuous Delivery (CoDers Who Test, Gothenburg...
Gáspár Nagy
 
We are sinking: Hitting the testing iceberg (CukenFest London, 2018)
Gáspár Nagy
 
Testing is Difficult (Agile in the City Bristol 2017, Lightening talk)
Gáspár Nagy
 
A tesztelés szerepe folyamatos kihelyezést használó projektekben (Microsoft, ...
Gáspár Nagy
 
Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (BDD Lond...
Gáspár Nagy
 

Recently uploaded (20)

PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 

Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx London, 11/11/2016)

  • 1. Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow BDDx, London 11th November 2016 Gáspár Nagy coach • trainer • bdd addict • creator of specflow @gasparnagy • [email protected]
  • 2. Copyright © Gaspar NagyCopyright © Gaspar Nagy bddaddict.com bdd addict given.when.then CAUTION! on the stage
  • 3. Copyright © Gaspar NagyCopyright © Gaspar Nagy There are problems with UI testing! 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 A decent app
  • 6. Copyright © Gaspar NagyCopyright © Gaspar Nagy With an ugly test…
  • 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 – BDD • Automated tests are investments for the future • Tests without clearly specified goal are only good until they pass • BDD/SpecFlow/Cucumber are great tools for helping you to connect purpose for the automation steps • Scenario title – defines the goal (“The one where …”) • Scenario steps – provide a functional grouping for the automation steps
  • 10. Copyright © Gaspar NagyCopyright © Gaspar Nagy Introduce SpecFlow/Cucumber
  • 11. Copyright © Gaspar NagyCopyright © Gaspar Nagy Introduce SpecFlow/Cucumber
  • 12. Copyright © Gaspar NagyCopyright © Gaspar Nagy Code duplication – Page Objects • A small change in the application should only make a small impact on the automation solution • Automated tests should support you for applying changes and not hold you back • Page Objects can help you to encapsulate the automation logic for particular UI elements • Page Objects mirror the page structure • They represent an automation layer below the step definitions • Driver pattern is a generalization of the page object pattern for non-UI automation tasks • They can serve as the interface for switching from UI automation to API-level automation
  • 13. Copyright © Gaspar NagyCopyright © Gaspar Nagy Introduce Page Objects
  • 14. Copyright © Gaspar NagyCopyright © Gaspar Nagy Introduce Page Objects
  • 15. Copyright © Gaspar NagyCopyright © Gaspar Nagy Introduce Page Objects
  • 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 Locators – Match your solution to the domain • If the solution is modeled on the basis of the problem space, the elements will have semantic identification • Question title – title column in DB – Title property in code - #Title [FindsBy(How = How.Id)] public IWebElement Title { get; set; }
  • 19. Copyright © Gaspar NagyCopyright © Gaspar Nagy Problem vs. solution domain Concept by Matt Wynne, see also http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/ Problem Domain Solution Domain Tweet • Tweet • Retweet Message • Send • Forward
  • 20. Copyright © Gaspar NagyCopyright © Gaspar Nagy Locating by ID is not enough! [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!
  • 21. Copyright © Gaspar NagyCopyright © Gaspar Nagy Locating by ID is not enough! [FindsBy(How = How.Id, Using = "cb9eb8be-71…")] public IWebElement Khaki { get; set; }
  • 22. Copyright © Gaspar NagyCopyright © Gaspar Nagy Be careful with Selenium IDE [FindsBy(How = How.CssSelector, Using = "input.btn.btn-default")] public IWebElement Fabric { get; set; } There was only one button on the page that time!
  • 23. 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
  • 24. 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
  • 26. Copyright © Gaspar NagyCopyright © Gaspar Nagy Unclear purpose Code duplication Anti- semantic locators Wrong abstraction Timing issues
  • 27. Copyright © Gaspar NagyCopyright © Gaspar Nagy Wrong abstraction
  • 28. 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
  • 30. 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
  • 31. Copyright © Gaspar NagyCopyright © Gaspar Nagy Encapsulate automation logic of UI concepts • Selenium’s PageFactory can only map IWebElement or List<IWebElement> • Defining a static helper method is already a good solution • like FillInTextBox(IWebElement elm, string value) • A factory infrastructure, similar to the PageFactory makes it even better
  • 32. Copyright © Gaspar NagyCopyright © Gaspar Nagy A concept-based page express concepts interact on concept level
  • 33. Copyright © Gaspar NagyCopyright © Gaspar Nagy Thread.Sleep(3000);
  • 34. Copyright © Gaspar NagyCopyright © Gaspar Nagy Why do we have this timing problem?
  • 35. Copyright © Gaspar NagyCopyright © Gaspar Nagy An example Enter text Post form Working, working… Observe result title.SendKeys(…); button.Click(); driver.FindElement(…);
  • 36. 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
  • 37. 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!
  • 38. Copyright © Gaspar NagyCopyright © Gaspar Nagy Waiting at the observation step… • Establishes an implicit dependency between the automation code triggering the action (Click) and the assertion (FindElement) • This makes the code brittle, because • you cannot compose new tests easily from the automation steps (e.g. the same assertion after another action) • the code will be sensitive to the order of the assertions • tests will be slowed down unnecessarily
  • 39. 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
  • 40. Copyright © Gaspar NagyCopyright © Gaspar Nagy An example Enter text Post form Working, working… Observe result title.SendKeys(…); button.SubmitClick(); driver.FindElement(…); Result page loaded
  • 41. Copyright © Gaspar NagyCopyright © Gaspar Nagy Define the waiting conditions for the interactions of the UI concepts! This is an example… • Submit concept – a concept that can trigger a server-side processing and results either in an error or a success • Success is indicated by a fully loaded page with a success message • Error is indicated by … • Fully loaded page means that the footer is visible • Solution: Implement SubmitConcept.Click() in a way that it clicks the button and is waiting either for the success or the error condition
  • 42. 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
  • 45. Gáspár Nagy coach • trainer • bdd addict • creator of specflow @gasparnagy • [email protected] Gáspár Nagy coach • trainer • bdd addict • creator of specflow @gasparnagy • [email protected] Thank you!