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