javascripttypescriptparameter-passingplaywright

Passing parameter using String interpolation to test case name


I have a test to be run on a set of pages. I am trying to run it as Parameterized test.

2 test cases cannot have same name so string interpolations used to give them a unique name as can be seen in the example. I am trying to achieve this with the code snippet below.

import { test, expect } from '@playwright/test';
[
  { name: 'Alice'},
  { name: 'Bob' },
  { name: 'Charlie' },
].forEach(({name}) => {
  test(`Publishing Error Message ${name}`, async ({ page }) => {
  // Set the timeout to 200 seconds
  test.setTimeout(200000);
 
});
});

Still, I am getting the error:

Error: duplicate test title "Publishing Error Message", first declared in example.spec.ts:9

Solution

  • There is nothing wrong with your code. You can restart typescript server or reload vscode window in case typescript is still throwing old errors.

    enter image description here