如何通过剧作家中的命令按确切名称(等于)执行测试

问题描述 投票:0回答:1

我正在尝试按名称执行特定测试。

问题是,当我执行

npx playwright test -g "test"
grep (-g) 时,会执行标题中包含给定字符串(“test”)的所有测试。

我只需要执行名称等于“test”的测试 (我不想更改名称,也不想为此添加标签)

test("test", async ({}, testInfo) => console.log(`Name: ${testInfo.title}`));
test("test2", async ({}, testInfo) => console.log(`Name: ${testInfo.title}`));
test("3test", async ({}, testInfo) => console.log(`Name: ${testInfo.title}`));
javascript typescript playwright playwright-test
1个回答
0
投票

您提供给 /g 的字符串被视为带有 /gi 开关的正则表达式,因此您可以执行“t.st”之类的操作来匹配 test/tasty/tostada。我的第一个猜测是在字符串的开头使用 ^ ,但这对我来说没有结果。

事实证明它匹配的字符串是:

relative\path\to\yourtest.spec.js Name of your test

因此,在您的示例中,您可以使用

" test$"
获得名为“test”的测试。这将是最简洁的,但如果有另一个名为“我的测试”的测试,则会失败。如果您知道所有测试都以“.spec.js”或“.spec.ts”结尾,您可以这样做:

npx playwright test -g "\.spec\..s test$"

不太光滑,但很有效。

© www.soinside.com 2019 - 2024. All rights reserved.