Playwright has documentation about how to parametrize tests from using project/fixture options:
import { test as base } from '@playwright/test';
export type TestOptions = {
person: string;
};
export const test = base.extend<TestOptions>({
person: ['John', { option: true }],
});
test('test 1', async ({ page, person }) => {
await page.goto(`/index.html`);
await expect(page.locator('#node'))
.toContainText(person); // person is John
});
And also has examples of creating many tests from parameters:
const people = ['Alice', 'Bob']; // This can be read from a file for example
for (const name of people) {
test(`testing with ${name}`, async () => {
});
}
However, there is no mention about how to do both things, being able to read information from the parameters, for example, where is a file containing data located, and use that to create parametrized tests.
Here is some pseudo code of what I want that does not work:
test.describe('test 1', async ({ peopleFile }) => {
const people = fs.readFileSync(peopleFile);
for (const name of people) {
test(`testing with ${name}`, async () => {
});
}
});
Is there any way to do something like this?