In this webinar, Dave Haeffner (Elemental Selenium, USA) discusses how to:
- Build an integrated feedback loop to automate test runs and find issues fast
- Setup your own infrastructure or connect to a cloud provider
-Dramatically improve test times with parallelization
https://huddle.eurostarsoftwaretesting.com/resource/webinar/use-selenium-successfully/
4. Write business valuable tests that are
reusable, maintainable and resilient
across all relevant browsers.
Then package and scale them for
you & your team.
5. Selenium Overview
• What it is — the Reader’s Digest version
• What it is and is not good at
• IDE vs. Local vs. Remote
• Slow, brittle, and hard to maintain?
11. Test Strategy
1. How does your business make money?
2. What features of your application are being used?
3. What browsers are your users using?
4. What things have broken before?
Outcome:
- What features to test
- Which browsers to care about
13. How To Pick a
Programming Language
• Same language as the app?
• Who will own it?
• Build a framework or use an existing one?
• http://se.tips/seleniumframeworks
15. Selenium Fundamentals
• Mimics human action
• Uses a few common actions
• Works with “locators”
Locators tell Selenium which HTML element to interact with
17. Locator Strategies
• Class
• CSS selectors
• ID
• Link Text
• Partial Link Text
• Tag Name
• XPath
Good locators are:
• unique
• descriptive
• unlikely to change
That rules a few of these out
18. Locator Strategies
• Class
• CSS selectors
• ID
• Link Text
• Partial Link Text
• Tag Name
• XPath
Good locators are:
• unique
• descriptive
• unlikely to change
That rules a few of these out
19. Locator Strategies
• Class
• CSS selectors
• ID
• Link Text
• Partial Link Text
• Tag Name
• XPath
Good locators are:
• unique
• descriptive
• unlikely to change
That rules a few of these out
Start with IDs and Classes
20. Locator Strategies
• Class
• CSS selectors
• ID
• Link Text
• Partial Link Text
• Tag Name
• XPath
Good locators are:
• unique
• descriptive
• unlikely to change
That rules a few of these out
Start with IDs and Classes
Use CSS or XPath (with care)
21. Locator Strategies
• Class
• CSS selectors
• ID
• Link Text
• Partial Link Text
• Tag Name
• XPath
CSS vs XPath
http://se.tips/seleniumbenchmarks
http://se.tips/cssxpathexamples
22. Finding Quality Locators
• Inspect the page
• Verify your selection
• e.g., FirePath or FireFinder
• e.g., JavaScript console with $$(‘’); or $(‘’);
• http://se.tips/verifyinglocators
• Learn through gaming
• http://se.tips/locatorgame
• Conversation
28. Good Test Anatomy
• Write for BDD or xUnit test framework
• Test one thing (atomic)
• Each test can be run independently (autonomous)
• Anyone can understand what it is doing
• Group similar tests together
29. A Login Example
1. Visit the login form
2. Find the login form’s username field and input text
3. Find the login form’s password field and input text
4. Find the submit button and click it
33. Now to find an assertion
1. Login
2. Inspect the page
3. Find a locator
4. Verify it
5. Add it to the test
34.
35. Assertion tips
• Only trust a test you’ve seen fail
• Check out Hamcrest matchers
http://se.tips/junit-hamcrest
36. Exception Handling
• org.openqa.selenium.NoSuchElementException:
Unable to locate element: {"method":"css
selector","selector":".flash.error"}
• Most common ones you’ll run into:
NoSuchElement and
StaleElementReferenceError
• A list of all WebDriver exceptions:
http://se.tips/se-exceptions-java
39. Automated 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
• Open-source libraries, baseline image comparison,
and inherent challenges
http://se.tips/visual-testing-getting-started
62. How everything fits together
Test TestTest
Page
Object
Page
Object
Base
Page
Object
Tests use page objects
Page objects inherit the
base page (utility) class
The base page object wraps
your Selenium commands
67. Waiting in Selenium
Implicit
• Specify an amount of time during test setup
• *Every* Selenium action will be retried until:
• The action can be completed, or
• The amount of time specified has been reached
(and throw an exception)
68. Waiting in Selenium
Explicit
• Specify an amount of time and an action (only
when you need it)
• Selenium will try *that* action repeatedly until:
• The action can be completed, or
• The amount of time specified has been reached
(and throw a Timeout exception)
82. Simple config with defaults
Import config where it’s needed
(e.g., base test, etc.)
83.
84. Reporting & Logging
• Machine readable
e.g., JUnit XML
• Human readable
e.g., screenshots, failure message, stack trace
Fantastic Test Report Tool
http://se.tips/se-reporter (Allure Framework)
Screenshot on Failure
http://se.tips/screenshot-on-failure
85. Parallelization
• In code
• Through your test runner
• Through your Continuous Integration (CI) server
#protip Enforce random order execution of tests
(turnkey in mvn-surefire)
Recommended approach:
http://se.tips/mvn-surefire
87. Test Grouping
• Metadata (a.k.a. Categories)
• Enables “test packs”
• Some category ideas
• defect
• shallow & deep
• release or story number
More info:
http://se.tips/junit-cat
99. Sauce Labs
Additional Considerations
- Test name
- Pass/Fail status
- Secure tunnel
More on Sauce:
http://se.tips/sauce-platform
http://se.tips/sauce-getting-started
http://se.tips/sauce-with-applitools
102. Feedback loops
• The goal: Find failures early and often
• Done with continuous integration and notifications
• Notifications
- remote: Email, chat, SMS
- in-person: audio/visual indicators
104. Simple CI configuration
1. Create a Job
2. Pull In Your Test Code
3. Set up Build Triggers
4. Configure Build steps
5. Configure Test Reports
6. Set up Notifications
7. Run Tests & View The Results
8. High-five your neighbor
108. Steps to solve the puzzle
1. Define a Test Strategy
2. Pick a programming language
3. Use Selenium Fundamentals
4. Write good tests
5. Write re-usable & maintainable code
6. Make your tests resilient with waits
7. Package your tests into a framework
8. Add in cross-browser execution
9. Build an automated feedback loop
10. Find information on your own
109. Write business valuable tests that are
reusable, maintainable and resilient
across all relevant browsers.
Then package them and scale them
for you & your team.
110. –Dave Haeffner
“You may think your puzzle is unique. But really, everyone is
trying to solve the same puzzle. Yours is just configured
differently — and it’s solvable”