Skip to main content

TestCase

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


方法

🌐 Methods

ok

Added in: v1.10 testCase.ok

无论测试是否认为运行正常。测试不通过时,测试运行会以非零退出代码失败。

🌐 Whether the test is considered running fine. Non-ok tests fail the test run with non-zero exit code.

用法

testCase.ok();

返回


outcome

Added in: v1.10 testCase.outcome

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

🌐 Testing outcome for this test. Note that outcome is not the same as testResult.status:

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

用法

testCase.outcome();

返回

  • "跳过" | "预期" | "意外" | "不稳定"#

titlePath

Added in: v1.10 testCase.titlePath

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

🌐 Returns a list of titles from the root down to this test.

用法

testCase.titlePath();

返回


属性

🌐 Properties

annotations

Added in: v1.10 testCase.annotations

testResult.annotations 上一次测试运行的注释。

用法

testCase.annotations

类型

  • [数组]<[对象]>
    • type string

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

    • description string (optional)

      可选描述。

    • location Location (optional)

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


expectedStatus

Added in: v1.10 testCase.expectedStatus

预期测试状态。

🌐 Expected test status.

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

🌐 See also testResult.status for the actual status.

用法

testCase.expectedStatus

类型

  • "通过" | "未通过" | "超时" | "跳过" | "中断"

id

Added in: v1.25 testCase.id

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

🌐 A test ID that is computed based on the test file name, test title and project name. The ID is unique within Playwright session.

用法

testCase.id

类型


location

Added in: v1.10 testCase.location

源中定义测试的位置。

🌐 Location in the source where the test is defined.

用法

testCase.location

类型


parent

Added in: v1.10 testCase.parent

该测试用例所属的套件。

🌐 Suite this test case belongs to.

用法

testCase.parent

类型


repeatEachIndex

Added in: v1.10 testCase.repeatEachIndex

在“重复每项”模式下运行时包含重复索引。通过向命令行传递 --repeat-each 可以启用此模式。

🌐 Contains the repeat index when running in "repeat each" mode. This mode is enabled by passing --repeat-each to the command line.

用法

testCase.repeatEachIndex

类型


results

Added in: v1.10 testCase.results

每次运行此测试的结果。

🌐 Results for each run of this test.

用法

testCase.results

类型

  • [数组]<[测试结果]>

retries

Added in: v1.10 testCase.retries

配置中为此测试指定的最大重试次数。

🌐 The maximum number of retries given to this test in the configuration.

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

🌐 Learn more about test retries.

用法

testCase.retries

类型


tags

Added in: v1.42 testCase.tags

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

🌐 The list of tags defined on the test or suite via test() or test.describe(), as well as @-tokens extracted from test and suite titles.

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

🌐 Learn more about test tags.

用法

testCase.tags

类型

  • [数组]<[字符串]>

timeout

Added in: v1.10 testCase.timeout

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

🌐 The timeout given to the test. Affected by testConfig.timeout, testProject.timeout, test.setTimeout(), test.slow() and testInfo.setTimeout().

用法

testCase.timeout

类型


title

Added in: v1.10 testCase.title

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

🌐 Test title as passed to the test() call.

用法

testCase.title

类型


type

Added in: v1.44 testCase.type

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

🌐 Returns "test". Useful for detecting test cases in suite.entries().

用法

testCase.type

类型

  • "test"