Page Object Pattern

As important and critical unit tests are to our applications, functional testing of the front part should be a must part of any project too. At Accesto we use a combination of Selenium browser automation tool, Facebook's WebDriver and PHPUnit framework to make sure the user interface is working as expected from the day one.

Each integration test covers up to multiple scenarios and consists of series of standard interface actions like URL navigation, clicking on an element, button typing and alike. The WebDriver offers a variety of ways to select an element to act upon. It includes selection by XPath, by link text, CSS selector and so on.

However, as the tests grow in numbers, it can quickly become quite cumbersome to maintain test quality as they become fragile to any changes in the document structure. A simple change made by the frontend developers can lead to lots of failing test cases and time wasted looking for the answer what did fail and why.

There is a pattern though called the Page Object pattern that aids in creating clean and maintainable tests. Quoting Martin Fowler, the class implementing this pattern acts as a wrapper to any part of the web application, centralizing document querying, actions, etc. in an object-oriented manner.

Implementing Page Object in PHP

We start by creating the base class for every Page Object:
and very first FrontPage page object representing the landing page with the login form on its top: Such object can be reused across many tests. Any change to the underlying document structure would be limited to this single class.
Remember, tests are as important as application code base. We want both to be maintainable, extendible and reusable as much as possible. Page Object pattern helps us to achieve that goal.

This website uses cookies to guarantee the best experience for the user. If you continue browsing, we consider that you agree to their use.