Playwright · Middle · Question 22 of 75
How do you parameterize a test over several inputs?
for (const email of ["", "bad", "a@"]) {
test(`rejects "${email}"`, async ({ page }) => {
// ...
});
}- 1Pass an array as the second argument to
test() - 2Loop and declare a test with a unique title for each
- 3Use
test.each, the only supported approach
Show the answer
Correct answer: Loop and declare a test with a unique title for each
Explanation
Playwright collects tests by running the file, so a loop creates one test per value. Titles must be unique.