Playwright + JS · Lesson 27 of 35
Module 27: Test Data & Parameterization
Try it yourself
Implement generateCartesianProduct:
The editor has a worked example. Read it, tweak it, then press Mark as complete.
import { test, expect } from "@playwright/test";
const searchQueries = [
{ term: "Playwright", expectedCount: 10 },
{ term: "JavaScript", expectedCount: 20 },
{ term: "Automation", expectedCount: 15 },
];
for (const { term, expectedCount } of searchQueries) {
test(`search for "${term}" returns at least ${expectedCount} results`, async ({ page }) => {
await page.goto("/search");
await page.getByPlaceholder("Search").fill(term);
await page.keyboard.press("Enter");
await expect(page.locator(".search-result")).toHaveCount(expectedCount);
});
}Data-driven testing allows you to run the same test scenario across multiple inputs without duplicating code. In this lesson, we will explore static JSON test fixtures, parameterized test loops, and dynamic test data generation. Let's parameterize our tests!
Part of the Playwright + JS course (Playwright with JavaScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
Each iteration of the loop creates a completely distinct test entry in the HTML report with its own execution time, video, and trace file.
Finished reading?
Review the worked example in the editor, then mark the lesson complete.