🌐
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 - % pytest test.py --verbose --browser chromium --browser firefox =============================== test session starts =============================== platform darwin -- Python 3.8.1, pytest-6.1.2, py-1.9.0, pluggy-0.13.1 -- .pyenv/versions/3.8.1/envs/playwright-test/bin/python3.8 cachedir: .pytest_cache rootdir: ... plugins: base-url-1.4.2, playwright-0.0.8 collected 4 items tests/test.py::test_page[chromium] PASSED [ 25%] tests/test.py::test_other[chromium] PASSED [ 50%] tests/test.py::test_page[firefox] PASSED [ 75%] tests/test.py::test_other[firefox] PASSED [100%] ================================ 4 passed in 3.12s ================================ I didn't expect test_other to be parameterized as test_other[chromium] in the first scenario, or called twice in the second scenario.
Author   jcushman
🌐
GitHub
github.com › list4c › playwright-python-testing
GitHub - list4c/playwright-python-testing: Template repository for automated testing using Playwright and Python
Template repository for automated testing using Playwright and Python - list4c/playwright-python-testing
Starred by 12 users
Forked by 4 users
Languages   Python 100.0% | Python 100.0%
Discussions

[Feature] Parametrization API for Playwright Test
Discussed in https://github.com/microsoft/playwright/discussions/10283 Originally posted by andrejs-ps November 12, 2021 Currently, there is no API to parametrize individual tests. To pass in a sin... More on github.com
🌐 github.com
8
November 15, 2021
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] 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
Python + Playwright with async methods
I don't think there's any reason to run playwright async on python for UI testing, as it just leads to more complicated setups. It works great as is, but if you just want to try it out for a POC, look at the docs here: https://playwright.dev/python/docs/library#usage I personally don't see any great reason unless you have some odd use case or you're using a library like asyncio More on reddit.com
🌐 r/softwaretesting
15
5
January 17, 2024
🌐
Playwright
playwright.dev › parameterize tests
Parameterize tests | Playwright
You can either parameterize tests on a test level or on a project level.
🌐
GitHub
github.com › microsoft › playwright-python › blob › main › examples › todomvc › mvctests › test_persistence.py
playwright-python/examples/todomvc/mvctests/test_persistence.py at main · microsoft/playwright-python
page.goto("https://demo.playwright.dev/todomvc") # run the actual test · yield · # run any cleanup code · · · def test_should_persist_its_data(page: Page) -> None: for item in TODO_ITEMS[:2]: page.locator(".new-todo").fill(item) page.locator(".new-todo").press("Enter") ·
Author   microsoft
🌐
GitHub
github.com › AutomationPanda › playwright-python-tutorial
GitHub - AutomationPanda/playwright-python-tutorial: A tutorial for learning how to automate tests with Playwright in Python · GitHub
A tutorial for learning how to automate tests with Playwright in Python - AutomationPanda/playwright-python-tutorial
Starred by 395 users
Forked by 107 users
Languages   Python
🌐
GitHub
github.com › microsoft › playwright-pytest
GitHub - microsoft/playwright-pytest: Pytest plugin to write end-to-end browser tests with Playwright. · GitHub
Pytest plugin to write end-to-end browser tests with Playwright. - microsoft/playwright-pytest
Starred by 543 users
Forked by 85 users
Languages   Python
🌐
GitHub
github.com › microsoft › playwright-python
GitHub - microsoft/playwright-python: Python version of the Playwright testing and automation library. · GitHub
Python version of the Playwright testing and automation library. - microsoft/playwright-python
Starred by 14.6K users
Forked by 1.2K users
Languages   Python
🌐
GitHub
github.com › SayanCispl › Python_Playwright
GitHub - SayanCispl/Python_Playwright: A ready-to-use Playwright + pytest test automation project with Allure reporting, POM structure, Docker support, and a GitHub Actions CI workflow. Includes example tests for registration, login, and add-to-cart, a .env pattern for credentials and base URL, and all config files so you can paste into a new repository and run locally or in CI. · GitHub
A ready-to-use Playwright + pytest test automation project with Allure reporting, POM structure, Docker support, and a GitHub Actions CI workflow. Includes example tests for registration, login, and add-to-cart, a .env pattern for credentials and base URL, and all config files so you can paste into a new repository and run locally or in CI.
Author   SayanCispl
Find elsewhere
🌐
GitHub
github.com › nirtal85 › Playwright-Python-Example
GitHub - nirtal85/Playwright-Python-Example: Enterprise-Grade Playwright Python Architecture 🎭 | Production-Ready Boilerplate with Pytest, Allure.
This repository is a Production-Ready Reference Architecture for building next-generation test automation using Playwright and Python.
Starred by 135 users
Forked by 25 users
Languages   Python
🌐
GitHub
github.com › ThompsonJonM › python-playwright
GitHub - ThompsonJonM/python-playwright: A testing repository using Python 3.9, Pytest, and Playwright.
A testing repository using Python 3.9, Pytest, and Playwright. - ThompsonJonM/python-playwright
Starred by 27 users
Forked by 9 users
Languages   Python 100.0% | Python 100.0%
🌐
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
🌐
GitHub
github.com › infopulse › Playwright-course-python
GitHub - infopulse/Playwright-course-python: The 2024 approach of web apps test automation using the Playwright framework.
The 2024 approach of web apps test automation using the Playwright framework. - infopulse/Playwright-course-python
Starred by 11 users
Forked by 4 users
Languages   Python 100.0% | Python 100.0%
🌐
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.

🌐
GitHub
github.com › cmoir › playwright_pytest_bdd_example
GitHub - cmoir/playwright_pytest_bdd_example · GitHub
Other examples Use "pytest tests/test_with_bdd.py" to run all the tests in the test_without_bdd module Use "pytest tests/without_bdd/test_without_bdd.py::test_select_numbers_link" to run the test_select_numbers_link test · https://playwright.dev/python/docs/intro ·
Starred by 32 users
Forked by 12 users
Languages   Python 91.9% | Gherkin 8.1%
🌐
GitHub
github.com › prashant1507 › behave-playwright
GitHub - prashant1507/behave-playwright: Python Test Framework with Behave, Playwright, and BehaveX · GitHub
Required only if PLaywright is ruuning on Selenium) password_for_sshpass = "passowrd" (this has no affect but can be useful if anyone want to start docker-compose where sudo is required) headless = true [/false] allow_tracing = true [/false] tags = (Provide specifi tag like tags = @QA-1) add_in_elk = false [/true] (if true then framework assuemes elastic search is running) - if add_in_elk is true the set elk_url = https://elk.com send_report_on_email = true [/false] - if send_report_on_email is true the provide below: - token = (Check Notes -> 'Create Gmail Key Password' to generate Token) - s
Author   prashant1507
🌐
GitHub
github.com › savvagen › playwright-pytest-example
GitHub - savvagen/playwright-pytest-example: Example of e2e web tests ptoject using Python, Playwright and Pytest with Allure reporting and attaching video files to allure report
Example of e2e web tests ptoject using Python, Playwright and Pytest with Allure reporting and attaching video files to allure report - savvagen/playwright-pytest-example
Starred by 65 users
Forked by 22 users
Languages   Python 100.0% | Python 100.0%
🌐
GitHub
github.com › JoanEsquivel › playwright-python-test-framework
GitHub - JoanEsquivel/playwright-python-test-framework: Repository to track playwright tests
Repository to track playwright tests. Contribute to JoanEsquivel/playwright-python-test-framework development by creating an account on GitHub.
Starred by 9 users
Forked by 8 users
Languages   Python 100.0% | Python 100.0%
🌐
GitHub
github.com › microsoft › playwright › issues › 22295
[Feature] Simple and elegant data driven parameterized tests · Issue #22295 · microsoft/playwright
April 9, 2023 - test.each` a | b | expected ${1} | ${1} | ${2} ${1} | ${2} | ${3} ${2} | ${1} | ${3} `('returns $expected when $a is added to $b', ({a, b, expected}) => { expect(a + b).toBe(expected); });
Author   NikkTod
🌐
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 duplication. ... AJAX (11) android (163) API (2) Automation (7) batch file (1) C (16) Chrome (2) CSS ...