Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Selenium Tips & Tricks

10,780 views

Published on

A best of tips & tricks from the weekly Selenium tip newsletter Elemental

Published in: Software
  • Hello! Get Your Professional Job-Winning Resume Here - Check our website! https://vk.cc/818RFv
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • SAP Simple Finance, SAP Success Factors, SAP HANA, Fiori, BPC, SAP MM, SAP FICO, GST, SAP SD, SAP Basis, Training in Chennai & Bangalore India Online/Class Room. The Reach @ 8122241286 or 9003085882. http://www.thecreatingexperts.com People from HR,Fianance,Manufacturing, Logistics, Sales, Customer Care & IT, ITES,BPO, Industries can learn SAP Technology to Get High Pay Salary with long term career Growth. Best SAP Training Institute in Chennai with Placement Support
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Selenium Tips & Tricks

  1. 1. Selenium Tips & Tricks by Dave Haeffner @TourDeDave
  2. 2. New to Selenium? • Selenium Bootcamp http://bit.ly/se-bootcamp • Selenium Guidebook http://bit.ly/se-guidebook • Weekly Selenium Tips http://bit.ly/se-weekly-tips
  3. 3. http://ElementalSelenium.com
  4. 4. etc. http://the-internet.herokuapp.com/
  5. 5. Headless Benefits: - Speed - Maintenance - Screenshotting
  6. 6. Headless w/ Xvfb http://elementalselenium.com/tips/38-headless
  7. 7. Why use it? Ideal for running small test suites on a headless machine e.g., a Continuous Integration (CI) Server
  8. 8. NOTE - display port collisions - use unique values - e.g., CI build number
  9. 9. Headless w/ GhostDriver http://elementalselenium.com/tips/46-headless-ghostdriver
  10. 10. http://phantomjs.org/
  11. 11. Why use it? • Faster execution times • Also useful for a CI server • Not limited to just Linux
  12. 12. 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://bit.ly/ghost-driver-grid
  13. 13. Visual Testing
  14. 14. A Visual Testing Primer • check that an application’s UI appears correctly to its users • goal: find visual bugs before the user does • e.g., font, layout, rendering issues • can also be used to verify content • e.g., charts, dashboards, etc. • hundreds of assertions for a few lines of code • at least 16 open source solutions available to choose from
  15. 15. Visual Testing Challenges • Managing complexity • False positives • e.g., shifting content, dynamic content, typos
  16. 16. Visual Testing Write-ups http://bit.ly/se-visual-1 Getting Started http://bit.ly/se-visual-2 False Positives part 1 http://bit.ly/se-visual-3 False Positives part 2 http://bit.ly/se-visual-4 Add Visual Testing To Your Existing Tests http://bit.ly/se-visual-5 Add Visual Testing To Your BDD Tests
  17. 17. Selenium Grid Resources • http://elementalselenium.com/tips/26-cloud • http://elementalselenium.com/tips/52-grid • http://elementalselenium.com/tips/70-grid-extras
  18. 18. Fun with a Proxy Server
  19. 19. Selenium Browser Proxy Server Application Under Test
  20. 20. HTTP Status Codes http://elementalselenium.com/tips/17-retrieve-http-status-codes
  21. 21. 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
  22. 22. Blacklisting http://elementalselenium.com/tips/66-blacklist
  23. 23. 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)
  24. 24. Load Testing http://elementalselenium.com/tips/68-load-testing-revisited
  25. 25. 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)
  26. 26. Adapted from ruby-jmeter example from flood.io https://github.com/flood-io/ruby-jmeter
  27. 27. Broken Image Checking http://elementalselenium.com/tips/67-broken-images
  28. 28. Option 1 - Proxy Server Option 2 - HTTP Library Option 3 - JavaScript
  29. 29. Option 1: Proxy Server
  30. 30. Proxy Server Cont’d
  31. 31. Proxy Server Cont’d
  32. 32. Proxy Server Cont’d
  33. 33. Option 2: HTTP Library
  34. 34. HTTP Library Cont’d
  35. 35. HTTP Library Cont’d
  36. 36. Option 3: JavaScript
  37. 37. JavaScript Cont’d
  38. 38. JavaScript Cont’d
  39. 39. JavaScript Cont’d
  40. 40. Forgot Password http://elementalselenium.com/tips/43-forgot-password
  41. 41. Configuration • Use Selenium to trigger a forgot password workflow (to a Gmail account) and keep the browser session active • Retrieve the e-mail and the password information via the Gmail API • Use the password information in the active Selenium session (if applicable)
  42. 42. A/B Testing http://elementalselenium.com/tips/12-opt-out-of-ab-tests
  43. 43. • 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
  44. 44. 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
  45. 45. File Management
  46. 46. Uploading a File
  47. 47. Workaround • Rather than use something like AutoIt (which is a bad idea) • You can send the file path you want to upload into the form input field (side-stepping the system dialog entirely)
  48. 48. http://bit.ly/se-file-detector
  49. 49. 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
  50. 50. 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
  51. 51. With Selenium
  52. 52. With Selenium
  53. 53. With an HTTP library
  54. 54. With an HTTP library (for secure files)
  55. 55. Additional Output
  56. 56. Highlight Elements http://elementalselenium.com/tips/65-highlight-elements
  57. 57. Growl Notifications http://elementalselenium.com/tips/53-growl
  58. 58. New to Selenium? • Selenium Bootcamp http://bit.ly/se-bootcamp • Selenium Guidebook http://bit.ly/se-guidebook • Weekly Selenium Tips http://bit.ly/se-weekly-tips
  59. 59. http://ElementalSelenium.com http://bit.ly/oss-es-tips
  60. 60. Get in touch @TourDeDave dhaeffner@gmail.com DaveHaeffner.com

×