Skip to main content

TestCase

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

¥TestCase corresponds to every test() call in a test file. When a single test() is running in multiple projects or repeated multiple times, it will have multiple TestCase objects in corresponding projects' suites.


方法

¥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.

用法

¥Usage

testCase.ok();

返回

¥Returns


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'

    ¥Test that is expected to fail and actually fails is 'expected'.

  • 第二次重试通过的测试是 'flaky'

    ¥Test that passes on a second retry is 'flaky'.

用法

¥Usage

testCase.outcome();

返回

¥Returns

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

titlePath

Added in: v1.10 testCase.titlePath

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

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

用法

¥Usage

testCase.titlePath();

返回

¥Returns


属性

¥Properties

annotations

Added in: v1.10 testCase.annotations

适用于当前测试的注释列表。包括:

¥The list of annotations applicable to the current test. Includes:

注释在测试执行期间通过 testInfo.annotations 可用。

¥Annotations are available during test execution through testInfo.annotations.

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

¥Learn more about test annotations.

用法

¥Usage

testCase.annotations

类型

¥Type

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

¥Annotation type, for example 'skip' or 'fail'.

  • description string (optional)

可选描述。

¥Optional description.


expectedStatus

Added in: v1.10 testCase.expectedStatus

预期测试状态。

¥Expected test status.

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

¥See also testResult.status for the actual status.

用法

¥Usage

testCase.expectedStatus

类型

¥Type

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

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.

用法

¥Usage

testCase.id

类型

¥Type


location

Added in: v1.10 testCase.location

源中定义测试的位置。

¥Location in the source where the test is defined.

用法

¥Usage

testCase.location

类型

¥Type


parent

Added in: v1.10 testCase.parent

该测试用例所属的套件。

¥Suite this test case belongs to.

用法

¥Usage

testCase.parent

类型

¥Type


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.

用法

¥Usage

testCase.repeatEachIndex

类型

¥Type


results

Added in: v1.10 testCase.results

每次运行此测试的结果。

¥Results for each run of this test.

用法

¥Usage

testCase.results

类型

¥Type


retries

Added in: v1.10 testCase.retries

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

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

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

¥Learn more about test retries.

用法

¥Usage

testCase.retries

类型

¥Type


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.

用法

¥Usage

testCase.tags

类型

¥Type


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().

用法

¥Usage

testCase.timeout

类型

¥Type


title

Added in: v1.10 testCase.title

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

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

用法

¥Usage

testCase.title

类型

¥Type


type

Added in: v1.44 testCase.type

返回 "test"。用于检测 suite.entries() 中的测试用例。

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

用法

¥Usage

testCase.type

类型

¥Type

  • "test"