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 }) => {
    // ...
  });
}
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.

Further reading

Problem with a question

Playwright · Middle · question 22

Test yourself

Take the Playwright · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz