The Page Object design pattern, which I explained in a previous post, follows a simple ethos, which is: get out of the spaghetti code and into something a little more flexible that can scale. The main idea is that you create classes which have properties and methods that model and execute the intended user actions. For example, you might construct a LoginPage and give it a method called LogIn(username, password). This method would contain the actual automation calls, hiding away that logic in an easy-to-read and easy-to-consume method.
The benefits of this approach are pretty clear:
- No copy/pasting spaghetti code.
- No attempting to do the same thing in two different ways – the page object is the source of truth.
- Stringing together page object methods to create a scenario only requires the ability to follow a pattern and use Intellisense.
I’ve been writing tests this way for a couple of years now with great success.
My particular implementation of the page object model enables you to create your own pages quickly, encapsulate queries, and create fluid “user stories” that move from page to page.
Check out the templates and let me know what you think!