SlideShare a Scribd company logo
How To Use Selenium,
Successfully
by Dave Haeffner, @TourDeDave
http://www.wpclipart.com/geography/features/chasm.png.html
http://en.wikipedia.org/wiki/Optimal_solutions_for_Rubik's_Cube
Write business valuable tests that are
reusable, maintainable and resilient
across all relevant browsers.
Then package and scale them for
you & your team.
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?
Step 1
Define a Test Strategy
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 in the app before?
Outcome: What to test and which
browsers to care about
Step 2
Pick a Programming
Language
Programming Language
• Same language as the app?
• Who will own it?
• Build a framework or use an existing one?
• http://bit.ly/seleniumframeworks
• Vim, Emacs, Sublime Text
• IntelliJ, Eclipse
Choose an Editor
Step 3
Use Selenium
fundamentals
Selenium Fundamentals
• Mimics human action
• Uses a few common actions
• Works with “locators”
Locators tell Selenium which HTML
element to interact with
Common Actions
• get();
• findElement();
• click(); //or submit();
• sendKeys();
• isDisplayed();
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
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
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
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)
Locator Strategies
• Class
• CSS selectors
• ID
• Link Text
• Partial Link Text
• Tag Name
• XPath
CSS vs XPath
http://bit.ly/seleniumbenchmarks
http://bit.ly/cssxpathexamples
Finding Quality Locators
• Inspect the page
• Verify your selection
• e.g., FirePath or FireFinder
• http://bit.ly/verifyinglocators
• Learn through gaming
• http://bit.ly/locatorgame
• Conversation
How To Use Selenium Successfully (Java Edition)
Step 4
Write your first test
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
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
http://the-internet.herokuapp.com/login
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)
Now to find an assertion
1. Login
2. Inspect the page
3. Find a locator
4. Verify it
5. Add it to the test
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)
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://bit.ly/se-exceptions-java
Exception Handling cont’d
http://bit.ly/se-exceptions-howto
Step 5
Write reusable and
maintainable test code
Page Objects
Application Under Test
Test 1 Test 2 Test 3 Test 4 Test 5Test 1 Test 2 Test 3 Test 4 Test 5
Need to update EVERY test :-(
Application Under TestPage Object(s)
Test 1 Test 2 Test 3 Test 4 Test 5Test 1 Test 2 Test 3 Test 4 Test 5
Need to update JUST the page object :-D
Let’s look at a page
object for login
How To Use Selenium Successfully (Java Edition)
And here’s what the test
looks like when using it
Page object helpers:
http://bit.ly/po-html-elements
http://bit.ly/po-page-factory
Base Page Object
Selenium
Commands
Page
Object 1
Page
Object 2
Page
Object 3
Page
Object 4
Page
Object 5
Base Page
Object
Page
Object 1
Page
Object 2
Page
Object 3
Page
Object 4
Page
Object 5
Selenium
Commands
• Global reuse
• More readable
• Insulates you from
Selenium API changes
http://bit.ly/se-upgrade
Let’s take a look at a
Base Page Object
How To Use Selenium Successfully (Java Edition)
And here it is
implemented
How To Use Selenium Successfully (Java Edition)
How everything fits together
Test TestTest
Page
Object
Page
Object
Base
Page
Object
Tests use page objects
Page objects use the
base page object
The base page object uses
Selenium commands
Step 6
Make your tests resilient
Waiting
Explicit Waits
• Specify an amount of time, and an action
• Selenium will try repeatedly until either:
• The action is completed, or
• The amount of time specified has been reached
(and throw a timeout exception)
How To Use Selenium Successfully (Java Edition)
In the Base page object
In the DynamicLoading page object
Browser Timing
Considerations
Step 7
Prep for use
Test Harness
• Simple organizational structure
• Central setup and teardown
• Configurable at run-time (with sensible defaults)
• Reporting & Logging
• Parallelization
• Test Grouping
Folder structure
Central setup/teardown
More on JUnit Rules:
http://bit.ly/junit-rules
Simple config with defaults
Reporting & Logging
• Machine readable

e.g., JUnit XML
• Human readable

e.g., screenshots, failure message, stack trace
Fantastic Test Report Tool
http://bit.ly/se-reporter (Allure Framework)
Parallelization
• In code
• Through your test runner
• Through your Continuous Integration (CI) server
#protip Enforce random order execution of tests
http://bit.ly/junit-random-order
Recommended approach:
http://bit.ly/mvn-surefire
Test Grouping
• Metadata (a.k.a. Categories)
• Enables “test packs”
• Some category ideas
• wip
• shallow
• deep
• story number
More info:
bit.ly/junit-categories
Step 8
Add in cross-browser
execution
Locally
http://bit.ly/se-chromedriver
http://bit.ly/se-firefoxdriver
http://bit.ly/se-iedriver
http://bit.ly/se-operadriver (12.16)
http://bit.ly/se-safaridriver
Chrome
Grid
Grid Hub
Browser
Tests
All done with the Selenium Standalone Server
Just requires additional runtime flags
Grid
Node
Grid
Node
Grid
Node
Browser
Browser
Grid
Hub
Node(s)
Grid
More on Selenium Grid
http://bit.ly/se-grid-docs
http://bit.ly/se-grid-post
http://bit.ly/se-grid-extras
http://bit.ly/se-grid-scaler
Sauce Labs
Sauce Labs Browser
Tests
Sauce Labs
Additional Considerations
- Test name
- Pass/Fail status
- Secure tunnel
More on Sauce:
http://bit.ly/sauce-platforms
http://bit.ly/sauce-post
http://bit.ly/sauce-tutorial-java
How To Use Selenium Successfully (Java Edition)
Step 9
Build an automated
feedback loop
Feedback loops
• The goal: Find failures early and often
• Done with continuous integration and notifications
• Notifications

e.g., remote: Email, chat, SMS

in-person: audio/visual, public shaming
Code
Committed
Unit/Integ.
(pass?)
Deploy to
autom. test
server
(success?)
Run
automated
tests
(pass?)
Deploy to
next env.
yes
yes
yes
Notify team if no
Code Promotion
Bonus points: stop the line
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
How To Use Selenium Successfully (Java Edition)
Step 10
Find information on
your own
http://bit.ly/se-info-slides
http://bit.ly/se-info-video
Elemental Selenium (3)
Selenium HQ (1)
Documentation & Tips
Issue Tracker Guidance (23)
Straight To The Source (24)
IRC Chat Channel (25)
Selenium Testing Tools Cookbook (18)
The Selenium Guidebook (19)
Selenium Design Patterns (21)
All in-person Selenium Meetups (13)
How to start your own (14)
Selenium Developer Google Group (10)
Agile Testing Yahoo Group (11)
Selenium Wiki (2)
Books
Meetups
Mailing Lists
Forums
The good stuff
http://bit.ly/se-info-#
Videos
Selenium LinkedIn Users Group (6)
Stack Overflow (7)
Quora (8)
Selenium Users Google Group (9)
The Selenium Hangout (12)
Conference talks (15)
Meetup talks (16)
Selenium 2 Testing Tools (17)
Selenium Simplified (20)
Issue Tracker (22)
Blogs
The official Selenium blog (4)
“All” Selenium blogs (5)
Issue Tracker Guidance (23)
Straight To The Source (24)
IRC Chat Channel (25)
Selenium Testing Tools Cookbook (18)
The Selenium Guidebook (19)
Selenium Design Patterns (21)
All in-person Selenium Meetups (13)
How to start your own (14)
Selenium Developer Google Group (10)
Agile Testing Yahoo Group (11)
Selenium Wiki (2)
Elemental Selenium (3)
Documentation & Tips
Selenium HQ (1)
Books
Meetups
Mailing Lists
Forums
The good stuff
http://bit.ly/se-info-#
Videos
Selenium LinkedIn Users Group (6)
Stack Overflow (7)
Quora (8)
Selenium Users Google Group (9)
The Selenium Hangout (12)
Conference talks (15)
Meetup talks (16)
Selenium 2 Testing Tools (17)
Selenium Simplified (20)
Issue Tracker (22)
Blogs
The official Selenium blog (4)
“All” Selenium blogs (5)
Beginner
Straight To The Source (24)
IRC Chat Channel (25)
Issue Tracker Guidance (23)
Selenium Testing Tools Cookbook (18)
The Selenium Guidebook (19)
Selenium Design Patterns (21)
All in-person Selenium Meetups (13)
How to start your own (14)
Selenium Developer Google Group (10)
Agile Testing Yahoo Group (11)
Selenium Wiki (2)
Elemental Selenium (3)
Documentation & Tips
Selenium HQ (1)
Books
Meetups
Mailing Lists
Forums
The good stuff
http://bit.ly/se-info-#
Videos
Selenium LinkedIn Users Group (6)
Stack Overflow (7)
Quora (8)
Selenium Users Google Group (9)
The Selenium Hangout (12)
Conference talks (15)
Meetup talks (16)
Selenium 2 Testing Tools (17)
Selenium Simplified (20)
Issue Tracker (22)
Blogs
The official Selenium blog (4)
“All” Selenium blogs (5)
Beginner
Issue Tracker Guidance (23)
Straight To The Source (24)
IRC Chat Channel (25)
Selenium Testing Tools Cookbook (18)
The Selenium Guidebook (19)
Selenium Design Patterns (21)
All in-person Selenium Meetups (13)
How to start your own (14)
Selenium Developer Google Group (10)
Agile Testing Yahoo Group (11)
Selenium Wiki (2)
Elemental Selenium (3)
Documentation & Tips
Selenium HQ (1)
Books
Meetups
Mailing Lists
Forums
The good stuff
http://bit.ly/se-info-#
Videos
Selenium LinkedIn Users Group (6)
Stack Overflow (7)
Quora (8)
Selenium Users Google Group (9)
The Selenium Hangout (12)
Conference talks (15)
Meetup talks (16)
Selenium 2 Testing Tools (17)
Selenium Simplified (20)
Issue Tracker (22)
Blogs
The official Selenium blog (4)
“All” Selenium blogs (5)
Intermediate - Advanced
Straight To The Source (24)
IRC Chat Channel (25)
Documentation & Tips
Issue Tracker Guidance (23)
Selenium Testing Tools Cookbook (18)
The Selenium Guidebook (19)
Selenium Design Patterns (21)
All in-person Selenium Meetups (13)
How to start your own (14)
Selenium Developer Google Group (10)
Agile Testing Yahoo Group (11)
Selenium Wiki (2)
Elemental Selenium (3)
Selenium HQ (1)
Books
Meetups
Mailing Lists
Forums
The good stuff
http://bit.ly/se-info-#
Videos
Selenium LinkedIn Users Group (6)
Stack Overflow (7)
Quora (8)
Selenium Users Google Group (9)
The Selenium Hangout (12)
Conference talks (15)
Meetup talks (16)
Selenium 2 Testing Tools (17)
Selenium Simplified (20)
Issue Tracker (22)
Blogs
The official Selenium blog (4)
“All” Selenium blogs (5)
Intermediate - Advanced
#selenium
Steps to solve the puzzle
1. Define a Test Strategy
2. Pick a programming language
3. Use Selenium Fundamentals
4. Write Your First Test
5. Write re-usable and maintainable
test code
6. Make your tests resilient
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
Write business valuable tests that are
reusable, maintainable and resilient
across all relevant browsers.
Then package them and scale them
for you & your team.
–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”
http://ElementalSelenium.com
Get in touch
@TourDeDave
dhaeffner@gmail.com
DaveHaeffner.com

More Related Content

PPTX
Testing Java EE apps with Arquillian
Ivan Ivanov
 
PDF
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Dave Haeffner
 
PPTX
Integration Testing with Selenium
All Things Open
 
PDF
30 Skills to Master to Become a Senior Software Engineer
Sean Coates
 
PPTX
Introducing ASP.NET Core 2.0
Steven Smith
 
PPTX
Selenium for Jobseekers
Seshu Madhav Chaturvedula
 
PDF
Integration testing - A&BP CC
JWORKS powered by Ordina
 
PPTX
Selenium topic 1- Selenium Basic
ITProfessional Academy
 
Testing Java EE apps with Arquillian
Ivan Ivanov
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Dave Haeffner
 
Integration Testing with Selenium
All Things Open
 
30 Skills to Master to Become a Senior Software Engineer
Sean Coates
 
Introducing ASP.NET Core 2.0
Steven Smith
 
Selenium for Jobseekers
Seshu Madhav Chaturvedula
 
Integration testing - A&BP CC
JWORKS powered by Ordina
 
Selenium topic 1- Selenium Basic
ITProfessional Academy
 

What's hot (20)

PPTX
Automated Testing using JavaScript
Simon Guest
 
PPT
Testing Java Web Apps With Selenium
Marakana Inc.
 
PPTX
Protractor overview
Abhishek Yadav
 
PPTX
Testing with laravel
Derek Binkley
 
PPTX
ProtractorJS for automated testing of Angular 1.x/2.x applications
Binary Studio
 
PPTX
Automation using Javascript
khanhdang1214
 
PDF
Unit testing - A&BP CC
JWORKS powered by Ordina
 
PDF
Testing Code.org's Interactive CS Curriculum
Brian Jordan
 
PDF
Practical Tips & Tricks for Selenium Test Automation - Dave Haeffner
Applitools
 
PDF
Testing with Codeception
Jeremy Coates
 
PDF
Selenium RC: Automated Testing of Modern Web Applications
qooxdoo
 
PDF
Laravel Forge: Hello World to Hello Production
Joe Ferguson
 
PDF
Selenium Frameworks
Dave Haeffner
 
PDF
Introduction to Protractor
Florian Fesseler
 
PPTX
Cakephp vs. laravel
GirnarSoft
 
PDF
Practical Tips & Tricks for Selenium Test Automation
Sauce Labs
 
PPTX
Selenium Topic 2 IDE
ITProfessional Academy
 
PPTX
CI / CD w/ Codeception
Tudor Barbu
 
PPTX
Selenium topic 4 - Selenium Web Driver Set Up
ITProfessional Academy
 
PPTX
Continuous Delivery - Automate & Build Better Software with Travis CI
wajrcs
 
Automated Testing using JavaScript
Simon Guest
 
Testing Java Web Apps With Selenium
Marakana Inc.
 
Protractor overview
Abhishek Yadav
 
Testing with laravel
Derek Binkley
 
ProtractorJS for automated testing of Angular 1.x/2.x applications
Binary Studio
 
Automation using Javascript
khanhdang1214
 
Unit testing - A&BP CC
JWORKS powered by Ordina
 
Testing Code.org's Interactive CS Curriculum
Brian Jordan
 
Practical Tips & Tricks for Selenium Test Automation - Dave Haeffner
Applitools
 
Testing with Codeception
Jeremy Coates
 
Selenium RC: Automated Testing of Modern Web Applications
qooxdoo
 
Laravel Forge: Hello World to Hello Production
Joe Ferguson
 
Selenium Frameworks
Dave Haeffner
 
Introduction to Protractor
Florian Fesseler
 
Cakephp vs. laravel
GirnarSoft
 
Practical Tips & Tricks for Selenium Test Automation
Sauce Labs
 
Selenium Topic 2 IDE
ITProfessional Academy
 
CI / CD w/ Codeception
Tudor Barbu
 
Selenium topic 4 - Selenium Web Driver Set Up
ITProfessional Academy
 
Continuous Delivery - Automate & Build Better Software with Travis CI
wajrcs
 
Ad

Similar to How To Use Selenium Successfully (Java Edition) (20)

PDF
How To Use Selenium Successfully
Dave Haeffner
 
PDF
How To Use Selenium Successfully (Java Edition)
Sauce Labs
 
PDF
Mastering Test Automation: How to Use Selenium Successfully
Applitools
 
PDF
How to use selenium successfully
TEST Huddle
 
PDF
Getting Started with Selenium
Dave Haeffner
 
PDF
How to Use Selenium, Successfully
Sauce Labs
 
PDF
How To Use Selenium Successfully
Dave Haeffner
 
PDF
KrishnaToolComparisionPPT.pdf
QA or the Highway
 
PPTX
How do you tame a big ball of mud? One test at a time.
Matt Eland
 
PPTX
Automated ui-testing
Slobodan Lohja
 
PPTX
Selenium web driver_2.0_presentation
sayhi2sudarshan
 
PPTX
Basic Selenium Training
Dipesh Bhatewara
 
PPTX
Selenium digitalinfobytes-120829005812-phpapp02
Kdeepapal Mishra
 
PDF
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
Pallavi Sharma
 
PPTX
Automated Acceptance Testing from Scratch
Excella
 
PPTX
Selenium.pptx
orbitprojects
 
PPTX
Continuous feature-development
nhm taveer hossain khan
 
PDF
Automated Visual Regression Testing by Dave Sadlon
QA or the Highway
 
PDF
Awesome Test Automation Made Simple w/ Dave Haeffner
Sauce Labs
 
KEY
CodeIgniter for Startups, cicon2010
Joel Gascoigne
 
How To Use Selenium Successfully
Dave Haeffner
 
How To Use Selenium Successfully (Java Edition)
Sauce Labs
 
Mastering Test Automation: How to Use Selenium Successfully
Applitools
 
How to use selenium successfully
TEST Huddle
 
Getting Started with Selenium
Dave Haeffner
 
How to Use Selenium, Successfully
Sauce Labs
 
How To Use Selenium Successfully
Dave Haeffner
 
KrishnaToolComparisionPPT.pdf
QA or the Highway
 
How do you tame a big ball of mud? One test at a time.
Matt Eland
 
Automated ui-testing
Slobodan Lohja
 
Selenium web driver_2.0_presentation
sayhi2sudarshan
 
Basic Selenium Training
Dipesh Bhatewara
 
Selenium digitalinfobytes-120829005812-phpapp02
Kdeepapal Mishra
 
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
Pallavi Sharma
 
Automated Acceptance Testing from Scratch
Excella
 
Selenium.pptx
orbitprojects
 
Continuous feature-development
nhm taveer hossain khan
 
Automated Visual Regression Testing by Dave Sadlon
QA or the Highway
 
Awesome Test Automation Made Simple w/ Dave Haeffner
Sauce Labs
 
CodeIgniter for Startups, cicon2010
Joel Gascoigne
 
Ad

More from Dave Haeffner (11)

PDF
Selenium Tips & Tricks
Dave Haeffner
 
PDF
How To Find Information On Your Own
Dave Haeffner
 
PDF
Bdd lessons-learned
Dave Haeffner
 
PDF
The Testable Web
Dave Haeffner
 
PDF
Selenium Basics
Dave Haeffner
 
PDF
Selenium Users Anonymous
Dave Haeffner
 
PPT
Full Stack Testing Done Well
Dave Haeffner
 
PPTX
Cucumber Crash Course
Dave Haeffner
 
PPTX
Agile testing for mere mortals
Dave Haeffner
 
PDF
Pivotal Failure - Lessons Learned from Lean Startup Machine DC
Dave Haeffner
 
PPTX
Open Source Investing
Dave Haeffner
 
Selenium Tips & Tricks
Dave Haeffner
 
How To Find Information On Your Own
Dave Haeffner
 
Bdd lessons-learned
Dave Haeffner
 
The Testable Web
Dave Haeffner
 
Selenium Basics
Dave Haeffner
 
Selenium Users Anonymous
Dave Haeffner
 
Full Stack Testing Done Well
Dave Haeffner
 
Cucumber Crash Course
Dave Haeffner
 
Agile testing for mere mortals
Dave Haeffner
 
Pivotal Failure - Lessons Learned from Lean Startup Machine DC
Dave Haeffner
 
Open Source Investing
Dave Haeffner
 

Recently uploaded (20)

PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PPTX
oapresentation.pptx
mehatdhavalrajubhai
 
PDF
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
PDF
Solar Panel Installation Guide – Step By Step Process 2025.pdf
CRMLeaf
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
PDF
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PDF
Community & News Update Q2 Meet Up 2025
VictoriaMetrics
 
PDF
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
PDF
Become an Agentblazer Champion Challenge
Dele Amefo
 
PPTX
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
PDF
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
PPTX
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
PDF
Multi-factor Authentication (MFA) requirement for Microsoft 365 Admin Center_...
Q-Advise
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PPTX
TestNG for Java Testing and Automation testing
ssuser0213cb
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PDF
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
oapresentation.pptx
mehatdhavalrajubhai
 
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
Solar Panel Installation Guide – Step By Step Process 2025.pdf
CRMLeaf
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
Community & News Update Q2 Meet Up 2025
VictoriaMetrics
 
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
Become an Agentblazer Champion Challenge
Dele Amefo
 
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
Role Of Python In Programing Language.pptx
jaykoshti048
 
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
Multi-factor Authentication (MFA) requirement for Microsoft 365 Admin Center_...
Q-Advise
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
TestNG for Java Testing and Automation testing
ssuser0213cb
 
Exploring AI Agents in Process Industries
amoreira6
 
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 

How To Use Selenium Successfully (Java Edition)

  • 1. How To Use Selenium, Successfully by Dave Haeffner, @TourDeDave
  • 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?
  • 6. Step 1 Define a Test Strategy
  • 7. 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 in the app before? Outcome: What to test and which browsers to care about
  • 8. Step 2 Pick a Programming Language
  • 9. Programming Language • Same language as the app? • Who will own it? • Build a framework or use an existing one? • http://bit.ly/seleniumframeworks
  • 10. • Vim, Emacs, Sublime Text • IntelliJ, Eclipse Choose an Editor
  • 12. Selenium Fundamentals • Mimics human action • Uses a few common actions • Works with “locators” Locators tell Selenium which HTML element to interact with
  • 13. Common Actions • get(); • findElement(); • click(); //or submit(); • sendKeys(); • isDisplayed();
  • 14. 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
  • 15. 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
  • 16. 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
  • 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 Start with IDs and Classes Use CSS or XPath (with care)
  • 18. Locator Strategies • Class • CSS selectors • ID • Link Text • Partial Link Text • Tag Name • XPath CSS vs XPath http://bit.ly/seleniumbenchmarks http://bit.ly/cssxpathexamples
  • 19. Finding Quality Locators • Inspect the page • Verify your selection • e.g., FirePath or FireFinder • http://bit.ly/verifyinglocators • Learn through gaming • http://bit.ly/locatorgame • Conversation
  • 21. Step 4 Write your first test
  • 22. 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
  • 23. 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
  • 27. Now to find an assertion 1. Login 2. Inspect the page 3. Find a locator 4. Verify it 5. Add it to the test
  • 30. 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://bit.ly/se-exceptions-java
  • 32. Step 5 Write reusable and maintainable test code
  • 34. Application Under Test Test 1 Test 2 Test 3 Test 4 Test 5Test 1 Test 2 Test 3 Test 4 Test 5 Need to update EVERY test :-(
  • 35. Application Under TestPage Object(s) Test 1 Test 2 Test 3 Test 4 Test 5Test 1 Test 2 Test 3 Test 4 Test 5 Need to update JUST the page object :-D
  • 36. Let’s look at a page object for login
  • 38. And here’s what the test looks like when using it
  • 42. Base Page Object Page Object 1 Page Object 2 Page Object 3 Page Object 4 Page Object 5 Selenium Commands • Global reuse • More readable • Insulates you from Selenium API changes http://bit.ly/se-upgrade
  • 43. Let’s take a look at a Base Page Object
  • 45. And here it is implemented
  • 47. How everything fits together Test TestTest Page Object Page Object Base Page Object Tests use page objects Page objects use the base page object The base page object uses Selenium commands
  • 48. Step 6 Make your tests resilient
  • 50. Explicit Waits • Specify an amount of time, and an action • Selenium will try repeatedly until either: • The action is completed, or • The amount of time specified has been reached (and throw a timeout exception)
  • 52. In the Base page object
  • 53. In the DynamicLoading page object
  • 56. Test Harness • Simple organizational structure • Central setup and teardown • Configurable at run-time (with sensible defaults) • Reporting & Logging • Parallelization • Test Grouping
  • 58. Central setup/teardown More on JUnit Rules: http://bit.ly/junit-rules
  • 60. Reporting & Logging • Machine readable
 e.g., JUnit XML • Human readable
 e.g., screenshots, failure message, stack trace Fantastic Test Report Tool http://bit.ly/se-reporter (Allure Framework)
  • 61. Parallelization • In code • Through your test runner • Through your Continuous Integration (CI) server #protip Enforce random order execution of tests http://bit.ly/junit-random-order Recommended approach: http://bit.ly/mvn-surefire
  • 62. Test Grouping • Metadata (a.k.a. Categories) • Enables “test packs” • Some category ideas • wip • shallow • deep • story number More info: bit.ly/junit-categories
  • 63. Step 8 Add in cross-browser execution
  • 66. Grid Grid Hub Browser Tests All done with the Selenium Standalone Server Just requires additional runtime flags Grid Node Grid Node Grid Node Browser Browser
  • 68. Grid More on Selenium Grid http://bit.ly/se-grid-docs http://bit.ly/se-grid-post http://bit.ly/se-grid-extras http://bit.ly/se-grid-scaler
  • 69. Sauce Labs Sauce Labs Browser Tests
  • 70. Sauce Labs Additional Considerations - Test name - Pass/Fail status - Secure tunnel More on Sauce: http://bit.ly/sauce-platforms http://bit.ly/sauce-post http://bit.ly/sauce-tutorial-java
  • 72. Step 9 Build an automated feedback loop
  • 73. Feedback loops • The goal: Find failures early and often • Done with continuous integration and notifications • Notifications
 e.g., remote: Email, chat, SMS
 in-person: audio/visual, public shaming
  • 74. Code Committed Unit/Integ. (pass?) Deploy to autom. test server (success?) Run automated tests (pass?) Deploy to next env. yes yes yes Notify team if no Code Promotion Bonus points: stop the line
  • 75. 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
  • 77. Step 10 Find information on your own http://bit.ly/se-info-slides http://bit.ly/se-info-video
  • 78. Elemental Selenium (3) Selenium HQ (1) Documentation & Tips Issue Tracker Guidance (23) Straight To The Source (24) IRC Chat Channel (25) Selenium Testing Tools Cookbook (18) The Selenium Guidebook (19) Selenium Design Patterns (21) All in-person Selenium Meetups (13) How to start your own (14) Selenium Developer Google Group (10) Agile Testing Yahoo Group (11) Selenium Wiki (2) Books Meetups Mailing Lists Forums The good stuff http://bit.ly/se-info-# Videos Selenium LinkedIn Users Group (6) Stack Overflow (7) Quora (8) Selenium Users Google Group (9) The Selenium Hangout (12) Conference talks (15) Meetup talks (16) Selenium 2 Testing Tools (17) Selenium Simplified (20) Issue Tracker (22) Blogs The official Selenium blog (4) “All” Selenium blogs (5)
  • 79. Issue Tracker Guidance (23) Straight To The Source (24) IRC Chat Channel (25) Selenium Testing Tools Cookbook (18) The Selenium Guidebook (19) Selenium Design Patterns (21) All in-person Selenium Meetups (13) How to start your own (14) Selenium Developer Google Group (10) Agile Testing Yahoo Group (11) Selenium Wiki (2) Elemental Selenium (3) Documentation & Tips Selenium HQ (1) Books Meetups Mailing Lists Forums The good stuff http://bit.ly/se-info-# Videos Selenium LinkedIn Users Group (6) Stack Overflow (7) Quora (8) Selenium Users Google Group (9) The Selenium Hangout (12) Conference talks (15) Meetup talks (16) Selenium 2 Testing Tools (17) Selenium Simplified (20) Issue Tracker (22) Blogs The official Selenium blog (4) “All” Selenium blogs (5) Beginner
  • 80. Straight To The Source (24) IRC Chat Channel (25) Issue Tracker Guidance (23) Selenium Testing Tools Cookbook (18) The Selenium Guidebook (19) Selenium Design Patterns (21) All in-person Selenium Meetups (13) How to start your own (14) Selenium Developer Google Group (10) Agile Testing Yahoo Group (11) Selenium Wiki (2) Elemental Selenium (3) Documentation & Tips Selenium HQ (1) Books Meetups Mailing Lists Forums The good stuff http://bit.ly/se-info-# Videos Selenium LinkedIn Users Group (6) Stack Overflow (7) Quora (8) Selenium Users Google Group (9) The Selenium Hangout (12) Conference talks (15) Meetup talks (16) Selenium 2 Testing Tools (17) Selenium Simplified (20) Issue Tracker (22) Blogs The official Selenium blog (4) “All” Selenium blogs (5) Beginner
  • 81. Issue Tracker Guidance (23) Straight To The Source (24) IRC Chat Channel (25) Selenium Testing Tools Cookbook (18) The Selenium Guidebook (19) Selenium Design Patterns (21) All in-person Selenium Meetups (13) How to start your own (14) Selenium Developer Google Group (10) Agile Testing Yahoo Group (11) Selenium Wiki (2) Elemental Selenium (3) Documentation & Tips Selenium HQ (1) Books Meetups Mailing Lists Forums The good stuff http://bit.ly/se-info-# Videos Selenium LinkedIn Users Group (6) Stack Overflow (7) Quora (8) Selenium Users Google Group (9) The Selenium Hangout (12) Conference talks (15) Meetup talks (16) Selenium 2 Testing Tools (17) Selenium Simplified (20) Issue Tracker (22) Blogs The official Selenium blog (4) “All” Selenium blogs (5) Intermediate - Advanced
  • 82. Straight To The Source (24) IRC Chat Channel (25) Documentation & Tips Issue Tracker Guidance (23) Selenium Testing Tools Cookbook (18) The Selenium Guidebook (19) Selenium Design Patterns (21) All in-person Selenium Meetups (13) How to start your own (14) Selenium Developer Google Group (10) Agile Testing Yahoo Group (11) Selenium Wiki (2) Elemental Selenium (3) Selenium HQ (1) Books Meetups Mailing Lists Forums The good stuff http://bit.ly/se-info-# Videos Selenium LinkedIn Users Group (6) Stack Overflow (7) Quora (8) Selenium Users Google Group (9) The Selenium Hangout (12) Conference talks (15) Meetup talks (16) Selenium 2 Testing Tools (17) Selenium Simplified (20) Issue Tracker (22) Blogs The official Selenium blog (4) “All” Selenium blogs (5) Intermediate - Advanced
  • 84. Steps to solve the puzzle 1. Define a Test Strategy 2. Pick a programming language 3. Use Selenium Fundamentals 4. Write Your First Test 5. Write re-usable and maintainable test code 6. Make your tests resilient 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
  • 85. Write business valuable tests that are reusable, maintainable and resilient across all relevant browsers. Then package them and scale them for you & your team.
  • 86. –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”