🌐
Playwright
playwright.dev › parameterize tests
Parameterize tests | Playwright
import { test as base } from '@playwright/test'; export type TestOptions = { person: string; }; export const test = base.extend<TestOptions>({ // Define an option and provide a default value. // We can later override it in the config. person: ['John', { option: true }], // Override default "page" fixture. page: async ({ page, person }, use) => { await page.goto('/chat'); // We use "person" parameter as a "name" for the chat room.
🌐
Medium
medium.com › syntest › what-are-parameterized-tests-in-playwright-and-why-should-you-use-them-e2c8ef02a73b
What Are Parameterized Tests in Playwright and Why Should You Use Them?
March 7, 2025 - Writing automated UI tests in Playwright is already powerful, but parameterized tests take it to the next level by allowing you to run the same test logic with multiple inputs.
Discussions

parameters - How can I parameterize tests in Playwright to run only specific tests for different environments? - Stack Overflow
We are using Playwright Automation framework using Typescript to do our Testing. We have 3 different environments. Right now, our project is having different code base for TST and UAT( Dev and TST ... More on stackoverflow.com
🌐 stackoverflow.com
[Feature] Simple and elegant data driven parameterized tests
Hello Playwright team, currentlly for passing parameters in tests we can use 'for loop'. More on github.com
🌐 github.com
1
April 9, 2023
How to use parameterize tests at runtime?
Have you tried something like this? import { expect, test, type Locator } from '@playwright/test'; const apiVersions = ['1', '2']; const testItems = new Map(); for (const apiVersion of apiVersions) { test.describe(Test Suite v${apiVersion}, () => { test(v${apiVersion}, async ({ page }) => { testItems.clear(); await page.goto('/'); const buttons = await page.locator('li').getByRole('button').all(); for (const button of buttons) { const title = await button.inputValue(); testItems.set(title, button); } for (const [title, button] of testItems) { await test.step(title, async () => { // add a random assertion here await expect(button).toHaveText(title); }); } }); }); } More on reddit.com
🌐 r/Playwright
8
1
June 24, 2024
[Feature] Parametrization API for Playwright Test
Originally posted by andrejs-ps November 12, 2021 Currently, there is no API to parametrize individual tests. To pass in a single parameter, one would use a for loop, as suggested in the documentation (https://playwright.dev/docs/test-parameterize) More on github.com
🌐 github.com
8
November 15, 2021
🌐
Allure Report
allurereport.org › docs › guides › playwright-parameterization
Allure Report Docs – Playwright parameterization
The source code used in this guide is available at https://github.com/allure-examples/guide-playwright-parameterization. ... Navigate to the project directory and install the dependencies using a package manager of your choice: ... Let’s start with a simple function. We want to check if adding two numbers gives the right answer: ... import { expect, test } from "playwright/test"; const sum = (a, b) => { return a + b; }; test("basic sum", () => { expect(sum(1, 2)).toBe(3); });
🌐
Octoperf
blog.octoperf.com › maximizing-testing-efficiency-parameterizing-playwright-scripts
Maximizing Testing Efficiency: Parameterizing Playwright Scripts - OctoPerf
October 13, 2023 - Parameterization in testing is a powerful technique that allows you to run the same test script with different inputs, configurations, or scenarios. In the world of browser automation and testing, Playwright provides various methods to parameterize ...
🌐
DEV Community
dev.to › pgangwani › achieving-asynchronous-parameterized-tests-in-playwright-with-api-data-28f5
Achieving Asynchronous Parameterized Tests in Playwright with API Data - DEV Community
October 25, 2024 - This blog post will guide you through setting up asynchronous parameterized tests in Playwright using data fetched from an API.
🌐
Strapi
strapi.io › blog › data-driven-testing-with-playwright
A Scalable Approach to Data-Driven Testing with Playwright
June 15, 2025 - That’s where parameterized tests come in. In Playwright, parameterized tests allow you to run the same test logic across different sets of data, ensuring comprehensive test coverage without redundant code.
🌐
Stack Overflow
stackoverflow.com › questions › 76231285 › how-can-i-parameterize-tests-in-playwright-to-run-only-specific-tests-for-differ
parameters - How can I parameterize tests in Playwright to run only specific tests for different environments? - Stack Overflow
The second approach seems a better one but I don't know what parameters I can use here and how can I achieve this. ... You could put tags on the tests and specify which to run with the grep command flag, which you can set as pipeline variables. test('Test 1 @dev @test', async ({ page }) => { // ... }); test('Test 2 @dev', async ({ page }) => { // ... }); Then use npx playwright test -g @dev to run all tests flagged @dev
🌐
GitHub
github.com › microsoft › playwright › issues › 22295
[Feature] Simple and elegant data driven parameterized tests · Issue #22295 · microsoft/playwright
April 9, 2023 - Hello Playwright team, currentlly for passing parameters in tests we can use 'for loop'. // example.spec.ts const people = ['Alice', 'Bob']; for (const name of people) { test(`testing with ${name}`, async () => { }); } We tent to use mul...
Author   NikkTod
Find elsewhere
🌐
DEV Community
dev.to › this-is-learning › playwright-parametrize-tests-2p2
Playwright - Parametrize tests - DEV Community
March 15, 2023 - The easiest way to do that with Playwright is using vanilla javascript. You can create an array with different cases, and using the for clause, you can call the test N times with different parameters.
🌐
Checkly
checklyhq.com › docs › learn › playwright › how-to-parameterize-playwright-projects
Parameterizing your Playwright projects - Checkly Docs
Playwright’s test method allows you to enrich Playwright’s core functionality with your own custom fixtures and options. The trick is to import and rename test, extend it with your custom additions, and then export the returned value as test to be used in your test cases.
🌐
Test Automation Blog
test-automation.blog › home › playwright
How to parameterize Playwright tests with different data - Test Automation Blog
April 30, 2025 - These could be written as 4 separate tests but since the steps will be identical it’s easier and more maintainable to write as a single, parameterized Playwright automated test.
🌐
Run, Code & Learn
blog.delpuppo.net › playwright-parametrize-tests
Playwright - Parametrize tests - Run, Code & Learn
February 23, 2023 - The easiest way to do that with Playwright is using vanilla javascript. You can create an array with different cases, and using the for clause, you can call the test N times with different parameters.
🌐
Reddit
reddit.com › r/playwright › how to use parameterize tests at runtime?
r/Playwright on Reddit: How to use parameterize tests at runtime?
June 24, 2024 -

Hey everyone,

I'm using Playwright for a little while now, but it's my first time dealing with parameterize tests. My problem is the following, it works well when the arrays are initialised before running the tests (put simply, when the array value is hard coded). But when I want to set the array value at runtime (during test execution) I get errors like:

Error: page.goto: Target page, context or browser has been closed
Error: page.goto: net::ERR_ABORTED; maybe frame was detached?

This is a snippet of what my current code is looking:

import { expect, test, type Locator } from '@playwright/test';

const apiVesions = ['1', '2'];
const testItems = new Map<string, Locator>();

for (const apiVersion of apiVesions) {
  test.describe('Test Suite', async () => {
    test(`v${apiVersion}`, async ({ page }) => {
      testItems.clear();

      await page.goto('/');

      const buttons = await page.locator('li').getByRole('button').all();
      
      for (const button of buttons) {
        const title = await button.inputValue();
        testItems.set(title, button);
      }

      for (const [title, button] of testItems) {
        test.step(title, async () => {
          // add a random assertion here
          await expect(button).toHaveText(title);
        });
      }
    });
  });
}

I put console.log everywhere, but the last loop (set dynamically), is never reach/executed. But loop correctly the first `apiVersions` array (in the real code, I have 3 hard coded arrays, no issue).

So, my question is, is it possible to achieve this, or does Playwright want some deterministic thing?

And, if possible, ideally, I want the loop to be for a `test` and not `test.step` (but currently tried, not working too)

And, lastly I'm taking any idea/resources, to try, even the wildest ones (but don't tell me to use another framework 😂 I can't, it's a job constrain).

Thanks for taking the time to read my post!

EDIT

My goal is not ONLY to loop through a list of Locator and perform some action. I need to perform the same series of task on a list (that change depending on version, environment, and a cluster location — those arrays are already hardcoded). Now, when everything is set up, the actual list is grabbed during test execution. I want to use `test` annotation (not `test.step` actually) to generate a good report. Another reason is that, a task may fail on one item on the list and should not impact the other ones (this is why `test.step` is a bit restrictive, even if I can wrap the task around a `try-catch` block to avoid the test failing). I attached a screenshot of the failing run to give you an idea.

PS: `auto()` is not a Playwright function or whatever, if you are interested you can look at it here: https://github.com/lucgagan/auto-playwright (DISCLAIMER: not mine)

EDIT 2 (not encouraging)

When I don't initialise the dynamic array (with an empty array []) the test don't actually start 🙁. Note that it's not even the first loop in the test, I perform some action before reaching it. This is the error:

TypeError: myArray is not iterable

EDIT 3 (good news)

Found this: https://github.com/microsoft/playwright/issues/9916

And, finally make `test.step` working. I forgot to await the `test.step` (my bad 🙁). But, I'm still open, if there is a way to use `test` directly.

🌐
Playwright
playwright.dev › parallelism
Parallelism | Playwright
These processes are OS processes, running independently, orchestrated by the test runner. All workers have identical environments and each starts its own browser. You can't communicate between the workers.
🌐
SKPTRICKS
skptricks.com › 2025 › 05 › best-ways-to-parameterize-tests-in-playwright.html
Best ways to Parameterize tests in playwright | SKPTRICKS
Parameterized testing in Playwright allows us to run the same test logic with multiple sets of inputs, increasing test coverage and reducing duplicati
🌐
Medium
qa-nora.medium.com › how-to-parameterize-projects-in-playwright-82da3b8a1baf
How to parameterize projects in Playwright | by Eleonora Belova | Medium
February 1, 2024 - To run a specific project, utilize the following command: npx playwright test -project=<project name>. This command executes the login test case against a predefined dataset for the specified project. In this piece, I shared my findings regarding parameterization in Playwright projects, covering aspects ranging from establishing test data to updating configurations and implementing options.
🌐
ProgramsBuzz
programsbuzz.com › article › playwright-parameterized-tests
Playwright Parameterized Tests
December 12, 2022 - Various usernames will be used on the same test using parameterized method. First let us create a constant with three names for our username. ... Using an advanced for loop encase the test within it. ... It should look like this. const {test, expect} = require('@playwright/test'); const people = ['Sasuke', 'Itachi','Naruto']; for (const name of people) { test(`Parameterized Testing With ${name}`, async ({page})=> { await page.goto('https://www.programsbuzz.com/user/login'); await page.locator('#edit-name',`${name}`) }); }
🌐
GitHub
github.com › microsoft › playwright › issues › 10325
[Feature] Parametrization API for Playwright Test · Issue #10325 · microsoft/playwright
November 15, 2021 - Originally posted by andrejs-ps November 12, 2021 Currently, there is no API to parametrize individual tests. To pass in a single parameter, one would use a for loop, as suggested in the documentation (https://playwright.dev/docs/test-parameterize)
Author   pavelfeldman