Practical Tips & Tricks for Selenium Test Automation
-
Upload
sauce-labs -
Category
Technology
-
view
5.582 -
download
0
Transcript of Practical Tips & Tricks for Selenium Test Automation
![Page 1: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/1.jpg)
Selenium Tips & Tricks
by Dave Haeffner
![Page 2: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/2.jpg)
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
![Page 5: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/5.jpg)
Headless
Benefits: - Speed - Maintenance - Screenshotting
http://se.tips/all-headless-browsers
![Page 6: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/6.jpg)
Headless w/ Xvfbhttp://elementalselenium.com/tips/38-headless
![Page 7: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/7.jpg)
Why use it?
Ideal for running small test suites on a headless machine e.g., a Continuous Integration (CI) Server
![Page 8: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/8.jpg)
NOTE- display port collisions - use unique values - e.g., CI build number
![Page 9: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/9.jpg)
NOTE- display port collisions - use unique values - e.g., CI build number
![Page 10: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/10.jpg)
Headless w/ GhostDriverhttp://elementalselenium.com/tips/46-headless-ghostdriver
![Page 12: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/12.jpg)
Why use it? • Faster execution times • Also useful for a CI server • Not limited to just Linux
![Page 13: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/13.jpg)
Step 2 - Start PhantomJS w/ WebDriver flag
Step 1 - Download PhantomJShttp://phantomjs.org/download.html
Step 3 - Connect Your Test to PhantomJS using Selenium Remote
NOTEYou can also connect PhantomJS to a Selenium Grid http://se.tips/ghost-driver-grid
Option 1
![Page 14: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/14.jpg)
![Page 15: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/15.jpg)
Step 2 - Tell Selenium where it is
Step 1 - Download PhantomJShttp://phantomjs.org/download.html
Step 3 - Launch Selenium with PhantomJS locally
Option 2
![Page 16: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/16.jpg)
![Page 17: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/17.jpg)
Visual Testing
![Page 18: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/18.jpg)
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
![Page 19: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/19.jpg)
Visual Testing Challenges
• Managing complexity
• False positives
• e.g., shifting content, dynamic content, typos
![Page 20: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/20.jpg)
![Page 21: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/21.jpg)
In pom.xml
![Page 22: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/22.jpg)
![Page 23: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/23.jpg)
![Page 24: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/24.jpg)
![Page 25: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/25.jpg)
![Page 26: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/26.jpg)
![Page 27: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/27.jpg)
![Page 28: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/28.jpg)
![Page 29: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/29.jpg)
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
![Page 30: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/30.jpg)
Selenium Grid Resources
• http://elementalselenium.com/tips/26-cloud
• http://elementalselenium.com/tips/52-grid
• http://elementalselenium.com/tips/70-grid-extras
![Page 31: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/31.jpg)
Fun with a Proxy Server
![Page 32: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/32.jpg)
Selenium Browser Proxy Server
Application Under Test
![Page 34: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/34.jpg)
HTTP Status Codeshttp://elementalselenium.com/tips/17-retrieve-http-status-codes
![Page 35: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/35.jpg)
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
![Page 36: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/36.jpg)
![Page 37: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/37.jpg)
![Page 38: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/38.jpg)
Blacklistinghttp://elementalselenium.com/tips/66-blacklist
![Page 39: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/39.jpg)
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)
![Page 40: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/40.jpg)
![Page 41: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/41.jpg)
![Page 42: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/42.jpg)
![Page 43: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/43.jpg)
Load Testinghttp://elementalselenium.com/tips/68-load-testing-revisited
![Page 44: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/44.jpg)
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)
![Page 45: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/45.jpg)
![Page 48: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/48.jpg)
Broken Image Checkinghttp://elementalselenium.com/tips/67-broken-images
![Page 49: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/49.jpg)
Option 1 - Proxy Server
Option 2 - HTTP Library
Option 3 - JavaScript
![Page 50: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/50.jpg)
Option 1: Proxy Server
![Page 51: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/51.jpg)
Option 1: Proxy Server
![Page 52: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/52.jpg)
Option 1: Proxy Server
![Page 53: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/53.jpg)
Option 2: HTTP Library
![Page 54: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/54.jpg)
Option 2: HTTP Library
![Page 55: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/55.jpg)
Option 2: HTTP Library
![Page 56: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/56.jpg)
Option 3: JavaScript
![Page 57: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/57.jpg)
Option 3: JavaScript
![Page 58: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/58.jpg)
Option 3: JavaScript
![Page 59: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/59.jpg)
Forgot Passwordhttp://elementalselenium.com/tips/43-forgot-password
![Page 60: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/60.jpg)
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)
![Page 61: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/61.jpg)
NOTE- not free - open issue
![Page 62: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/62.jpg)
A/B Testinghttp://elementalselenium.com/tips/12-opt-out-of-ab-tests
![Page 63: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/63.jpg)
![Page 64: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/64.jpg)
![Page 65: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/65.jpg)
• 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
![Page 66: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/66.jpg)
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
![Page 67: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/67.jpg)
![Page 68: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/68.jpg)
![Page 69: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/69.jpg)
![Page 70: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/70.jpg)
File Management
![Page 71: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/71.jpg)
Uploading a Filehttp://elementalselenium.com/tips/1-upload-a-file
![Page 72: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/72.jpg)
![Page 73: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/73.jpg)
Options
• GUI manipulation with something like AutoIt
• Input the file path into the form field (side-stepping the system dialog)
![Page 75: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/75.jpg)
Downloading a Filehttp://elementalselenium.com/tips/2-download-a-file http://elementalselenium.com/tips/8-download-a-file-revisited http://elementalselenium.com/tips/15-download-secure-files
![Page 76: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/76.jpg)
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
![Page 77: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/77.jpg)
With Selenium
![Page 78: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/78.jpg)
With Selenium
![Page 79: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/79.jpg)
With an HTTP library
![Page 80: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/80.jpg)
With an HTTP library
![Page 81: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/81.jpg)
Additional Output
![Page 82: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/82.jpg)
Highlight Elementshttp://elementalselenium.com/tips/65-highlight-elements
![Page 83: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/83.jpg)
![Page 84: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/84.jpg)
![Page 85: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/85.jpg)
Growl Notificationshttp://elementalselenium.com/tips/53-growl
![Page 86: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/86.jpg)
![Page 87: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/87.jpg)
![Page 88: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/88.jpg)
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
![Page 89: Practical Tips & Tricks for Selenium Test Automation](https://reader033.fdocuments.in/reader033/viewer/2022051101/586ff8791a28ab92198b767d/html5/thumbnails/89.jpg)
Available in Java and Ruby(C#, Python, & JS coming soon!)
https://seleniumguidebook.com