typescriptplaywrightplaywright-test

Playwright with Typescript, test inside a for loop is not identified by Test Runner


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)
        });
    };
});

Solution

  • 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)
        });
      };