Which design patterns have you used in automation frameworks?
60-second answer
The common ones are: Page Object and Page Component for UI structure; Factory, for creating drivers or API clients based on configuration; Singleton, for configuration that's loaded once, used carefully so it doesn't break parallel runs; Builder, for readable test data objects with sensible defaults; Strategy, to switch behaviour like login via UI, API or SSO at runtime; Facade, to hide multi-step workflows like placing an order behind one method; Decorator or Proxy, to add logging, retries or waits around driver calls; and Observer, through test listeners and event hooks.
Explanation
| Pattern | Framework use |
|---|---|
| Factory | DriverFactory.create(browser) |
| Singleton | Config.get() (immutable, thread-safe) |
| Builder | UserBuilder.aUser().premium().withCart(3).build() |
| Strategy | LoginStrategy (UI / API / cookie) |
| Facade | OrderFlows.placePaidOrder(user) |
| Decorator | EventFiringDecorator + WebDriverListener for logging |
| Observer | TestNG listeners, Playwright page.on(...) |
| Fluent interface | Page methods returning this or next page |
Explain why you chose a pattern, not just its name.
Example
Selenium 4's EventFiringDecorator wrapped the driver to log every click and find with timings, which helped diagnose a slow page without touching test code.
Sample code
WebDriverListener listener = new WebDriverListener() {
@Override public void beforeClick(WebElement element) {
log.info("Click {}", element);
}
@Override public void afterFindElement(WebDriver d, By locator, WebElement result) {
log.debug("Found {}", locator);
}
};
WebDriver driver = new EventFiringDecorator<>(listener).decorate(new ChromeDriver());