跳到主要内容

TestCase

TestCase 对应测试文件中每个 test() 调用。当单个 test() 在多个项目中运行或重复多次时,它将在相应项目的测试套件中包含多个 TestCase 对象。


方法

ok

Added in: v1.10 testCase.ok

判断测试是否被认为运行正常。非正常状态的测试会导致测试运行以非零退出码失败。

用法

testCase.ok();

返回值


outcome

Added in: v1.10 testCase.outcome

获取此测试的结果状态。注意:outcome 与 testResult.status 不同:

  • 预期会失败且实际失败的测试状态为 'expected'
  • 在第二次重试时通过的测试状态为 'flaky'

用法

testCase.outcome();

返回值

  • "skipped" | "expected" | "unexpected" | "flaky"#

titlePath

Added in: v1.10 testCase.titlePath

返回从根测试到当前测试的标题路径列表。

用法

testCase.titlePath();

返回值


属性

annotations

Added in: v1.10 testCase.annotations

最后一次测试运行的 testResult.annotations

用法

testCase.annotations

类型


expectedStatus

Added in: v1.10 testCase.expectedStatus

预期的测试状态。

实际状态请参见 testResult.status

用法

testCase.expectedStatus

类型

  • "passed" | "failed" | "timedOut" | "skipped" | "interrupted"

id

Added in: v1.25 testCase.id

基于测试文件名、测试标题和项目名称计算的测试ID。该ID在Playwright会话中是唯一的。

用法

testCase.id

类型


location

Added in: v1.10 testCase.location

测试在源代码中定义的位置。

用法

testCase.location

类型


parent

添加于: v1.10 testCase.parent

该测试用例所属的测试套件。

用法

testCase.parent

类型


repeatEachIndex

添加于: v1.10 testCase.repeatEachIndex

在"repeat each"模式下运行时包含的重复索引。此模式通过向命令行传递--repeat-each参数启用。

用法

testCase.repeatEachIndex

类型


results

添加于: v1.10 testCase.results

该测试每次运行的结果。

用法

testCase.results

类型


retries

添加于: v1.10 testCase.retries

配置中为该测试设置的最大重试次数。

了解更多关于测试重试的信息。

用法

testCase.retries

类型


tags

添加于: v1.42 testCase.tags

通过test()test.describe()在测试或套件上定义的标签列表,以及从测试和套件标题中提取的@标记。

了解更多关于测试标签的信息。

用法

testCase.tags

类型


timeout

Added in: v1.10 testCase.timeout

测试用例的超时时间。受以下配置影响:testConfig.timeouttestProject.timeouttest.setTimeout()test.slow()testInfo.setTimeout()

用法

testCase.timeout

类型


title

Added in: v1.10 testCase.title

传递给 test() 调用的测试标题。

用法

testCase.title

类型


type

Added in: v1.44 testCase.type

返回值为 "test"。可用于在 suite.entries() 中识别测试用例。

用法

testCase.type

类型

  • "test"