[Feature] Parametrization API for Playwright Test
See original GitHub issueDiscussed in https://github.com/microsoft/playwright/discussions/10283
<div type='discussions-op-text'>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)
const people = ['Alice', 'Bob'];
for (const name in people) {
test(`testing with ${name}`, async () => {
// ...
});
}
For two parameters, one can iterate over keys and values of a map. This isn’t exactly a clean solution, but it gets harder for 3+ parameters
for (const [a, b, c] of [["a", 1, 2], ["b", 3, 4], ["c", 5, 6]]) {
test(`testing with ${a} ${b} ${c}`, async () => {
console.log(a, b, c);
});
}
I believe Playwright would benefit from a parametrization API, similar to Java’s TestNG or JUnit. Example from JUnit:
@ParameterizedTest
@CsvSource({"a,1", "b,2", "foo,3"})
Given that Playwright has:
test.use({ viewport: { width: 600, height: 900 } });
Playwright could have as below for a single test or a group of tests
test.parameters("a,1", "b,2", "foo,3"});
Issue Analytics
- State:
- Created 2 years ago
- Reactions:19
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Parametrize tests | Playwright
Parameterized Projects. Playwright Test supports running multiple test projects at the same time. In the following example, we'll run two projects with ...
Read more >Parameterize Tests and usage of Text locator in Playwright
So this is how we can easily parametrize our tests in playwright. We can simply use the text of the above link and...
Read more >Using Playwright for API testing - Reflect.run
A walkthrough on how to use Playwright to create standalone API tests as well as incorporate API calls into a larger end-to-end testing...
Read more >API testing with Playwright & odottaa | by Yevhen Laichenkov
In this article, I'm going to share a quick overview of how easy it can be to quickly set up your project to...
Read more >Advanced: configuration | Playwright - CukeTest
To set something up once before running all tests, use globalSetup option in the configuration file. Global setup file must export a single...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@xelact No workaround for now. I’d suggest a separate step before
npm run test
, something likenpm run generate-tests
.After this change #12018 in v1.19, it is no longer possible to dynamically create test cases based on some data written in the
globalSetup.ts
as the global setup runs after listing the test cases, is there any workaround?