Advertisement

Practical Tips & Tricks for Selenium Test Automation

Sr. Manager, Demand Generation & Operations
May. 25, 2016
Advertisement

More Related Content

Advertisement

More from Sauce Labs(20)

Advertisement

Practical Tips & Tricks for Selenium Test Automation

  1. Selenium Tips & Tricks by Dave Haeffner
  2. New to Selenium? • Selenium Bootcamp http://se.tips/se-bootcamp • Selenium Guidebook http://se.tips/se-guidebook • Weekly Selenium Tips http://se.tips/se-weekly-tips
  3. http://ElementalSelenium.com
  4. http://the-internet.herokuapp.com/
  5. Headless Benefits: - Speed - Maintenance - Screenshotting http://se.tips/all-headless-browsers
  6. Headless w/ Xvfb http://elementalselenium.com/tips/38-headless
  7. Why use it? Ideal for running small test suites on a headless machine e.g., a Continuous Integration (CI) Server
  8. NOTE - display port collisions - use unique values - e.g., CI build number
  9. NOTE - display port collisions - use unique values - e.g., CI build number
  10. Headless w/ GhostDriver http://elementalselenium.com/tips/46-headless-ghostdriver
  11. http://phantomjs.org/
  12. Why use it? • Faster execution times • Also useful for a CI server • Not limited to just Linux
  13. Step 2 - Start PhantomJS w/ WebDriver flag Step 1 - Download PhantomJS http://phantomjs.org/download.html Step 3 - Connect Your Test to PhantomJS using Selenium Remote NOTE You can also connect PhantomJS to a Selenium Grid http://se.tips/ghost-driver-grid Option 1
  14. Step 2 - Tell Selenium where it is Step 1 - Download PhantomJS http://phantomjs.org/download.html Step 3 - Launch Selenium with PhantomJS locally Option 2
  15. Visual Testing
  16. A Visual Testing Primer • Check that an application’s UI appears correctly • Can also be used to verify content • Hundreds of assertions for a few lines of code
  17. Visual Testing Challenges • Managing complexity • False positives • e.g., shifting content, dynamic content, typos
  18. In pom.xml
  19. Visual Testing Write-ups http://se.tips/se-visual-1 Getting Started http://se.tips/se-visual-2 False Positives part 1 http://se.tips/se-visual-3 False Positives part 2 http://se.tips/se-visual-4 Add Visual Testing To Your Existing Tests http://se.tips/se-visual-5 Add Visual Testing To Your BDD Tests
  20. Selenium Grid Resources • http://elementalselenium.com/tips/26-cloud • http://elementalselenium.com/tips/52-grid • http://elementalselenium.com/tips/70-grid-extras
  21. Fun with a Proxy Server
  22. Selenium Browser Proxy Server Application Under Test
  23. http://bmp.lightbody.net/
  24. HTTP Status Codes http://elementalselenium.com/tips/17-retrieve-http-status-codes
  25. Configuration • Use a proxy server to capture the traffic from your Selenium test(s) • Find the status code for the action you’re interested in (e.g., visiting a URL) • Assert that the status code is what you expect
  26. Blacklisting http://elementalselenium.com/tips/66-blacklist
  27. Configuration • Use a proxy server to manipulate the traffic from your Selenium test(s) • Identify third-party resources that are slow to load (which could negatively impact your tests) • Blacklist them (e.g., make it so they don’t load)
  28. Load Testing http://elementalselenium.com/tips/68-load-testing-revisited
  29. Configuration • Use a proxy server to capture the traffic from your Selenium test(s) • Convert the HTTP Archive into a JMeter JMX file • Run the new JMX file with JMeter to enact load on your application (modify as needed)
  30. https://flood.io/har2jmx
  31. http://se.tips/selenium-to-jmeter
  32. Broken Image Checking http://elementalselenium.com/tips/67-broken-images
  33. Option 1 - Proxy Server Option 2 - HTTP Library Option 3 - JavaScript
  34. Option 1: Proxy Server
  35. Option 1: Proxy Server
  36. Option 1: Proxy Server
  37. Option 2: HTTP Library
  38. Option 2: HTTP Library
  39. Option 2: HTTP Library
  40. Option 3: JavaScript
  41. Option 3: JavaScript
  42. Option 3: JavaScript
  43. Forgot Password http://elementalselenium.com/tips/43-forgot-password
  44. Configuration • Use Selenium to trigger a forgot password workflow (to an send to a real email address) and keep the browser session active • Retrieve the e-mail and the password information via the email provider’s API • Use the password information in the active Selenium session (if applicable)
  45. NOTE - not free - open issue
  46. A/B Testing http://elementalselenium.com/tips/12-opt-out-of-ab-tests
  47. • 3 page states available • You can identify which state you’re in because there is different header text for each • When you’re in the control: A/B Test Control • For the variation: A/B Test Variation 1 • When you’re not in a test: No A/B Test http://the-internet.herokuapp.com/abtest
  48. Configuration • You can easily opt-out of A/B tests by • forging a cookie • appending a query to the URL • This way you get a known state of the page which isn’t likely to change without your knowledge
  49. File Management
  50. Uploading a File http://elementalselenium.com/tips/1-upload-a-file
  51. Options • GUI manipulation with something like AutoIt • Input the file path into the form field (side-stepping the system dialog)
  52. http://se.tips/grid-file-upload
  53. Downloading a File http://elementalselenium.com/tips/2-download-a-file http://elementalselenium.com/tips/8-download-a-file-revisited http://elementalselenium.com/tips/15-download-secure-files
  54. Two approaches • Configure Selenium to download to local disk, and delete the file when done • Use an HTTP library, perform a HEAD request, and check the headers for the correct content type & length. Why? • An order of magnitude faster using Selenium • No need to download the file
  55. With Selenium
  56. With Selenium
  57. With an HTTP library
  58. With an HTTP library
  59. Additional Output
  60. Highlight Elements http://elementalselenium.com/tips/65-highlight-elements
  61. Growl Notifications http://elementalselenium.com/tips/53-growl
  62. More Selenium Resources • Selenium Bootcamp http://se.tips/se-bootcamp • Weekly Selenium Tips http://se.tips/se-weekly-tips • Weekly Se Tip Code http://se.tips/oss-tip-code • Selenium Guidebook http://se.tips/se-guidebook
  63. Available in Java and Ruby (C#, Python, & JS coming soon!) https://seleniumguidebook.com
Advertisement