Framework Architecture & CI/CD · Lesson 2 of 6

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.

By Shahriyar · Updated

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

▸ try it
# 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 obvious

Read 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)

All lessons in Framework Architecture & CI/CD

  1. Designing a Framework from Scratch: The Layers
  2. The Four Patterns SDETs Actually Use
  3. Test Data: Fixtures vs Factories vs Seeding
  4. CI with GitHub Actions: Run UI + API on Every Push
  5. Docker & Selenium Grid: Reproducible Test Environments
  6. Parallel, Retries & Flaky-Test Quarantine