Module 2. Advanced testing · Lesson 16 of 41 · 13 min
Test automation architecture and fighting flaky tests
Framework layers, Page Object, test data, stability and running in CI.
Automated tests are a product too
Test code is read and changed more often than it's written. Without an architecture, a hundred tests turn into copies of selectors within six months, and every UI change breaks them.
Layers
- Tests read like a scenario: "add an item, apply a promo code, check the total".
- Page Objects / steps know how the pages are built and expose methods like
apply_promo(code). - Clients and utilities: an API client for setting up data, test data factories, waits.
- Driver — Playwright, Selenium, Appium or an HTTP client.
The rule: a test doesn't know selectors, and a Page Object doesn't know about business assertions.
Test data
The most reliable approach is to create data through the API before a test and clean it up afterwards. A UI test that registers a user through the form just to check the cart is slow and brittle. Generate unique data the way the test data generator does — only in code.
Flaky tests
A test that sometimes fails without code changes destroys trust in the whole suite: the team gets used to ignoring a red build.
What to do with a flaky test: find the cause from the trace and the screenshot → fix it → if that can't be done quickly, quarantine it with a ticket to fix. Retries without analysis only hide the problem.
Running in CI
- Smoke on every pull request, a few minutes.
- Full regression nightly or before a release.
- Parallel runs and sharding.
- Failure artifacts: screenshot, trace, video, log.
In QA Tools, automated test results appear next to the manual testing of the same project — with each test's history and failure screenshots. The basics are in the intro to test automation.
Key takeaways
- A framework has layers: tests, Page Objects, clients and utilities, the driver.
- Test data is created through the API and cleaned up after the test.
- A flaky test is cured by finding the cause, not by retries.
Check yourself
1. Where should element selectors live?
2. The best way to prepare data for a UI cart test?
3. A test fails once in 10 runs. First step?