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.

Test automation framework architectureTeststest_checkout_with_promo()Steps / Page ObjectsCartPage.apply_promo(code)Clients and utilitiesApiClient · TestDataFactory · WaitsDriverPlaywright · Selenium · Appium · requestsApplication under testWeb · API · mobile · desktop
Test automation framework architecture. Tests describe the scenario in business language, Page Objects know the pages, clients and the driver know how to reach the app. A UI change is fixed in one layer.

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.

Flaky tests: cause → fixsleep(3) instead of a waitWait for a condition: visible, API responseTests depend on run orderEach test creates its own dataData shared between testsUnique data + cleanup in teardownUnstable external serviceMock or contract testAnimations and UI racesDisable animations in test mode
Flaky tests: cause → fix. An unstable test is worse than no test: the team stops trusting a red build. Retries hide the problem — find the cause.

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. 1. Where should element selectors live?

  2. 2. The best way to prepare data for a UI cart test?

  3. 3. A test fails once in 10 runs. First step?

Practice: Automation interview questions