playwright document has parameterize sample like this. It works
const people = ['Alice', 'Bob'];
for (const name of people) {
test(`testing with ${name}`, async () => {
// ...
});
// You can also do it with test.describe() or with multiple tests as long the test name is unique.
}
however, I want to get data array before each test,and generate test loop
//data like data[] = [{name:'Alice',age:'20'},..]
let data: any[] = [];
test.beforeEach(async ({ request }) => {
data = await getData(request);
});
for (let i = 0; i < data.length; i++) {
test(`testing with ${name}`, async (page) => {
// ...
});
}
In visual studio code,It shows Error : No Test found
But it works when I assign a exact value let data: any[] =[{name:’Alice’,age:’20’}];
I test similar case
https://github.com/microsoft/playwright/issues/9916
How do I properly run individual Playwright tests from a dynamic array of built urls?
2
Answers
I have a bad solution which is define length of Array
Then This tests can be determined by VScode
}
That’s because you are using beforeEach hook and most probably
getData
method is assigning undefined value todata
ordata
length is zero.I recommend you debugging what’s being assigned to
data
in beforeEach hook.One more important thing: beforEach hook run once before EACH test. In your case,
data
;data
is empty, test run stops and process exits with error:No Test found
.Solution: Use
test.beforeAll