Last updated by fletcherr 2 years ago
Using The 'Page Object' Pattern
Whether using theSeleniumTest mixin or extending GrailsSeleniumTestCase your tests interact directly with Selenium. Once you go beyond a handful of simple tests this can make your tests difficult to maintain as they are dealing with the details of the page. Some of the problems with this approach include:
- Page element locators (whether XPath, CSS, element Ids, etc.) are repeated throughout the tests and therefore require you to hunt out instances if you change the page structure.
- Multiple Selenium commands representing a single logical action may be repeated in several tests or grouped together into utility classes that can easily get out of control and turn into 'God Objects'.
- Details of page can be refactored more easily as changes only need to be reflected in the page object, not the tests themselves.
- Complex interactions can be modelled in methods on the page object, meaning they can be reused in multiple tests.
- Navigation actions can be modelled as page object methods that return instances of other page objects representing the user's journey through the application.
- Page objects are very easy to write, can be expanded as necessary and greatly enhance the simplicity and readability of your tests.



