Join Dave Haeffner as he steps through the core tenets of good test and page object design, locators, and a repeatable and quantitative approach for assessing your test code. When you're done, you'll be able to see how your tests and page objects stack up, and what changes are needed to help them stand the test of time.
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)
โข Veri๏ฌes 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
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)
24. A Locator Rubric
(Each locator gets a grade)
Item Letter Grade E.g.,
Dynamic locators D-
User account speci๏ฌc
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