跳到主要内容

TestResult

单个 TestCase 运行的结果。


属性

annotations

添加于: v1.52 testResult.annotations

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

注解在测试执行期间可通过 testInfo.annotations 获取。

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

用法

testResult.annotations

类型

  • Array<Object>
    • type string

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

    • description string (可选)

      可选的描述信息。


attachments

添加于: v1.10 testResult.attachments

在测试执行期间通过 testInfo.attachments 附加的文件或缓冲区列表。

用法

testResult.attachments

类型

  • Array<Object>
    • name string

      附件名称。

    • contentType string

      此附件的内容类型,用于在报告中正确展示,例如 'application/json''image/png'

    • path string (可选)

      附加文件在文件系统上的可选路径。

    • body Buffer (可选)

      可选的附件内容,用于替代文件。


duration

Added in: v1.10 testResult.duration

运行时间(毫秒)。

用法

testResult.duration

类型


error

Added in: v1.10 testResult.error

测试执行过程中抛出的第一个错误(如果有)。该值等于 testResult.errors 数组的第一个元素。

用法

testResult.error

类型


errors

Added in: v1.10 testResult.errors

测试执行过程中抛出的所有错误。

用法

testResult.errors

类型


parallelIndex

Added in: v1.30 testResult.parallelIndex

工作线程的索引值,范围在 0workers - 1 之间。可以保证同时运行的工作线程具有不同的 parallelIndex 值。

用法

testResult.parallelIndex

类型


retry

Added in: v1.10 testResult.retry

当测试进行多次重试时,每次重试尝试都会被赋予一个顺序编号。

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

用法

testResult.retry

类型


startTime

Added in: v1.10 testResult.startTime

本次特定测试运行的开始时间。

用法

testResult.startTime

类型


status

Added in: v1.10 testResult.status

测试结果的状态。另请参阅 testCase.expectedStatus

用法

testResult.status

类型

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

stderr

Added in: v1.10 testResult.stderr

测试运行期间写入标准错误输出的内容。

用法

testResult.stderr

类型


stdout

Added in: v1.10 testResult.stdout

测试运行期间写入标准输出的内容。

用法

testResult.stdout

类型


steps

Added in: v1.10 testResult.steps

本次测试运行中的步骤列表。

用法

testResult.steps

类型


workerIndex

Added in: v1.10 testResult.workerIndex

运行测试的工作线程索引。如果测试没有被运行过(例如用户中断了测试),唯一的结果将具有 workerIndex 等于 -1

了解更多关于 Playwright Test 的并行和分片功能。

用法

testResult.workerIndex

类型