๐ŸŒ
GitHub
github.com โ€บ microsoft โ€บ playwright-pytest โ€บ issues โ€บ 27
Tests are parameterized even if not using playwright fixtures ยท Issue #27 ยท microsoft/playwright-pytest
November 18, 2020 - Tests are parameterized that don't use playwright fixtures. For example, given these tests: def test_page(page): print("page") def test_other(): print("other") ... % pytest test.py --verbose =============================== test session starts ...
Author ย  jcushman
๐ŸŒ
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.
Discussions

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
automated tests - Playwright - passing arguments into python script - Stack Overflow
Is there a way to pass arguments into a playwright test in python? I want to be able to check a certain string appears on the browser screen, but this string is variable. e.g. if i call the test sc... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - How to parameterize element locators in pytest playwright - Stack Overflow
How to write an element locator of which the text value could be parameterized in Pytest Playwright. Eg: We can do it like this in Selenium, initially define a string: String product_code = form[... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Parameterized tests timeout : r/Playwright
๐ŸŒ r/Playwright
๐ŸŒ
Chercher
chercher.tech โ€บ null โ€บ null โ€บ parameterize playwright tests - python
Parameterize Playwright Tests - Python
August 29, 2018 - If you have a case where you have to check the user names against the different passwords then you can create two different parameters like the one below. Each username is validated against a different password on each iteration. @pytest.mark.parametrize("username", [ pytest.param("cher", marks=pytest.mark.xfail), pytest.param("tech", marks=pytest.mark.xfail), ("standard_user")]) @pytest.mark.parametrize("password", [ pytest.param("password1", marks=pytest.mark.xfail), pytest.param("password2", marks=pytest.mark.xfail), ("secret_sauce")]) def test_login(playwright: Playwright, username, password): print(f"username : {username}, password : {password}")
๐ŸŒ
Way2Automation
way2automation.com โ€บ home โ€บ parameterization (data driven testing) using playwright python
Parameterization (Data Driven Testing) using Playwright Python - Way2Automation
February 10, 2023 - This is how we can perform data driven testing. ... importโ€‹โ€‹ time importโ€‹โ€‹ pytest fromโ€‹โ€‹ playwright.sync_apiโ€‹โ€‹ importโ€‹โ€‹ Page,โ€‹โ€‹ expect @pytest.mark.parametrize("username",โ€‹โ€‹ [("TestUser1"),("TestUser2"),("TestUser3")]) defโ€‹โ€‹ test_example(page: Page,โ€‹โ€‹ username) ->โ€‹โ€‹ None: โ€‹โ€‹ โ€‹โ€‹ โ€‹โ€‹โ€‹โ€‹ page.goto("http://zero.webappsecurity.com/login.html") โ€‹โ€‹ โ€‹โ€‹ โ€‹โ€‹โ€‹โ€‹ page.locator("#user_login").fill(username) โ€‹โ€‹ โ€‹โ€‹ โ€‹โ€‹โ€‹โ€‹ time.sleep(6)
Price ย  $$$
Address ย  CDR Complex, 3rd Floor, Naya Bans Market, Sector 15, Noida
๐ŸŒ
Octoperf
blog.octoperf.com โ€บ maximizing-testing-efficiency-parameterizing-playwright-scripts
Maximizing Testing Efficiency: Parameterizing Playwright Scripts - OctoPerf
October 13, 2023 - Create robust, scalable, and adaptable Playwright test scripts via parameterization. Explore several approaches to parameterizing Playwright scripts such as external data sources, environment variables, command-line arguments and more.
๐ŸŒ
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 - In this guide, youโ€™ll learn how to implement parameterized tests in Playwright, along with best practices and a real-world example.
๐ŸŒ
Way2Automation
way2automation.com โ€บ home โ€บ parameterize tests and usage of text locator in playwright
Parameterize Tests and usage of Text locator in Playwright - Way2Automation
August 1, 2022 - Now, launchโ€‹โ€‹ https://playwright.dev/docs/test-parameterizeโ€‹โ€‹
Price ย  $$$
Address ย  CDR Complex, 3rd Floor, Naya Bans Market, Sector 15, Noida
๐ŸŒ
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.

Find elsewhere
๐ŸŒ
LambdaTest
lambdatest.com โ€บ automation-testing-advisor โ€บ python โ€บ playwright-python-pytest_generate_tests
Use pytest_generate_tests in Playwright Python With Examples | LambdaTest
Use the pytest_generate_tests method in your next Playwright Python project with LambdaTest Automation Testing Advisor. Learn how to set up and run automated tests with code examples of pytest_generate_tests method from our library.
๐ŸŒ
Playwright
playwright.dev โ€บ writing tests
Writing tests | Playwright Python
Pages are isolated between tests due to the Browser Context, which is equivalent to a brand new browser profile, where every test gets a fresh environment, even when multiple tests run in a single Browser. ... from playwright.sync_api import Page def test_example_test(page: Page): pass # "page" belongs to an isolated BrowserContext, created for this specific test.
๐ŸŒ
Playwright
playwright.dev โ€บ pytest plugin reference
Pytest Plugin Reference | Playwright Python
This plugin configures Playwright-specific fixtures for pytest. To use these fixtures, use the fixture name as an argument to the test function. def test_my_app_is_working(fixture_name): pass # Test using fixture_name # ... Function scope: These fixtures are created when requested in a test function and destroyed when the test ends. ... new_context: Allows creating different browser contexts for a test. Useful for multi-user scenarios. Accepts the same parameters ...
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 76941767 โ€บ playwright-passing-arguments-into-python-script
automated tests - Playwright - passing arguments into python script - Stack Overflow
from playwright.sync_api import sync_playwright, Page, expect import re def test(): playwright = sync_playwright().start() chromium = playwright.chromium # or "firefox" or "webkit". browser = chromium.launch(headless=False) # TODO remove this later page = browser.new_page() page.goto("https://playwright.dev/") # Expect a title "to contain" a substring. expect(page).to_have_title(re.compile("Playwright")) # create a locator get_started = page.get_by_role("link", name="Get started") # Expect an attribute "to be strictly equal" to the value. expect(get_started).to_have_attribute("href", "/docs/intro") # Click the get started link. get_started.click() # Expects the URL to contain intro. expect(page).to_have_url(re.compile(".*intro")) ... You should not pass as parameter a string to verify on the screen.
๐ŸŒ
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); });
๐ŸŒ
Pamelafox
blog.pamelafox.org โ€บ 2024 โ€บ 07 โ€บ playwright-and-pytest-parametrization.html
Playwright and Pytest parametrization for responsive E2E tests
Fortunately, Playwright makes it easy to change the viewport of a browser window, via the set_viewport_size function: page.set_viewport_size({"width": 600, "height": 1024}) I wanted to make sure that all the functionality was still usable at all supported viewport sizes. I didn't want to write a new test for every viewport size, however. So I wrote this parameterized pytest fixture:
๐ŸŒ
TestAndAnalysis
testandanalysis.home.blog โ€บ 2023 โ€บ 06 โ€บ 06 โ€บ improve-test-coverage-by-parameterising-tests-with-playwright-and-other-tools
Improve test coverage by parameterising tests with Playwright and other tools โ€“ TestAndAnalysis
June 6, 2023 - When you parameterise a Playwright test you will need to parameterise the testโ€™s name because the testโ€™s name is used in the name of the screenshot. If the value of your parameter can be used in the test name and in the test you can use an array of strings to hold your parameters.
๐ŸŒ
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.
๐ŸŒ
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 ensures that all test cases are available when the tests start. Parameterized Tests: The testCases.forEach loop dynamically creates a test for each set of parameters retrieved from the API.
๐ŸŒ
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.