SlideShare a Scribd company logo
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 In The Real World
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

PDF
Use React Patterns to Build Large Scalable App
PDF
Enhance react app with patterns - part 1: higher order component
PDF
Lets make a better react form
PDF
軟體測試是在測試什麼?
PDF
Refactor your way forward
PDF
Introducing Playwright's New Test Runner
PDF
Behave manners for ui testing pycon2019
PDF
Dave Haeffner's Proven Method to Grading the Quality of Selenium Tests
Use React Patterns to Build Large Scalable App
Enhance react app with patterns - part 1: higher order component
Lets make a better react form
軟體測試是在測試什麼?
Refactor your way forward
Introducing Playwright's New Test Runner
Behave manners for ui testing pycon2019
Dave Haeffner's Proven Method to Grading the Quality of Selenium Tests

What's hot (6)

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

Similar to Selenium In The Real World (20)

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

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PPT
Teaching material agriculture food technology
PPTX
Big Data Technologies - Introduction.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Spectroscopy.pptx food analysis technology
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation theory and applications.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Unlocking AI with Model Context Protocol (MCP)
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
A comparative analysis of optical character recognition models for extracting...
Teaching material agriculture food technology
Big Data Technologies - Introduction.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Spectroscopy.pptx food analysis technology
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation theory and applications.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Spectral efficient network and resource selection model in 5G networks
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Network Security Unit 5.pdf for BCA BBA.
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
sap open course for s4hana steps from ECC to s4
Dropbox Q2 2025 Financial Results & Investor Presentation
“AI and Expert System Decision Support & Business Intelligence Systems”

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
  • 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

  • #5: 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
  • #6: 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
  • #7: 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.
  • #8: 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
  • #9: 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
  • #10: 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
  • #11: Public methods can be getters / setters / mouse driven actions
  • #12: 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)
  • #13: Tests are written in the language of your applicationNo Web Driver code in the testsNo details of web application internals in the test
  • #14: 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)
  • #15: 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
  • #16: 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
  • #17: 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
  • #18: Another reason to use By locators is they can be reused in waits which leads to next section
  • #19: 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
  • #20: 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
  • #21: Explicit waits have a single purpose and are always used on demand
  • #22: 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
  • #23: 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
  • #24: 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
  • #26: No
  • #29: 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.