How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar

Sauce Labs
Sauce LabsSr. Manager, Demand Generation & Operations
How To Grade Your
Selenium Tests
http://se.tips/getting-started-talk
http://se.tips/selenium-tips
http://se.tips/selenium-book
Let’s talk about tests
What Makes a Bad Test?
• Fails For No Good Reason
• Changes in AUT, Need to Update Test(s)
• Slow
• Unreliable
• Hard to Understand and Maintain
What Makes a Good Test?
• Written 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
• Centralized setup/teardown
• Uses Page Objects
A Testing Rubric
(Each test starts with 100 points, deduct as necessary)
Item Belong in tests? Score
Selenium Commands No -3 per (max of -9)
Locators No -2 per (max of -8)
Selenium setup/teardown* No -20
Hard-coded sleeps No -5 per (max of -20)
Implicit wait calls No -10
Explicit Wait calls No -3
Conditionals No -5 (max of -20)
Calls to Page Objects Yes N/A
Assertion(s)* Yes N/A
Let’s talk about
Page Objects
http://martinfowler.com/bliki/PageObject.html
What Makes a Bad PO?
• Gigantic in size (e.g., hundreds or thousands of
lines in code)
• Over-reaching responsibility
• Contain overly complicated logic
• Return not enough or too much information to the
test (leaky abstraction)
• Assertions happening in the PO instead of the test
What Makes a Good PO?
• Contains State (e.g., locators)
• Contains Behavior (e.g., methods to interact with
the page)
• Returns some information about the page (e.g.,
new page object, text from the page, a boolean
result for some check, etc. — never a WebElement)
• Verifies page ready state as part of initialization
with a found Element
A Page Object Rubric
(Each Page Object starts with 100, deduct points as necessary)
Item Belong in POs? Score
> 200 lines of code No -5 per 50 lines over
Assertions No* -5 per (max of -20)
Hard-coded sleeps No -5 per (max of -20)
Implicit wait calls No -10
Explicit waits Yes N/A
Verify page ready state* Yes -8 if not verifying an
element
Locators* Yes N/A
http://se.tips/se-waiting-jim-evans
Let’s talk about locators
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)
Which is better
CSS or XPath?
CSS vs. XPath
Benchmarks
http://se.tips/se-benchmarks
How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar
How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar
How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar
How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar
How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar
A Locator Rubric
(Each locator gets a grade)
Item Letter Grade E.g.,
Dynamic locators D-
User account specific
or tied to page render
Tied to page layout D
XPath: / / /
CSS: > > >, etc.
Text on the page C Link text, page copy
Reasonable traversal B
Parent to child w/in an
element node
Using semantic name B+
Input labels
(name='username')
Semantic ID A
Unique, descriptive,
unlikely to change
Non-unique locator? -2 full letter grades
So…
What’s your testing GPA?
Topic Weight
Tests 20%
Page Objects 30%
Locators 50%
Available in Java, JavaScript, Python, Ruby, and C#
25% OFF until Friday at midnight (Eastern)
https://seleniumguidebook.com
1 of 27

More Related Content

What's hot(20)

Selenium FrameworksSelenium Frameworks
Selenium Frameworks
Dave Haeffner4.4K views
How to Use Selenium, SuccessfullyHow to Use Selenium, Successfully
How to Use Selenium, Successfully
Sauce Labs14.8K views
Selenium (2)Selenium (2)
Selenium (2)
onlinemindq515 views
PhpUnit & web driverPhpUnit & web driver
PhpUnit & web driver
Manish Trivedi2.5K views
Selenium and The GrinderSelenium and The Grinder
Selenium and The Grinder
OpenSource Connections3.1K views
Selenium Users AnonymousSelenium Users Anonymous
Selenium Users Anonymous
Dave Haeffner2.5K views
Introduction to jestIntroduction to jest
Introduction to jest
pksjce2.4K views
Selenium 101Selenium 101
Selenium 101
becoded694 views
Jest: Frontend Testing leicht gemacht @EnterJS2018Jest: Frontend Testing leicht gemacht @EnterJS2018
Jest: Frontend Testing leicht gemacht @EnterJS2018
Holger Grosse-Plankermann1.1K views
How To Find Information On Your OwnHow To Find Information On Your Own
How To Find Information On Your Own
Dave Haeffner14.7K views
Selenium Design PatternsSelenium Design Patterns
Selenium Design Patterns
Liraz Shay1.6K views
Selenium testing IDE 101Selenium testing IDE 101
Selenium testing IDE 101
Adam Culp2.3K views
Automated Software TestingAutomated Software Testing
Automated Software Testing
arild2129 views
Brace yourself from automation death trapBrace yourself from automation death trap
Brace yourself from automation death trap
Prasad Kalgutkar547 views

Similar to How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar

Unit TestingUnit Testing
Unit TestingAdam Birr
169 views10 slides

Similar to How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar(20)

More from Sauce Labs(20)

Just Enough (Automated) TestingJust Enough (Automated) Testing
Just Enough (Automated) Testing
Sauce Labs254 views

Recently uploaded(20)

How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar

  • 1. How To Grade Your Selenium Tests
  • 4. What Makes a Bad Test? • Fails For No Good Reason • Changes in AUT, Need to Update Test(s) • Slow • Unreliable • Hard to Understand and Maintain
  • 5. What Makes a Good Test? • Written 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 • Centralized setup/teardown • Uses Page Objects
  • 6. A Testing Rubric (Each test starts with 100 points, deduct as necessary) Item Belong in tests? Score Selenium Commands No -3 per (max of -9) Locators No -2 per (max of -8) Selenium setup/teardown* No -20 Hard-coded sleeps No -5 per (max of -20) Implicit wait calls No -10 Explicit Wait calls No -3 Conditionals No -5 (max of -20) Calls to Page Objects Yes N/A Assertion(s)* Yes N/A
  • 9. What Makes a Bad PO? • Gigantic in size (e.g., hundreds or thousands of lines in code) • Over-reaching responsibility • Contain overly complicated logic • Return not enough or too much information to the test (leaky abstraction) • Assertions happening in the PO instead of the test
  • 10. What Makes a Good PO? • Contains State (e.g., locators) • Contains Behavior (e.g., methods to interact with the page) • Returns some information about the page (e.g., new page object, text from the page, a boolean result for some check, etc. — never a WebElement) • Verifies page ready state as part of initialization with a found Element
  • 11. A Page Object Rubric (Each Page Object starts with 100, deduct points as necessary) Item Belong in POs? Score > 200 lines of code No -5 per 50 lines over Assertions No* -5 per (max of -20) Hard-coded sleeps No -5 per (max of -20) Implicit wait calls No -10 Explicit waits Yes N/A Verify page ready state* Yes -8 if not verifying an element Locators* Yes N/A http://se.tips/se-waiting-jim-evans
  • 12. Let’s talk about locators
  • 13. 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
  • 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 Start with IDs and Classes
  • 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 Use CSS or XPath (with care)
  • 17. Which is better CSS or XPath?
  • 24. A Locator Rubric (Each locator gets a grade) Item Letter Grade E.g., Dynamic locators D- User account specific or tied to page render Tied to page layout D XPath: / / / CSS: > > >, etc. Text on the page C Link text, page copy Reasonable traversal B Parent to child w/in an element node Using semantic name B+ Input labels (name='username') Semantic ID A Unique, descriptive, unlikely to change Non-unique locator? -2 full letter grades
  • 25. So…
  • 26. What’s your testing GPA? Topic Weight Tests 20% Page Objects 30% Locators 50%
  • 27. Available in Java, JavaScript, Python, Ruby, and C# 25% OFF until Friday at midnight (Eastern) https://seleniumguidebook.com