Selenium/Explanation/Page object pattern

There are two main purposes of the page object pattern.


 * Move parts of the application that change a lot (user interface) to a central location. When the user interface changes, the test suite only needs to be updated in one place.
 * Make tests easier to read and understand by moving complexity to page objects.

With page object pattern
Let's describe the purposes with code samples from MediaWiki Core (as of June 2021). Following code is available at 702327.

The code is split into two files. contains the test. contains the page object.

Please notice how readable  is. You can immediately see that the point of  is to create an user account with   and   as arguments.



Please notice that  has two major sections. In the first section are elements on the page ( ...). The second section contains actions ( ...).



Without page object pattern
Let's compare that to a simpler, but less readable and less maintainable solution without page object pattern. Following code is available at TODO.



More information

 * PageObject by Martin Fowler (2013)
 * PageObjects by Simon Stewart (Selenium, 2015)
 * Page object models by Diego Molina (Selenium, 2019)
 * Page Object Pattern by Christian Bromann (WebdriverIO, 2021)
 * Selenium/Explanation/Stack
 * Selenium/Reference/Stack