0

I'm trying to execute a test multiple times using a for loop. Playwright Testrunner is not identifying the test inside for loop. it is giving message "no tests found".

Sample code.

test.describe("Feature: Execute script ", async () => {

test.beforeEach(({ page }) => {
    landingpage = new Landingpage(page);
});

const dm = 2;
for (let i = 1; i <= dm; i++) {
   
    test(`Execute script multiple times`, async () => {
        //test steps
        console.log(i)
    });
}; });
Prasad
  • 119
  • 1
  • 5
  • 13

2 Answers2

2

First of all, make sure that your tests are found without a loop. Then you have to rename the test's title to make it unique.

  const dm = 2;

  for (let i = 1; i <= dm; i++) {

    // Add unique identifier        ↓
    test(`Execute script multiple ${i} times`, async () => {
      //test steps
      console.log(i)
    });
  };
Yevhen Laichenkov
  • 7,746
  • 2
  • 27
  • 33
-1

The suggested solution does not work, rather below solution will work

results.forEach(async function (result) {
    await page.getByRole('button', { name: 'New ' }).click();
    await ....
    await ....
 
}
John
  • 19
  • 5