Page Object Model
- Radek Stolarczyk
- Jan 18
- 3 min read
Page Object Model Overview
The Page Object Model is a design pattern used in test automation to better organize code and improve reusability and maintainability. At its core, the idea is simple: instead of calling test steps directly in every test, you extract repetitive logic into methods or functions.
Rather than repeating the same actions across multiple tests, those actions live in one place and are reused wherever needed.
Why Page Object Model Helps
Using Page Object Model brings several practical benefits:
It reduces the overall number of lines of code in a project
It eliminates copy-paste, which improves reusability
It makes maintenance easier, because changes only need to be made once
There’s no single “correct” way to implement Page Object Model. In fact, there is no industry standard. You’ll find hundreds of different variations across teams and projects.
Some teams store locators inside methods, others use constructors, constants, or external files like JSON or CSV. Naming also varies, with terms like page objects, page functions, or app actions all referring to similar ideas. The key point is that the concept stays the same, even if the structure looks different.
Implementation Approach
A common approach is to treat each page of a web application as its own class. That class contains methods that represent what a user can do on that page.
A Simple Example
Take a login page with an email field, a password field, and a login button.
Without using Page Object Model, those same steps often get copied into every test that needs to log in. Over time, this leads to duplicated code scattered throughout the test suite.
With Page Object Model, those steps are grouped into a single method, such as a login action. The test then calls that one method instead of repeating multiple lines of code.
The result is cleaner tests that read more like a description of behavior. When something changes on the login page, only one method needs to be updated.
Core Design Principles
DRY – Don’t Repeat Yourself
If you find yourself copying the same code more than three times, that’s usually a sign it should be turned into a reusable method. It’s worth pausing and thinking about reusability before continuing to write more tests.
Applying DRY consistently helps keep the framework structured and prevents unnecessary duplication.
KISS – Keep It Simple, Stupid
Frameworks don’t need to be clever or overly complex to be effective. Simple designs are easier to understand, easier to maintain, and easier for new engineers to learn.
Over-engineered frameworks often become difficult to work with, and in many cases, they end up being abandoned and rebuilt. Keeping things simple helps avoid that situation.
Best Practices
Use Descriptive Naming
Clear and descriptive naming goes a long way in making a framework readable.
Avoid shortcuts or acronyms in method, class, and variable names. Names should clearly describe what the method does. A good way to validate this is to ask a teammate whether a method name makes sense without extra explanation.
If the name clearly communicates intent, it’s doing its job.
Avoid Too Many Tiny Methods
While breaking code into reusable methods is important, creating too many small, single-line methods can be counterproductive.
Instead, aim to group meaningful steps into larger, more functional methods. This keeps page classes from becoming bloated with dozens of tiny methods and makes the code easier to work with.
The goal is balance: reusable methods that represent real actions, not just individual clicks or inputs.
Framework Design Philosophy
This approach to Page Object Model has proven to scale well across large test suites and long-running projects.
The concept itself is flexible and can be adapted based on the application being tested. The priority should always be framework usability over complexity.
A good measure of success is whether a new engineer can join the team, understand the structure quickly, and confidently continue building on it. If that’s possible, the framework is doing what it’s meant to do.