PHPUnit-Webdriver: 10 - PageObjectModel Framework

  • When testing web applications ( or any complex product ) modeling the application is critical for reducing maintenance overhead.
  • Tests should be abstracted away from interacting with the DOM & its elements such that they only reflect interactions
  • By modeling the application, creating tests is intuitive & element selectors are assigned one time in one place
    • Using enumerations and/or constants allow for indirect references to elements so if their selectors change, the only update needed is one constant assignment
  • When the framework is updated to reflect architectural changes in the product, updates will be contained and encapsulated
    • failing tests will show technical debt & expose possible impact to the product that may have not been anticipated.

 

Page Object Model

 

Advanced Page Object

 

  • Create a base Page Class
  • then Create Fragment ( or Block for Drupal lingo ) Classes
  • Then Create Page Objects with a collection of applicatble fragments/blocks that a user would interact with
  • Further encapsulation can be done with PageAction Objects that abstract the PageObjects (elements) from what the test will be doing with them.
  • This can reduce maintenance for when - for example - a login routine changes.... the PageAction.login() method would only need changing one time to update all calling tests.
  • If the login steps are placed directly in each test, EACH test will need updating... makes for a bad week/month/quarter