TestCase
TestCase
对应测试文件中每个test()调用。当单个test()在多个项目中运行或重复多次时,它将在对应项目的套件中包含多个TestCase
对象。
方法
好的
Added in: v1.10测试是否被认为运行正常。非正常状态的测试会导致测试运行以非零退出码失败。
用法
testCase.ok();
返回
结果
Added in: v1.10本测试的测试结果。请注意,结果与testResult.status不同:
- 预期会失败且实际失败的测试是
'expected'
。 - 测试在第二次重试时通过的情况属于
'flaky'
。
用法
testCase.outcome();
返回
- "skipped" | "expected" | "unexpected" | "flaky"#
titlePath
Added in: v1.10返回从根目录到当前测试的标题列表。
用法
testCase.titlePath();
返回
属性
注解
Added in: v1.10适用于当前测试的注解列表。包括:
- 通过test()和test.describe()在测试或套件上定义的注解;
- 由方法test.skip()、test.fixme()和test.fail()隐式添加的注释;
- 测试执行期间附加到testInfo.annotations的注解。
在测试执行期间,可以通过testInfo.annotations获取注解信息。
了解更多关于测试注解的信息。
用法
testCase.annotations
类型
expectedStatus
Added in: v1.10预期的测试状态。
- 标记为test.skip()或test.fixme()的测试预期会是
'skipped'
状态。 - 标记为test.fail()的测试预期会是
'failed'
状态。 - 其他测试预期结果为
'passed'
。
另请参阅testResult.status获取实际状态。
用法
testCase.expectedStatus
类型
- "passed" | "failed" | "timedOut" | "skipped" | "interrupted"
id
Added in: v1.25一个基于测试文件名、测试标题和项目名称计算得出的测试ID。该ID在Playwright会话中是唯一的。
用法
testCase.id
类型
位置
Added in: v1.10测试在源代码中定义的位置。
用法
testCase.location
类型
父级
Added in: v1.10该测试用例所属的测试套件。
用法
testCase.parent
类型
repeatEachIndex
Added in: v1.10当在"repeat each"模式下运行时,包含重复索引。此模式通过向命令行传递--repeat-each
来启用。
用法
testCase.repeatEachIndex
类型
结果
Added in: v1.10每次运行此测试的结果。
用法
testCase.results
类型
重试次数
Added in: v1.10配置中为此测试设置的最大重试次数。
了解更多关于测试重试的信息。
用法
testCase.retries
类型
标签
Added in: v1.42通过test()或test.describe()在测试或套件上定义的标签列表,以及从测试和套件标题中提取的@
标记。
了解更多关于test tags的信息。
用法
testCase.tags
类型
超时时间
Added in: v1.10赋予测试的超时时间。受testConfig.timeout、testProject.timeout、test.setTimeout()、test.slow()和testInfo.setTimeout()影响。
用法
testCase.timeout
类型
标题
Added in: v1.10作为传递给test()调用的测试标题。
用法
testCase.title
类型
类型
Added in: v1.44返回"test"。用于在suite.entries()中检测测试用例。
用法
testCase.type
类型
- "测试"