Project | Web & API
Design Patterns in a Selenium and Playwright Framework
Five design patterns doing real work in one Java framework: Page Object, Factory (browser and engine), Strategy (JSON, CSV or API test data), Adapter (two browser engines, three catalog APIs) and Observer (reports, logs, metrics and screenshots from test events).
The same 13 UI tests run on Selenium WebDriver and on Playwright for Java, on 7 browser setups, through one Browser interface. Running both engines exposed a Chrome password-leak dialog that swallowed clicks on Selenium only; the fix lives in the Factory and a test keeps it there.
Evidence checked 22 Nov 2026 | CI run on main
On this page
Problem and purpose
Pattern names are easy to list and hard to show. Here each pattern solves a problem the framework really has: two browser engines behind one interface, test data that can come from three sources, three catalog APIs that disagree on names and prices, and reporting that must not be called from the tests. Running one set of tests on two engines also turns environment problems into visible differences instead of flaky tests.
Architecture
run config ──► BrowserFactory ──► Browser (Selenium or Playwright adapter) Factory, Adapter
▲
test ──► LoginPage / ProductsPage ──┘ (no locators or waits in the test) Page Object
└── users, products ◄── TestDataSource (json | csv | api) Strategy
TestNG ──► TestNgEventBridge ──► TestEventBus ──► report, log, metrics, screenshots ObserverTechnology and tools
| Area | Tools |
|---|---|
| Tests | Java 21, TestNG 7.12, AssertJ: 39 tests (26 unit and API, 13 UI) |
| Engines | Selenium 4.53 (Chrome, Firefox, Edge, Selenium Grid) and Playwright 1.65 for Java (Chromium, Firefox, WebKit) |
| Application | Pattern Shop: pages, REST, SOAP-style XML and a legacy text API |
| CI | GitHub Actions: a core job and 7 UI jobs, each with its own shop container; weekly and on demand |
Engineering decisions and approach
- Page objects hold no assertions; each action returns the page it leads to
- One Browser interface: tests and page objects never import Selenium or Playwright
- The Factory validates the configuration first, so an engine and browser that do not fit stop the run before a browser starts
- Test data source chosen by one property (json, csv or api); the tests do not change
- Listeners found through ServiceLoader: adding a report is a new class, not a change to the tests
Test scope and execution approach
Project-specific checks and execution details documented in the repository:
- Adapters for three catalog APIs: JSON in cents, SOAP-style XML in dollars, legacy upper-case text with error strings
- Observer output on every run: a Markdown report (also in the CI job summary), metrics.json, a log line per test, a screenshot per failed UI test
- Selenium Grid in Docker as one of the browser setups
- Data-provider sign-in tests for every demo user: active, locked, a problem user and a slow user
- A personal guide with the reasons and the alternatives that were not chosen
Results with dated evidence
Historical repository or workflow evidence
CI run on main
The same 13 UI tests run on Selenium WebDriver and on Playwright for Java, on 7 browser setups, through one Browser interface. Running both engines exposed a Chrome password-leak dialog that swallowed clicks on Selenium only; the fix lives in the Factory and a test keeps it there.
Evidence checked: | Open dated evidence
Evidence explorer
Static screenshots are labelled as images; dated workflow links identify the execution evidence and its check date.
The first Selenium Chrome run failed every test that clicked twice after signing in, while Playwright's Chromium passed. Chrome's password manager had recognised the demo password from a data breach and opened a dialog that swallowed the next click. The fix went into the Factory, and a unit test keeps it there.
Static material from the public repository. The linked verification record was checked 2026-11-22; that date is not a screenshot capture date.
Dated workflow record
Evidence checked 2026-11-22. Open CI run on main
Local setup and execution
docker run -d -p 8080:8080 ghcr.io/niranjankagri/pattern-shop-demo-app:latest
mvnw.cmd verify -Dsuite=core
mvnw.cmd verify -Dsuite=ui -Dengine=playwright -Dbrowser=webkit -Ddata.source=csvWorkflow and reports
Known limitations
- The application under test is a small demo shop; the patterns are shown at framework scale
- Edge's first start on a fresh CI runner takes 30 to 45 seconds, so CI starts it once before the tests
- Five patterns, not all of them: no Builder, Decorator or Singleton, by choice
- The application under test is my own small demo shop; the patterns are shown at framework scale, not on a large product.