跳转到主要内容

TestCase

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


方法

ok

新增于: v1.10 testCase.ok

测试是否被认为是正常运行。非正常测试会以非零退出代码导致测试运行失败。

用法

testCase.ok();

返回


outcome

新增于: v1.10 testCase.outcome

此测试的测试结果。请注意,结果与 testResult.status 不同。

  • 预期失败但实际失败的测试为 'expected'
  • 第二次重试通过的测试为 'flaky'

用法

testCase.outcome();

返回

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

titlePath

新增于: v1.10 testCase.titlePath

返回从根目录到此测试的标题列表。

用法

testCase.titlePath();

返回


属性

annotations

新增于: v1.10 testCase.annotations

上次测试运行的 testResult.annotations

用法

testCase.annotations

类型

  • Array<Object>
    • type 字符串

      注释类型,例如 'skip''fail'

    • description 字符串 (可选)

      可选描述。

    • location 位置 (可选)

      注释在源代码中的可选位置。


expectedStatus

新增于: v1.10 testCase.expectedStatus

预期的测试状态。

另请参阅 testResult.status 以了解实际状态。

用法

testCase.expectedStatus

类型

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

id

新增于: v1.25 testCase.id

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

用法

testCase.id

类型


location

新增于: v1.10 testCase.location

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

用法

testCase.location

类型


parent

新增于: v1.10 testCase.parent

此测试用例所属的套件。

用法

testCase.parent

类型


repeatEachIndex

新增于: v1.10 testCase.repeatEachIndex

在“每次重复”模式下运行时包含重复索引。此模式通过向 命令行 传递 --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

新增于: v1.10 testCase.timeout

为此测试设置的超时时间。受 testConfig.timeouttestProject.timeouttest.setTimeout()test.slow()testInfo.setTimeout() 的影响。

用法

testCase.timeout

类型


title

新增于: v1.10 testCase.title

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

用法

testCase.title

类型


type

新增于:v1.44 testCase.type

返回“test”。对于在 suite.entries() 中检测测试用例很有用。

用法

testCase.type

类型

  • "test"