docs(test-parameterize): improve forEach example
This commit is contained in:
parent
6fb214de23
commit
2a671e036f
|
|
@ -9,15 +9,21 @@ You can either parameterize tests on a test level or on a project level.
|
||||||
## Parameterized Tests
|
## Parameterized Tests
|
||||||
|
|
||||||
```js title="example.spec.ts"
|
```js title="example.spec.ts"
|
||||||
const people = ['Alice', 'Bob'];
|
[
|
||||||
for (const name of people) {
|
{ name: 'Alice', expected: 'Hello, Alice!' },
|
||||||
test(`testing with ${name}`, async () => {
|
{ name: 'Bob', expected: 'Hello, Bob!' },
|
||||||
// ...
|
{ name: 'Charlie', expected: 'Hello, Charlie!' },
|
||||||
});
|
].forEach(({ name, expected }) => {
|
||||||
// You can also do it with test.describe() or with multiple tests as long the test name is unique.
|
// You can also do it with test.describe() or with multiple tests as long the test name is unique.
|
||||||
}
|
test(`testing with ${name}`, async ({ page }) => {
|
||||||
|
await page.goto(`/greet?name=${name}`);
|
||||||
|
await expect(page.getByRole('heading', { name })).toBeVisible();
|
||||||
|
})
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
When looping over `before{Each,All}` or `after{Each,All}` hooks, they will be executed for every iteration, so in most cases, you should loop only over tests.
|
||||||
|
|
||||||
## Parameterized Projects
|
## Parameterized Projects
|
||||||
|
|
||||||
Playwright Test supports running multiple test projects at the same time. In the following example, we'll run two projects with different options.
|
Playwright Test supports running multiple test projects at the same time. In the following example, we'll run two projects with different options.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue