Chapter 54: Data-driven and parameterized tests
Automation learning lab
Playwright Automation
Self Study Guide
Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.
Data-driven and parameterized tests
Parameterized tests use data records to define multiple independent cases. Generate a unique test title for each case at declaration time. Each test receives its own fixtures and should assert its own expected result.
How it works
Step-by-step walkthrough
- Define test records
- Loop to declare tests
- Run and inspect separate results
Example
import { test, expect } from '@playwright/test';
const cases = ['Alpha', 'Beta'];
for (const name of cases) {
test(`renders ${name}`, async ({ page }) => {
await page.setContent('<h1></h1>');
await page.locator('h1').evaluate((el, value) => el.textContent = value, name);
await expect(page.getByRole('heading')).toHaveText(name);
});
}Use distinct titles and avoid shared mutable test data.
✎ Your practice task
Add a third data record.
Knowledge check
Why use unique test titles?
🌐 Continue learning
60-chapter learning path
Start at chapter 1, or choose any topic. Your progress is tracked separately for each chapter.
JavaScript fundamentals
TypeScript fundamentals
Playwright • setup & locators
Playwright • interactions & assertions
Playwright • framework & debugging
Playwright • real-world automation
Interactive practice lab
Try the controls below and observe the corresponding Playwright locator instructions. This browser demo does not execute Node.js or Playwright Test; copy the code to your local Playwright project to automate it.
Task manager demo
Suggested automation
Actions on the demo update these examples. In your local test use a page that contains the same controls.
Download a standalone lab page, then serve it locally (for example with Python's http.server). Navigate to it in a Playwright test.