最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Passing parameter using String interpolation to test case name - Stack Overflow

programmeradmin0浏览0评论

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

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
Share Improve this question asked Nov 20, 2024 at 9:26 NutsAndBoltsNutsAndBolts 4291 gold badge4 silver badges16 bronze badges 1
  • 2 your code is working for me – hardkoded Commented Nov 20, 2024 at 13:02
Add a comment  | 

1 Answer 1

Reset to default 1

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

发布评论

评论列表(0)

  1. 暂无评论