+ All Categories
Home > Software > Selenium Tips & Tricks

Selenium Tips & Tricks

Date post: 14-Jul-2015
Category:
Upload: dave-haeffner
View: 5,699 times
Download: 2 times
Share this document with a friend
Popular Tags:
107
Selenium Tips & Tricks by Dave Haeffner @TourDeDave
Transcript
Page 1: Selenium Tips & Tricks

Selenium Tips & Tricks

by Dave Haeffner @TourDeDave

Page 2: Selenium Tips & Tricks

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

Page 3: Selenium Tips & Tricks

http://ElementalSelenium.com

Page 4: Selenium Tips & Tricks

etc. http://the-internet.herokuapp.com/

Page 5: Selenium Tips & Tricks

HeadlessBenefits: - Speed - Maintenance - Screenshotting

Page 6: Selenium Tips & Tricks

Headless w/ Xvfbhttp://elementalselenium.com/tips/38-headless

Page 7: Selenium Tips & Tricks

Why use it?

Ideal for running small test suites on a headless machine e.g., a Continuous Integration (CI) Server

Page 8: Selenium Tips & Tricks

NOTE- display port collisions - use unique values - e.g., CI build number

Page 9: Selenium Tips & Tricks
Page 10: Selenium Tips & Tricks

Headless w/ GhostDriverhttp://elementalselenium.com/tips/46-headless-ghostdriver

Page 11: Selenium Tips & Tricks

http://phantomjs.org/

Page 12: Selenium Tips & Tricks

Why use it?

• Faster execution times • Also useful for a CI server • Not limited to just Linux

Page 13: Selenium Tips & Tricks

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://bit.ly/ghost-driver-grid

Page 14: Selenium Tips & Tricks
Page 15: Selenium Tips & Tricks

Visual Testing

Page 16: Selenium Tips & Tricks

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

Page 17: Selenium Tips & Tricks

Visual Testing Challenges

• Managing complexity

• False positives

• e.g., shifting content, dynamic content, typos

Page 18: Selenium Tips & Tricks
Page 19: Selenium Tips & Tricks
Page 20: Selenium Tips & Tricks
Page 21: Selenium Tips & Tricks
Page 22: Selenium Tips & Tricks
Page 23: Selenium Tips & Tricks
Page 24: Selenium Tips & Tricks
Page 25: Selenium Tips & Tricks
Page 26: Selenium Tips & Tricks

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

Page 27: Selenium Tips & Tricks

Selenium Grid Resources

• http://elementalselenium.com/tips/26-cloud

• http://elementalselenium.com/tips/52-grid

• http://elementalselenium.com/tips/70-grid-extras

Page 28: Selenium Tips & Tricks

Fun with a Proxy Server

Page 29: Selenium Tips & Tricks

Selenium Browser Proxy Server

Application Under Test

Page 30: Selenium Tips & Tricks
Page 31: Selenium Tips & Tricks

HTTP Status Codeshttp://elementalselenium.com/tips/17-retrieve-http-status-codes

Page 32: Selenium Tips & Tricks

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 33: Selenium Tips & Tricks
Page 34: Selenium Tips & Tricks
Page 35: Selenium Tips & Tricks
Page 36: Selenium Tips & Tricks
Page 37: Selenium Tips & Tricks
Page 38: Selenium Tips & Tricks

Blacklistinghttp://elementalselenium.com/tips/66-blacklist

Page 39: Selenium Tips & Tricks

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: Selenium Tips & Tricks
Page 41: Selenium Tips & Tricks
Page 42: Selenium Tips & Tricks

Load Testinghttp://elementalselenium.com/tips/68-load-testing-revisited

Page 43: Selenium Tips & Tricks

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 44: Selenium Tips & Tricks
Page 45: Selenium Tips & Tricks
Page 46: Selenium Tips & Tricks

Adapted from ruby-jmeter example from flood.io https://github.com/flood-io/ruby-jmeter

Page 47: Selenium Tips & Tricks
Page 48: Selenium Tips & Tricks
Page 49: Selenium Tips & Tricks

Broken Image Checkinghttp://elementalselenium.com/tips/67-broken-images

Page 50: Selenium Tips & Tricks

Option 1 - Proxy Server

Option 2 - HTTP Library

Option 3 - JavaScript

Page 51: Selenium Tips & Tricks

Option 1: Proxy Server

Page 52: Selenium Tips & Tricks

Proxy Server Cont’d

Page 53: Selenium Tips & Tricks

Proxy Server Cont’d

Page 54: Selenium Tips & Tricks

Proxy Server Cont’d

Page 55: Selenium Tips & Tricks

Option 2: HTTP Library

Page 56: Selenium Tips & Tricks

HTTP Library Cont’d

Page 57: Selenium Tips & Tricks

HTTP Library Cont’d

Page 58: Selenium Tips & Tricks

Option 3: JavaScript

Page 59: Selenium Tips & Tricks

JavaScript Cont’d

Page 60: Selenium Tips & Tricks

JavaScript Cont’d

Page 61: Selenium Tips & Tricks

JavaScript Cont’d

Page 62: Selenium Tips & Tricks

Forgot Passwordhttp://elementalselenium.com/tips/43-forgot-password

Page 63: Selenium Tips & Tricks

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)

Page 64: Selenium Tips & Tricks
Page 65: Selenium Tips & Tricks
Page 66: Selenium Tips & Tricks
Page 67: Selenium Tips & Tricks
Page 68: Selenium Tips & Tricks
Page 69: Selenium Tips & Tricks

A/B Testinghttp://elementalselenium.com/tips/12-opt-out-of-ab-tests

Page 70: Selenium Tips & Tricks
Page 71: Selenium Tips & Tricks
Page 72: Selenium Tips & Tricks

• 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 73: Selenium Tips & Tricks

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 74: Selenium Tips & Tricks
Page 75: Selenium Tips & Tricks
Page 76: Selenium Tips & Tricks
Page 77: Selenium Tips & Tricks
Page 78: Selenium Tips & Tricks

File Management

Page 79: Selenium Tips & Tricks

Uploading a File

Page 80: Selenium Tips & Tricks
Page 81: Selenium Tips & Tricks

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)

Page 82: Selenium Tips & Tricks
Page 83: Selenium Tips & Tricks

http://bit.ly/se-file-detector

Page 84: Selenium Tips & Tricks

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 85: Selenium Tips & Tricks

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 86: Selenium Tips & Tricks

With Selenium

Page 87: Selenium Tips & Tricks

With Selenium

Page 88: Selenium Tips & Tricks
Page 89: Selenium Tips & Tricks
Page 90: Selenium Tips & Tricks

With an HTTP library

Page 91: Selenium Tips & Tricks

With an HTTP library (for secure files)

Page 92: Selenium Tips & Tricks
Page 93: Selenium Tips & Tricks

Additional Output

Page 94: Selenium Tips & Tricks

Highlight Elementshttp://elementalselenium.com/tips/65-highlight-elements

Page 95: Selenium Tips & Tricks
Page 96: Selenium Tips & Tricks
Page 97: Selenium Tips & Tricks
Page 98: Selenium Tips & Tricks
Page 99: Selenium Tips & Tricks
Page 100: Selenium Tips & Tricks

Growl Notificationshttp://elementalselenium.com/tips/53-growl

Page 101: Selenium Tips & Tricks
Page 102: Selenium Tips & Tricks
Page 103: Selenium Tips & Tricks
Page 104: Selenium Tips & Tricks
Page 105: Selenium Tips & Tricks

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

Page 106: Selenium Tips & Tricks

http://ElementalSelenium.com http://bit.ly/oss-es-tips

Page 107: Selenium Tips & Tricks

Get in touch

@TourDeDave

[email protected]

DaveHaeffner.com


Recommended