Parameterized and data-driven tests, and environment variables
Write one test and run it with many sets of data, and switch the site address or a secret from outside the code, without copying the test.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: one recipe cooked with different ingredients. A cook has one recipe for soup. Today it is carrots. Tomorrow it is tomatoes. The steps stay the same. Only the ingredients change. Nobody writes a new recipe for each vegetable.
Daily List is a to-do list app. Tom, the tester, wants to check that Add task accepts different kinds of name. He wants a short name, a long name, a name with a number and a name with an emoji. He could copy one test four times. Then a change to the steps means four edits.
What it is: Playwright is a free tool, made by Microsoft, that drives real web browsers from test code. This topic is about two habits that work with its . The first is a parameterized test: you write the steps once and feed in many sets of data. The data are called . The second is an environment variable, a setting that lives outside your code, such as the website address. Neither habit is a Playwright invention. Playwright lets you do both with ordinary JavaScript or TypeScript, so there is no special add-on to learn.
Why it matters: four near-copy tests drift apart the first time someone edits only three. One parameterized test feeds four names through the same steps, so Tom changes the path once and covers every case. A site address and a password kept outside the code let the same tests run on a test site, on staging and on the .
The picture has a limit. A soup recipe tastes different with each vegetable, but a test must still check the right thing for each one.
Kept simple: this lesson covers a loop and a settings file. Playwright also has per-project settings, which a later lesson covers.
(SYNTHETIC / TRAINING ONLY: Daily List, its test site and every person named here are made up.)
PLAIN WORDS · 4 in this section
- emoji
- a small picture character, such as a smiling face
- playwright
- a free Microsoft tool that drives a browser for tests
- parameterized
- sending values apart from the command so they cannot alter
- typescript
- JavaScript with added labels for the kinds of data
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.
THE REAL JOB Running the same steps with many inputs, and pointing the same tests at different copies of the app, without copying anything.
- Write the steps once
- List the data
- Loop to make tests
- Set the kitchen from outside
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| The recipe | The test steps |
| The ingredients | The list of test data |
| The kitchen you cook in | The environment, set from outside |
| The key to the pantry | A secret kept out of the code |
WHERE THIS PICTURE STOPS
- A recipe tastes different with each vegetable, but a test must check the right thing for each input.
- A cook picks ingredients by hand. A loop makes them all at file load, so the list must be ready.
- A pantry key can be copied. A secret can leak if it is printed in a report.
HOOK
One recipe, many ingredients, any kitchen.
REMEMBER IT THIS WAY
A chunk: a long list grouped so it is easier to hold.
Write the steps once and loop the data. Tom's four names are short, long, number and emoji.
| In the trick | What it stands for |
|---|---|
| short | a short name |
| long | a long name |
| number | a name with a number |
| emoji | a name with an emoji |
A loop makes every test at file load, so the data list must be ready first.
TELL A FRIEND
One recipe cooked with different ingredients, in whichever kitchen you are given.
OFTEN MIXED UP WITH Test structure: describe, hooks, tags, annotations and skipping. The structure lesson covers hooks and tags. This lesson uses them with loops and settings.
Sources & standards — 3 sources
- Market practice
Parameterize tests (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
III. Config (The Twelve-Factor App) ↗ — Adam Wiggins · Keep config, including credentials, in the environment and not in the code (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Playwright Test class reference (Playwright documentation) ↗ — Microsoft (Playwright) · test.step groups actions under a name in the report; test.info() returns the TestInfo of the running test (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
PRACTISE AND KEEP
Sources for this topic — 3 sources
- Market practice
Parameterize tests (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
III. Config (The Twelve-Factor App) ↗ — Adam Wiggins · Keep config, including credentials, in the environment and not in the code (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Playwright Test class reference (Playwright documentation) ↗ — Microsoft (Playwright) · test.step groups actions under a name in the report; test.info() returns the TestInfo of the running test (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.