Top Tips for Writing Better Selenium Tests
Santiago Suarez Ordoñez
Sauce Ninja & Selenium Committer
51 min, 24 sec
http://www.youtube.com/watch?v=WJnlOQ3zxro

My Notes:

  • Video quality is not great. Essentially a display of a code editor with too small of a font.
  • When build break due to flaky tests, developers stop trusting the build
  • Selenium 1 Tips
    • Implicit waits
      • Part of Selenium 2
      • Have to code yourself in Selenium 1. Hook into doCommand.
    • Reasonable timeouts (over 90s)
      • 30 seconds may be low when driving lots of browsers
    • Generate application states with test handles
      • Tendency is to write long test sequences
      • Better to have short sets of user actions that can be plugged together.
      • Even better if have some method to setup the application to meet the pre-requisites without having go through the steps a user must got through to get there.
      • Make sure these short cuts are turned off in production.
    • Wait for the right events (never ever use static pauses)
      • Do not use sleep
      • Implicit waits help
      • Even better is understanding how the elements appear within the application and take that into account with custom wait functions.
    • Don’t use verifications
      • Referring to the Selenium 1 “wait…” vs. “verify…” commands
      • Use the “wait…” variants.
      • Use asserts from your test frameworks instead.
    • Ignore Open and WaitForPageToLoad Features
      • Ignore the selenium failures for these commands
      • Behavior is inconsistent across browsers
      • Should behave like a user – of they see what they need to do, they do it vs waiting for the browser to say it is done. If the needed item is not there, the test will fail at that point.
  • Selenium 2 Tips
    • Selenium 2 is more robust than Selenium 1
    • Implicit Waits
      • Easier than Selenium 1
      • Use driver.implicitlyWait
    • Use findElement instead of a complex locator
      • Selenium 1 xpath and css locators may confuse people reading the code
      • Selenium 2 allows you to be explicit with how things are made, able to retrieve a list of items, interact with that list, etc. rather than using a complex selector
  • Sauce Tips
    • Report pass/fail status automatically
    • Use Sauce Connect 2
  •