LESSON VIEW
LAB-3 · AUTOMATION PRACTICE LAB · PRACTICAL QA

Data-Driven Testing

Objective: Separate any repeated check into one template plus a table of rows, and choose — and defend — where the rows live: framework, sheet, database, or generated fresh by factories.

⏱ ≈2.5 h practice unit · Code: copy, paste, practise · English edition — Español · العربية · বাংলা in translation

🧽 The practice business: FreshNest Home Cleaning — a fictional local cleaning company (owner: Maya Torres) invented for this course. Every example and exercise uses FreshNest, so you learn on a complete, realistic business without ever touching a real one.

⚡ Key Points

  • Spot the shape: identical steps, differing inputs → one template + a table of rows.
  • Four homes for data: framework-internal, sheet, database, generated — each with its own owner and failure mode.
  • Validate sheet rows at load, with the row number — never discover bad data mid-run.
  • IDs are forever; row positions are not. One case, one home, or the copies will diverge.
  • Factories beat fixtures: fresh, uniquely-marked entities per run instead of data that rots and collides.

📖 Read

Beginners write one test per case, copying and pasting code and changing a word or two. Professionals notice the shape: the steps are identical; only the inputs differ. Data-driven testing separates the two halves — one test template, and a table of data rows it runs once per row. The payoff is not elegance; it is economics. Twenty cases maintained in a spreadsheet, which a manual tester can edit, beat twenty copies of code, which they cannot. When the data lives outside the code, the people who own the cases can grow the suite without touching the framework: template thinks, data varies.

Where the rows live is an architecture decision, because each of the four homes has a different owner and a different failure mode (A-05). Framework-internal data is owned by the automation engineer — versioned with the code, zero moving parts, but non-coders cannot safely grow it. A sheet (Excel/CSV) is owned by manual testers or the business — anyone can add a row, but it drifts from code and carries no validation until runtime. A database is the product's own world — tests read the actual state customers see, at the price of coupling to the schema. Generated data comes from factories — the framework builds it fresh at runtime, which demands honest modelling of the domain's rules.

Used professionally, each home has disciplines. Sheets: validate the rows like an API — a bad row fails at load, with its row number, not mid-run as a mystery; IDs are forever, so never key anything to row position; and one case, one home, because a case living in both sheet and code will diverge. Databases: read like a guest, never write like an owner — legitimate uses are verification ("the order the UI placed exists, with these totals") and state selection ("find a real active listing"), never creating what the test claims the product created; read-only credentials, and schema knowledge kept in one module. Factories beat static fixtures: fixture data rots — the test user gets edited, dates slide into the past, parallel runs collide — while factories build fresh entities per run, uniquely marked (timestamp, run ID) so cleanup can find everything by its marker. The decision in one paragraph: small suite, technical owner → internal. Business-owned cases → sheet. Verifying what the system stored → database, read-only. Stateful, parallel, repeated → factories. The sin is not the source — it is the accident.

💻 Code for this unit — copy, paste, practise

The original worked code for this unit, verbatim, with its line-by-line explanations. Run it against the course practice project (download on the course page).

B-10 · Example 1 — Data-driven testing

const hrefs = ["/", "/privacy.html", "/terms.html"];
for (const href of hrefs) {
  expect(domPaths).toContain(href);
  // …request the target, expect status < 400…
}

Data-driven at its smallest scale, inside TC-002: the list is data, the loop body is the template. New page on the site → add one string → coverage grows.

B-10 · Example 2 — Data-driven testing

test("[TC-S001] Welcome heading is visible", async ({ page }) => {
  await page.goto("/");
  await expect(page.getByText("Welcome heading is visible").first()).toBeVisible();
});

Give TestGen a sheet (ID, Page, Check — from Excel, Sheets, Jira, Trello) and it generates one test per row, titled with YOUR ID. TC-S001 came from the sheet — not from TestGen.

B-10 · Example 3 — Data-driven testing

const hrefs = ["/", "/privacy.html", "/terms.html"];
// …read the links actually rendered on the page…
for (const href of hrefs) {
  expect(domPaths, `a link to ${href} should be rendered on the page`).toContain(href);
  // …request the target and expect its status to be < 400…
}

From the module's full text.

B-10 · Example 4 — Data-driven testing

/** Generated from your sheet: example-sheet.csv — one test per row, titled with YOUR case ID. */

test("[TC-S001] Welcome heading is visible", async ({ page }) => {
  await page.goto("/");
  await expect(page.getByText("Welcome heading is visible").first()).toBeVisible();
});

test("[TC-S002] Privacy Policy heading is visible", async ({ page }) => {
  await page.goto("/privacy.html");
  await expect(page.getByText("Privacy Policy heading is visible").first()).toBeVisible();
});

From the module's full text.