The Four Patterns SDETs Actually Use
There are 23 famous design patterns. Good news — you only need four for test automation, and naming them clearly is a strong signal in an interview.
The idea, in one line
A design pattern is just a named, reusable way to organise code. Four of them cover almost everything you'll build in a test framework.
The four, and where each fits
- Page Object Model (POM) — one class per screen exposes actions and hides selectors. When the login button's id changes, you edit one file, not fifty tests. This is the pattern interviewers expect most.
- Factory — a function that builds an object based on input, so callers don't hardcode the exact type. A driver factory returns Chrome, Firefox, or a remote Grid session from one config string. Tests just ask for "a driver".
- Singleton — exactly one shared instance. Config is the honest use: load the settings once, read them everywhere, don't re-parse the file for every test.
- Builder — assemble a complex object step by step with sensible defaults. Perfect for test data: start from a valid user and override only the field under test.
# Factory: tests ask for a driver, stay browser-agnostic
def make_driver(kind):
if kind == "chrome":
return webdriver.Chrome()
if kind == "remote": # points at Selenium Grid
return webdriver.Remote(GRID_URL, options=ChromeOptions())
raise ValueError(f"unknown driver: {kind}")
# Builder: start valid, override only what the test cares about
class UserBuilder:
def __init__(self):
self._u = {"name": "Ada", "role": "member", "active": True}
def role(self, r): # fluent override, returns self
self._u["role"] = r
return self
def build(self):
return dict(self._u)
admin = UserBuilder().role("admin").build() # intent is obviousRead it top to bottom: the factory hands back "a driver" without the test caring which browser, and the builder produces an admin user by changing just the one field that matters.
Advanced — knowing when not to
The senior move isn't reaching for patterns everywhere — it's knowing when to skip them. Don't wrap a two-line helper in a factory. A pattern earns its place when it removes real, repeated pain, not because it has a fancy name.
Grounded in the Selenium Page Object Model docs and the classic Gang-of-Four creational patterns (factory, singleton, builder)