Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

SauceCon 2017: Selenium... Say goodbye to the F Word: Flaky No More

176 views

Published on

Utilizing a Base Page Object in a Selenium framework has a number of huge benefits. It makes PageObjects more readable and standardized. It insulates teams from changes to the Selenium API. It also offers a single place for the entire organization to perform error handling, including a great place for debug/log statements or helper code that the entire organization can automatically leverage.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

SauceCon 2017: Selenium... Say goodbye to the F Word: Flaky No More

  1. 1. Selenium… Say goodbye to the F word: Flaky No more Craig Schwarzwald | Vanguard
  2. 2. • Maintainability • Stability • Readability Goal: For The Entire Enterprise
  3. 3. Solution: 1) Good locators 2) Page Objects Issue: Poor Maintainability Goal:Maintainability
  4. 4. 1) Unique 2) Descriptive 3) Unlikely to change What are good locators? Goal:Maintainability
  5. 5. Issue: Bad Locators Goal:Maintainability driver.findElement(By.xpath(“//div[34]/span[21]” + “/table/tbody/tr[17]/td[2]/input”)).click(); Solution: Use better ones By continueBtn = By.id(“continueButton”); click(continueBtn); By continueBtn = By.xpath(“//input[value=‘Continue’]”); click(continueBtn); or if there is no ID:
  6. 6. Solution: Page Objects Goal:Maintainability Construction: - By locators pertaining to page/section on top - Constructor - isLoaded() method - Finally create all user action methods specific to that page.
  7. 7. Base Page Object Goal:Maintainability - Wraps Selenium core functionality • findElement(), click(), isDisplayed(), visit(), etc. - Also add common functions to be used across teams • getCellFromTableContainingText(byTable, text); • selectWizzyWidget(value);
  8. 8. Base Page Object Benefits BONUS - Encapsulate all Selenium commands. - All pages get auto-enabled functionality. - One single place to implement all the null checks, failsafe's, and logging. - Say goodbye to NoSuchElementExceptions and StaleElementReferenceExceptions.
  9. 9. Solution: Page Objects Goal:Stability
  10. 10. Base Page Methods Goal:Stability
  11. 11. Base Page Methods Goal:Stability
  12. 12. Explicit Wait Goal:Stability Method from findElement()
  13. 13. Rules to Follow Goal:Readability Page Objects: • Contain all locators • Contain methods for any actions you can do on the corresponding page / section of page. Tests: • Tests only have 2 (or 3) things they can do • Perform an assertion • Call a page object method • (Assign variables to make more readable)
  14. 14. Put it all together - Pages Goal:Readability
  15. 15. Put it all together - Pages Goal:Readability
  16. 16. Put it all together - Pages Goal:Readability
  17. 17. Put it all together - Pages Goal:Readability
  18. 18. Put it all together - Tests Goal:Readability BaseTest – a talk for another day.
  19. 19. Put it all together - Tests Goal:Readability
  20. 20. Summing up our three goals - Page Objects + Good Locators = Maintainability - Explicit Waits and Verifying Page Loads = Stability - Following Page and Test Rules = Readability Maintainability Stability Readability Across our entire Enterprise Selenium Suites

×