RELIABLE SUITES · LESSON 8 OF 24
Parameterized tests and boundaries
Turn a small table of cases into separately reported tests.
- test data
- boundaries
- unique names
- loops
Your runnable checkpoint
Extract into a new practice folder. Each download contains tests, configuration, the complete local practice app and an offline lesson. Use Node.js 22 or 24. Each checkpoint is independent.
Install dependencies and browser binaries using the commands below. The test runner starts the practice server on port 4174. Tests target localhost, never the production EduPoly site.
1. Understand the concepts
Data-driven tests are useful when the same behavior must hold for several meaningful inputs. Generate separate tests so each case has its own title, isolation and result.
Choose cases based on requirements: normal text, punctuation, Unicode and boundaries. More cases are not automatically better; use a small set that distinguishes likely mistakes.
Define tests synchronously while the test module is loaded. Put asynchronous operations inside the test body. An async forEach at module scope can register tests unpredictably.
Do not include sensitive personal data in parameterized test names, since names appear in reports and logs. This course uses invented practice text.
2. Build and run
These are complete test files and configuration. The download also includes app/ and server.mjs; preserve their paths. Stop any manually started practice server before running the suite.
npm install
npx playwright install chromium
npm run check
npm testtests/lesson.spec.ts
import { test, expect } from '@playwright/test';
for (const title of ['Read docs', "Learner's task", 'తెలుగు practice']) {
test(`accept title: ${title}`, async ({ page }) => {
await page.goto('/');
await page.getByLabel('Task title', { exact: true }).fill(title);
await page.getByRole('button', { name: 'Add task', exact: true }).click();
await expect(page.getByTestId('task-row')).toContainText(title);
});
}
playwright.config.ts
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 1 : 0,
workers: process.env.CI ? 2 : undefined,
timeout: 30000,
expect: { timeout: 5000 },
reporter: [['list'], ['html', { open: 'never' }]],
use: { baseURL: 'http://127.0.0.1:4174', trace: 'retain-on-failure', screenshot: 'only-on-failure' },
projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],
webServer: { command: 'node server.mjs', url: 'http://127.0.0.1:4174', reuseExistingServer: false, timeout: 15000 }
});
package.json
{
"name": "edupoly-playwright-parameterized-tests",
"version": "1.0.0",
"private": true,
"scripts": {
"test": "playwright test",
"test:headed": "playwright test --headed",
"test:ui": "playwright test --ui",
"check": "tsc --noEmit",
"report": "playwright show-report",
"serve": "node server.mjs"
},
"devDependencies": {
"@playwright/test": "1.56.1",
"typescript": "5.9.3",
"@types/node": "22.20.5"
}
}
tsconfig.json
{
"compilerOptions": {
"target": "ES2022",
"module": "CommonJS",
"moduleResolution": "Node",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"types": [
"node"
],
"noEmit": true
},
"include": [
"tests/**/*.ts",
"pages/**/*.ts",
"playwright.config.ts"
]
}
.gitignore
node_modules/
playwright-report/
test-results/
playwright/.auth/
.env
3. Trace the code and check the result
- The loop registers one scenario per title.
- Each test receives fresh browser storage.
- The assertion checks the actual displayed title.
Verify your result
- Three independently reported tests pass.
- Punctuation and Unicode display as text.
4. Practice independently
Add the 120-character accepted boundary.
Show the explanation
Add "x".repeat(120) to the table. Test over-limit input at the appropriate boundary too: the UI maxlength may prevent typing it, while an API needs its own validation.
When something goes wrong
If a browser executable is missing, run npx playwright install chromium in the project folder. If port 4174 is occupied, stop your manual practice server. Read assertion call logs for mismatched locators or expectations. Use npm run report to inspect failures; do not add fixed sleeps or broad resets to hide them.
