SlideShare a Scribd company logo
1 of 27
Selenium In The Real World
Where are the tests, and how do I run them?
Iain Rose May 2012
INTRO
A bit about me




Iain Rose
Software Engineer in Test, xMatters




slides:          http://bit.ly/vanq
code:            https://github.com/iainrose/vanq-java




twitter: @iainrose
email: irose@xmatters.com
AGENDA
Coming up next




•     Selenium & friends
•     Page objects
•     Locators
•     Implicit & explicit waits
•     Building your tests
•     Running your tests




THERE WILL BE CODE!!!
W H Y A U T O M AT E ?
Regression testing sucks
SELENIUM AND FRIENDS
The world it lives in




•       WebDriver API (Java / Ruby / Python / C#)

•       Test Frameworks
                  Java (jUnit, TestNG)
                  Ruby (Test::Unit, MiniTest, Rspec, Cucumber)
                  Python (py.test)
                  C# (nUnit)

•       Build Tools (Ant, Maven, Gradle, Rake .... )

•       Continuous Integration Server (Jenkins, Bamboo, Cruise Control)

•       Browsers (IE, FF, Chrome, Mobile .... )

•       Application Under Test
A W ORD ABOUT SELENIUM IDE
Use with caution
R E C O R D & P L AY B A C K ( I S ) F O R D U M M I E S
A shortcut to brittle, flaky tests
PA G E O B J E C T S
A test automation design pattern




                                    PAGE
          TESTS                              SELENIUM   WEB APP
                                   OBJECTS
PA G E O B J E C T S
Usage guidelines




 •     The public methods represent the services that the page offers
 •     Try not to expose the internals of the page
 •     Generally don't make assertions
 •     Methods return other Page Objects
 •     Need not represent an entire page
 •     Different results for the same action are modelled as different methods




http://code.google.com/p/selenium/wiki/PageObjects
PA G E O B J E C T E X A M P L E : VA N Q . O R G
Identifying Public Methods




                                                    class Home

                                                    clickMeetingsTab()
                                                    clickPastMeetingsLink()
                                                    getDateOfNextMeeting()
                                                    getPresenterOfNextMeeting()
                                                    isVanqLogoDisplayed()
PA G E O B J E C T E X A M P L E : VA N Q . O R G
Sample test method
PA G E O B J E C T E X A M P L E : VA N Q . O R G
Sample page object
L O C AT O R S
A map to your web application
L O C AT O R S
Ways to save your locators




   •      Inline




   •      Page Factory




   •      By Objects
L O C AT O R S
Why I prefer By objects




•      WebDriver does not have an isElementPresent() method.
L O C AT O R S
Why I prefer By object locators




•      By locators allow for nested lookups
FIREFINDER PLUGIN FOR FIREFOX
A tool for testing CSS & xPath locators
WAIT CONDITIONS
Timing is everything




•      Implicit Waits




    + Quick to implement
    + Covers most scenarios

    - Slows down tests
    - Cannot use to wait for absence of Web Elements
WAIT CONDITIONS
Timing is everything




•      Explicit Waits
WAIT CONDITIONS
Explicit Waits




+ Most efficient use of waits
+ Built in ExpectedConditions class covers majority of scenarios
+ Custom wait conditions can be added to cover any other scenario

- Need to be manually added to each Page Object method




http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html
WAIT CONDITIONS
Usage Guidelines




•     Avoid static pauses
•     Use long timeouts
•     Add explicit waits to end of page object ‘action’ methods
•     Always leave your Web Application in known ready state
BUILDING THE TESTS
Lessons learnt so far




•      Keep tests focused
•      Don’t share test data
•      Do test data tear down at the start of each test
•      Plan to run in parallel from day 1
RUNNING THE TESTS
Time for action




•      IDE (Run & Debug)
•      Command Line (Remote and Local)
•      CI Tool
•      Selenium Grid
GRADLE
Build Tool




•      No XML
•      Can setup your development IDE (IDEA, Eclipse)
•      Dependency management
•      1 line of code runs TestNG & jUnit tests in parallel
•      Manage TestNG group inclusions and exclusions
•      No XML
•      No XML
BUILD.GRADLE
Project Definition
D E M O N S T R AT I O N
Time for action

More Related Content

What's hot

Test automation expert days
Test automation   expert daysTest automation   expert days
Test automation expert daysOren Rubin
 
Front-end Automated Testing
Front-end Automated TestingFront-end Automated Testing
Front-end Automated TestingRuben Teijeiro
 
Ukoug webinar - testing PLSQL APIs with utPLSQL v3
Ukoug webinar - testing PLSQL APIs with utPLSQL v3Ukoug webinar - testing PLSQL APIs with utPLSQL v3
Ukoug webinar - testing PLSQL APIs with utPLSQL v3Jacek Gebal
 
The Evil Tester's Guide to HTTP proxies Tutorial
The Evil Tester's Guide to HTTP proxies TutorialThe Evil Tester's Guide to HTTP proxies Tutorial
The Evil Tester's Guide to HTTP proxies TutorialAlan Richardson
 
Nightwatch JS for End to End Tests
Nightwatch JS for End to End TestsNightwatch JS for End to End Tests
Nightwatch JS for End to End TestsSriram Angajala
 
How to build rock solid apps & keep 100m+ users happy
How to build rock solid apps & keep 100m+ users happyHow to build rock solid apps & keep 100m+ users happy
How to build rock solid apps & keep 100m+ users happyIordanis (Jordan) Giannakakis
 

What's hot (6)

Test automation expert days
Test automation   expert daysTest automation   expert days
Test automation expert days
 
Front-end Automated Testing
Front-end Automated TestingFront-end Automated Testing
Front-end Automated Testing
 
Ukoug webinar - testing PLSQL APIs with utPLSQL v3
Ukoug webinar - testing PLSQL APIs with utPLSQL v3Ukoug webinar - testing PLSQL APIs with utPLSQL v3
Ukoug webinar - testing PLSQL APIs with utPLSQL v3
 
The Evil Tester's Guide to HTTP proxies Tutorial
The Evil Tester's Guide to HTTP proxies TutorialThe Evil Tester's Guide to HTTP proxies Tutorial
The Evil Tester's Guide to HTTP proxies Tutorial
 
Nightwatch JS for End to End Tests
Nightwatch JS for End to End TestsNightwatch JS for End to End Tests
Nightwatch JS for End to End Tests
 
How to build rock solid apps & keep 100m+ users happy
How to build rock solid apps & keep 100m+ users happyHow to build rock solid apps & keep 100m+ users happy
How to build rock solid apps & keep 100m+ users happy
 

Similar to Selenium In The Real World

How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfullyTEST Huddle
 
Colorful world-of-visual-automation-testing-latest
Colorful world-of-visual-automation-testing-latestColorful world-of-visual-automation-testing-latest
Colorful world-of-visual-automation-testing-latestOnur Baskirt
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testingdrewz lin
 
Enterprise Strength Mobile JavaScript
Enterprise Strength Mobile JavaScriptEnterprise Strength Mobile JavaScript
Enterprise Strength Mobile JavaScriptTroy Miles
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Applitools
 
Automated Testing of Web Applications
Automated Testing of Web ApplicationsAutomated Testing of Web Applications
Automated Testing of Web Applicationsjonatankronqvist
 
Shifting landscape of mobile automation, and the future of Appium - Jonathan ...
Shifting landscape of mobile automation, and the future of Appium - Jonathan ...Shifting landscape of mobile automation, and the future of Appium - Jonathan ...
Shifting landscape of mobile automation, and the future of Appium - Jonathan ...Applitools
 
Quick start with AngularJS
Quick start with AngularJSQuick start with AngularJS
Quick start with AngularJSIuliia Baranova
 
Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014Wojciech Seliga
 
Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsBrowser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsLuís Bastião Silva
 
Automation Abstractions: Page Objects and Beyond
Automation Abstractions: Page Objects and BeyondAutomation Abstractions: Page Objects and Beyond
Automation Abstractions: Page Objects and BeyondTechWell
 
Selendroid in Action
Selendroid in ActionSelendroid in Action
Selendroid in ActionDominik Dary
 
Testing of React JS app
Testing of React JS appTesting of React JS app
Testing of React JS appAleks Zinevych
 
DSL, Page Object и WebDriver – путь к надежным функциональным тестам
DSL, Page Object и WebDriver – путь к надежным функциональным тестамDSL, Page Object и WebDriver – путь к надежным функциональным тестам
DSL, Page Object и WebDriver – путь к надежным функциональным тестамSQALab
 
Good practices for debugging Selenium and Appium tests
Good practices for debugging Selenium and Appium testsGood practices for debugging Selenium and Appium tests
Good practices for debugging Selenium and Appium testsAbhijeet Vaikar
 
How do you tame a big ball of mud? One test at a time.
How do you tame a big ball of mud? One test at a time.How do you tame a big ball of mud? One test at a time.
How do you tame a big ball of mud? One test at a time.Matt Eland
 
10 Useful Testing Tools for Open Source Projects @ TuxCon 2015
10 Useful Testing Tools for Open Source Projects @ TuxCon 201510 Useful Testing Tools for Open Source Projects @ TuxCon 2015
10 Useful Testing Tools for Open Source Projects @ TuxCon 2015Peter Sabev
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupSelenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupDave Haeffner
 
DSL, Page Object and WebDriver – the path to reliable functional tests.pptx
DSL, Page Object and WebDriver – the path to reliable functional tests.pptxDSL, Page Object and WebDriver – the path to reliable functional tests.pptx
DSL, Page Object and WebDriver – the path to reliable functional tests.pptxMikalai Alimenkou
 

Similar to Selenium In The Real World (20)

How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
 
Colorful world-of-visual-automation-testing-latest
Colorful world-of-visual-automation-testing-latestColorful world-of-visual-automation-testing-latest
Colorful world-of-visual-automation-testing-latest
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testing
 
Enterprise Strength Mobile JavaScript
Enterprise Strength Mobile JavaScriptEnterprise Strength Mobile JavaScript
Enterprise Strength Mobile JavaScript
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully
 
Automated Testing of Web Applications
Automated Testing of Web ApplicationsAutomated Testing of Web Applications
Automated Testing of Web Applications
 
Shifting landscape of mobile automation, and the future of Appium - Jonathan ...
Shifting landscape of mobile automation, and the future of Appium - Jonathan ...Shifting landscape of mobile automation, and the future of Appium - Jonathan ...
Shifting landscape of mobile automation, and the future of Appium - Jonathan ...
 
Quick start with AngularJS
Quick start with AngularJSQuick start with AngularJS
Quick start with AngularJS
 
Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014
 
Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsBrowser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.js
 
Automated ui-testing
Automated ui-testingAutomated ui-testing
Automated ui-testing
 
Automation Abstractions: Page Objects and Beyond
Automation Abstractions: Page Objects and BeyondAutomation Abstractions: Page Objects and Beyond
Automation Abstractions: Page Objects and Beyond
 
Selendroid in Action
Selendroid in ActionSelendroid in Action
Selendroid in Action
 
Testing of React JS app
Testing of React JS appTesting of React JS app
Testing of React JS app
 
DSL, Page Object и WebDriver – путь к надежным функциональным тестам
DSL, Page Object и WebDriver – путь к надежным функциональным тестамDSL, Page Object и WebDriver – путь к надежным функциональным тестам
DSL, Page Object и WebDriver – путь к надежным функциональным тестам
 
Good practices for debugging Selenium and Appium tests
Good practices for debugging Selenium and Appium testsGood practices for debugging Selenium and Appium tests
Good practices for debugging Selenium and Appium tests
 
How do you tame a big ball of mud? One test at a time.
How do you tame a big ball of mud? One test at a time.How do you tame a big ball of mud? One test at a time.
How do you tame a big ball of mud? One test at a time.
 
10 Useful Testing Tools for Open Source Projects @ TuxCon 2015
10 Useful Testing Tools for Open Source Projects @ TuxCon 201510 Useful Testing Tools for Open Source Projects @ TuxCon 2015
10 Useful Testing Tools for Open Source Projects @ TuxCon 2015
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupSelenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
 
DSL, Page Object and WebDriver – the path to reliable functional tests.pptx
DSL, Page Object and WebDriver – the path to reliable functional tests.pptxDSL, Page Object and WebDriver – the path to reliable functional tests.pptx
DSL, Page Object and WebDriver – the path to reliable functional tests.pptx
 

Recently uploaded

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 

Recently uploaded (20)

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 

Selenium In The Real World

  • 1. Selenium In The Real World Where are the tests, and how do I run them? Iain Rose May 2012
  • 2. INTRO A bit about me Iain Rose Software Engineer in Test, xMatters slides: http://bit.ly/vanq code: https://github.com/iainrose/vanq-java twitter: @iainrose email: irose@xmatters.com
  • 3. AGENDA Coming up next • Selenium & friends • Page objects • Locators • Implicit & explicit waits • Building your tests • Running your tests THERE WILL BE CODE!!!
  • 4. W H Y A U T O M AT E ? Regression testing sucks
  • 5.
  • 6. SELENIUM AND FRIENDS The world it lives in • WebDriver API (Java / Ruby / Python / C#) • Test Frameworks Java (jUnit, TestNG) Ruby (Test::Unit, MiniTest, Rspec, Cucumber) Python (py.test) C# (nUnit) • Build Tools (Ant, Maven, Gradle, Rake .... ) • Continuous Integration Server (Jenkins, Bamboo, Cruise Control) • Browsers (IE, FF, Chrome, Mobile .... ) • Application Under Test
  • 7. A W ORD ABOUT SELENIUM IDE Use with caution
  • 8. R E C O R D & P L AY B A C K ( I S ) F O R D U M M I E S A shortcut to brittle, flaky tests
  • 9. PA G E O B J E C T S A test automation design pattern PAGE TESTS SELENIUM WEB APP OBJECTS
  • 10. PA G E O B J E C T S Usage guidelines • The public methods represent the services that the page offers • Try not to expose the internals of the page • Generally don't make assertions • Methods return other Page Objects • Need not represent an entire page • Different results for the same action are modelled as different methods http://code.google.com/p/selenium/wiki/PageObjects
  • 11. PA G E O B J E C T E X A M P L E : VA N Q . O R G Identifying Public Methods class Home clickMeetingsTab() clickPastMeetingsLink() getDateOfNextMeeting() getPresenterOfNextMeeting() isVanqLogoDisplayed()
  • 12. PA G E O B J E C T E X A M P L E : VA N Q . O R G Sample test method
  • 13. PA G E O B J E C T E X A M P L E : VA N Q . O R G Sample page object
  • 14. L O C AT O R S A map to your web application
  • 15. L O C AT O R S Ways to save your locators • Inline • Page Factory • By Objects
  • 16. L O C AT O R S Why I prefer By objects • WebDriver does not have an isElementPresent() method.
  • 17. L O C AT O R S Why I prefer By object locators • By locators allow for nested lookups
  • 18. FIREFINDER PLUGIN FOR FIREFOX A tool for testing CSS & xPath locators
  • 19. WAIT CONDITIONS Timing is everything • Implicit Waits + Quick to implement + Covers most scenarios - Slows down tests - Cannot use to wait for absence of Web Elements
  • 20. WAIT CONDITIONS Timing is everything • Explicit Waits
  • 21. WAIT CONDITIONS Explicit Waits + Most efficient use of waits + Built in ExpectedConditions class covers majority of scenarios + Custom wait conditions can be added to cover any other scenario - Need to be manually added to each Page Object method http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html
  • 22. WAIT CONDITIONS Usage Guidelines • Avoid static pauses • Use long timeouts • Add explicit waits to end of page object ‘action’ methods • Always leave your Web Application in known ready state
  • 23. BUILDING THE TESTS Lessons learnt so far • Keep tests focused • Don’t share test data • Do test data tear down at the start of each test • Plan to run in parallel from day 1
  • 24. RUNNING THE TESTS Time for action • IDE (Run & Debug) • Command Line (Remote and Local) • CI Tool • Selenium Grid
  • 25. GRADLE Build Tool • No XML • Can setup your development IDE (IDEA, Eclipse) • Dependency management • 1 line of code runs TestNG & jUnit tests in parallel • Manage TestNG group inclusions and exclusions • No XML • No XML
  • 27. D E M O N S T R AT I O N Time for action

Editor's Notes

  1. Automation can help with exploratory testing. Simultaneous testing & learningAutomation can increase learning about the application as you peel the onionRegression testing typically catches less bugs than exploratory testing a product for the first timeAutomated testing by definition is regression testing.Less time spent regression testing means more time exploratory testingAutomation scripts become your exploratory testing notesCan help improve working relationships and communication between testers and developersIt’s fun
  2. Everything I’m going to present is a work in progressWeb Driver is a new tool first stable release was Selenium 2.0 (July 2011)No best practices, find the solution that best fits your application and team dynamicsTesting and checking are different things. Strictly speaking automation is checking
  3. Selenium only automates browsers. Needs some help before it can be used to run tests.Selenium 1 is unsupportedPick the API that makes your test team more productive. Not necessarily the same language that your application is written in.
  4. Beware of automation tools with ‘no coding required’Automation projects are development projects----- Meeting Notes (12-05-28 10:56) -----Lets show an example of how we would record a test against the VanQ.org web site
  5. Issues apply to all record and playback toolsIssues:Browser selection embedded in the testBaseUrl embedded in the testBrittle xpath locators, some are 10 levels deepDuplicated use of locatorsText search scope is too broad, searching entire documentNo assertions = no resultsRecord & Playback can be useful for …Supplementing bug reports, imagine seeing the last ‘works on my machine’ comment ever!Quick demonstrations
  6. Page Object allow us to add a layer of separation between our tests, selenium and the application under testReduces code duplication and allows you to define each action and locator once only, significantly reduces maintenance efforts WHEN things start to changeIncreases test code reaability
  7. Public methods can be getters / setters / mouse driven actions
  8. A web page is a class of objectThe VanQ home page is an instance of a Web Page classThe VanQ home page has propertiesThe VanQ home page offers public facing methods to interact with itThe VanQ home page inherits methods from a parent page object that represents the nav bar and page header / footerThe VanQ home page allows you to navigate to other web pages (represented by other page objects)
  9. Tests are written in the language of your applicationNo Web Driver code in the testsNo details of web application internals in the test
  10. Locators vs Web ElementsWeb Elements are objects on the page you can interact with (click, getText(), etc)Locators are a map to find your Web ElementsPage Objects generally don't make assertionsException to the rule is on transition from one Page Object to anotherRecommend find a strategy for your web application that can be used to determine if the web application is on the correct page. (URL, Title, Page Content, Key Element Locator)
  11. Keep locators as simple as possible and use a few criteria as possible to make a unique match.Good locators will pass the mother in law testRecommend reading up on CSS locators.SauceLabs blog has good articlesCSS can be just as brittle as xPathxPath slow in IE
  12. Casting Web Elements using inline locators cannot be shared across methods. Locators will get duplicatedPage Factory is a support library. Allows Web Elements to be shared across all methods in a page object while eliminating some boiler plate codeFirst 2 methods use your locators to save a Web Element Using By objects means you save the locator itself, not the target Web Element. You use these in your page object methods to find the WebElements as they are neededRecommend using By objects as they are the most flexible and can be reused in lookups and waits
  13. Building your own is trivial but the findElement method returns an exception is Element is not found.By objects can be used by findElements methods which returns a list of all elements found by the provided locatorSaving your locators as By objects in the first place means you don’t need to duplicate your locators if you ever need to check for the presence or absence of a web element on the pageBy objects locators allow you to control exactly when the WebElement is looked up and assigned to a variable. This can avoid stale element exceptions when testing ajax heavy web pages (drag and drop, etc)By objects can be used in explicit wait conditions
  14. Another reason to use By locators is they can be reused in waits which leads to next section
  15. FindElement methods returns 1st Web Element found by locators not necessarily the only Web ElementAlways test your locators, there might be hidden elements on the page you cannot see
  16. Effective use of wait conditions are the single most important feature to learn to.There is no waitForPageToLoad method in WebDriver, even if there was how to define a rule of when page is loaded?Implicit Waits always make the maximum in findElements
  17. Explicit waits have a single purpose and are always used on demand
  18. Efficient becuase they never wait short or longEfficient because are only used when you explicitly instruct the test to do so Another reason to use By objects as your locator strategy
  19. Static pauses will always wait short or wait long. Both badDon’t mix performance tests and functional testsAllow for slow performing test environmentsMake page object methods leave the web application ready to use
  20. Compare to exploratory tests where you do as much as you can at onceBetter to have 15 tests that do a single assertion than 1 test that does 15Use clear, specific names for test methodsDon’t worry about test name lengthUse a BaseTest class to handle browser setup and tear downUse @BeforeClass annotations to handle test data setupDon’t share test data across tests that make data updates
  21. No
  22. Do not show this slide in your presentation, but instead use it to copy and past elements to your slides. This page can also be found in the master slides incase it is deleted.