QA AND TEST AUTOMATION · PART 7 · BDD AND FRAMEWORK DESIGN · DESIGN · 69 OF 112

Test Automation Framework Architecture: The Layers

How a test automation framework is organised so other people can use it: the layers (tests, flows, page objects and API clients, core services, configuration), what belongs in each, a project layout for ShopRung, configuration per environment and secrets, test data builders, and the rules that keep a framework small, readable and fast.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 67
  63. 68
  64. 69
  65. 70
  66. 71
  67. 72
  68. 73
  69. 74
  70. 75
  71. 76
  72. 77
  73. 78
  74. 79
  75. 80
  76. 81
  77. 82
  78. 83
  79. 84
  80. 85
  81. 86
  82. 87
  83. 88
  84. 89
  85. 90
  86. 91
  87. 92
  88. 93
  89. 94
  90. 95
  91. 96
  92. 97
  93. 98
  94. 99
  95. 100
  96. 101
  97. 102
  98. 103
  99. 104
  100. 105
  101. 106
  102. 107
  103. 108
  104. 109
  105. 110
  106. 111
  107. 112
1 / 12

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Tests → flows → page objects and API clients → core
  • config per environment
  • data builders
  • simple rules

Notes

The layers

A good framework has layers. At the top, tests: what is checked, with the assertions. Below them, flows or steps: reusable journeys like log in or buy a product. Then page objects and API clients: how to reach the system. At the bottom, core services: creating browsers and HTTP clients, reading configuration, building test data, logging. Each layer only uses the one below it, so a change in one place stays in one place.

Top to bottom
  • tests: WHAT is checked (scenarios, assertions)
  • flows: reusable journeys (log in, buy a product)
  • page objects + API clients: HOW to reach the system
  • core: driver factory, HTTP, config, data, logging
  • each layer uses only the layer below

Tests

Tests sit at the top. A test should read like the requirement: a customer adds four notebooks, applies save ten, and the total is forty nine ninety nine. No locators, no URLs, no JSON parsing, no waits. Assertions live here and only here, so anyone can see what a test checks without opening other files. If a test is longer than a screen, something below it is missing.

A test at the top
@Test
void save10At50Dollars() {
  var alice = users.customer();
  var cart = shop.as(alice)
    .addToCart(NOTEBOOK, 4)
    .applyCoupon("save10");
  assertEquals("$49.99",
    cart.total());
}

Access layer

The access layer knows how to reach the system. For the UI, page objects and components like the header. For APIs, one client per resource: auth, cart, orders. Both return domain objects, like a cart record, not raw JSON or web elements, so tests stay readable. Flows combine them: log in through the API, then check the cart in the UI. Mixing API setup with UI checks is what makes UI suites fast.

How we reach the system
  • UI: page objects and components (Header, Cart)
  • API: one client per resource (AuthApi, CartApi, OrdersApi)
  • both return domain objects (Cart, Order), not raw JSON or WebElements
  • flows combine them: login via API, check via UI

Core

The core holds shared services. A driver factory creates the right browser from configuration: Chrome or Firefox, headless or not, local or a remote grid. An HTTP client with the base URL, authentication and logging on failure. Test data builders that create unique users and orders and clean them up. And shared helpers for waits, logging and reporting. Tests never create drivers or clients themselves.

Core services
  • DriverFactory: browser by config (chrome, headless, remote grid)
  • HttpClient: base URL, auth, logging on failure
  • TestData: builders, unique emails, cleanup
  • Waits, retries (for setup only), logging, reporting

Configuration

Configuration lets one suite run anywhere. Defaults in a properties file, one file per environment like staging, and overrides from system properties or environment variables, in that order. Choose the environment with one flag, such as env equals staging. Secrets, like passwords and API keys, come from CI secret variables and never live in files in Git. Tests never contain a URL or a password.

Config resolution
defaults     config/default.properties
environment  config/staging.properties
overrides    -DbaseUrl=... or
             BASE_URL env variable
secrets      CI secret variables
             (never in files)

mvn test -Denv=staging
  → staging URL, staging users

Layout

As folders, a ShopRung framework might look like this. Tests split by type: API, UI and end to end. Flows. Page objects with shared components. API clients. Core services. A model package for domain objects like cart, order and user. And configuration files under resources. A new team member can find where anything belongs, which is the real test of a framework.

src/test/java/dev/algorung
tests/   api/  ui/  e2e/
flows/   CheckoutFlow
pages/   LoginPage CartPage
         components/Header
api/     AuthApi CartApi
core/    Config DriverFactory
         Http TestData
model/   Cart Order User
resources/config/*.properties

Test data

Test data deserves its own place. Builders create exactly what a test needs through the API, with sensible defaults and only the interesting fields set in the test, like a customer with a specific name. Each call makes unique data, such as an email with a random id, and cleans it up afterwards. This is what makes parallel runs safe, as the parallel episode showed with ShopRung.

Data per test
User u = TestData.customer()
  .withName("Test Shopper")
  .create();   // via the API

unique email per call:
  shopper-<uuid>@shoprung.test
clean up what you create

enables parallel runs

Principles

A few rules keep a framework healthy. Tests read like requirements and contain no logic: no if statements around UI state. There is one way to do each thing, not three login helpers. Failures are fast and clear. Unused code gets deleted. A README and one example test per layer let newcomers start. And framework code is reviewed like product code, because it is product code for testers.

Rules of thumb
  • tests read like requirements
  • no logic in tests (no ifs, no loops over UI state)
  • one way to do each thing
  • fail fast, fail clearly
  • small: delete unused code
  • documented: a README and one example test per layer
  • reviewed like product code

Common mistakes

Framework anti patterns. A god base test with two thousand lines of helpers every test inherits. Assertions hidden inside page objects. Hard coded URLs, sleeps and credentials. Copying a huge framework from the internet before writing a single test. And wrapping every library call in your own layer just in case you switch tools one day: that wrapper usually becomes the hardest code in the project.

Avoid these
  • a god BaseTest with 2,000 lines of helpers
  • assertions hidden in pages
  • hard-coded URLs, waits, credentials
  • copying a big framework before writing one test
  • wrapping every library call "in case we switch"

Say it like this

In the interview, describe layers and reasons. Tests that read like requirements and are the only place with assertions. Flows for reusable journeys. Page objects and per resource API clients that return domain objects. A core with a driver factory, an HTTP client, configuration and data builders. Configuration per environment with secrets from CI. Unique data per test so it runs in parallel, and reports with screenshots and logs on failure. Then give one number, like run time or flakiness, that improved.

In the interview
  • "Layers: tests that only assert; flows; page objects
  • and per-resource API clients
  • returning domain objects; a core with driver factory, HTTP, config and data builders.
  • Config per env, secrets from CI. Unique data per test, so it runs in parallel; reports
  • with evidence on failure."

Interview questions

Q1What are the layers of a test automation framework?

Tests (assertions), flows or steps (journeys), page objects and API clients (access), core services (driver factory, HTTP client, config, data, logging), and configuration.

Q2Where should assertions live?

In tests, so each test shows what it checks; page objects and clients only expose state and actions.

Q3How do you run one suite against several environments?

Layered configuration: defaults, a file per environment selected by a flag, overrides from system properties or environment variables, and secrets from CI.

Q4What is a driver factory?

A core class that creates the configured WebDriver (browser, headless, local or remote grid) so tests never construct drivers themselves.

Q5How should test data be handled in a framework?

Builders that create unique data through APIs with sensible defaults, cleaned up after use, so tests are independent and parallel-safe.

Q6Why return domain objects from page objects and API clients?

So tests read in business terms and are insulated from JSON shapes and DOM details.

Q7What makes a framework hard to maintain?

God base classes, hidden assertions, hard-coded values, duplicated helpers, excessive wrappers and missing documentation.

Q8How do you judge a framework?

How quickly a newcomer adds a reliable test, how fast and stable the suite runs, and how clearly failures explain themselves.