how to grade your selenium tests by dave haeffner - sauce labs webinar
TRANSCRIPT
![Page 1: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/1.jpg)
How To Grade Your Selenium Tests
![Page 2: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/2.jpg)
http://se.tips/getting-started-talk
http://se.tips/selenium-tips
http://se.tips/selenium-book
![Page 3: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/3.jpg)
Let’s talk about tests
![Page 4: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/4.jpg)
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
![Page 5: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/5.jpg)
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
![Page 6: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/6.jpg)
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
![Page 7: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/7.jpg)
Let’s talk about Page Objects
![Page 9: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/9.jpg)
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
![Page 10: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/10.jpg)
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
![Page 11: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/11.jpg)
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
![Page 12: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/12.jpg)
Let’s talk about locators
![Page 13: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/13.jpg)
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
![Page 14: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/14.jpg)
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
![Page 15: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/15.jpg)
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
![Page 16: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/16.jpg)
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)
![Page 17: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/17.jpg)
Which is better CSS or XPath?
![Page 19: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/19.jpg)
![Page 20: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/20.jpg)
![Page 21: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/21.jpg)
![Page 22: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/22.jpg)
![Page 23: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/23.jpg)
![Page 24: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/24.jpg)
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
![Page 25: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/25.jpg)
So…
![Page 26: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/26.jpg)
What’s your testing GPA?Topic Weight
Tests 20%
Page Objects 30%
Locators 50%
![Page 27: How To Grade Your Selenium Tests by Dave Haeffner - Sauce Labs Webinar](https://reader031.vdocuments.site/reader031/viewer/2022022412/58f9b353760da3da068bd4fb/html5/thumbnails/27.jpg)
Available in Java, JavaScript, Python, Ruby, and C#25% OFF until Friday at midnight (Eastern)
https://seleniumguidebook.com