TestStep
表示 TestResult 中的一个步骤。
🌐 Represents a step in a TestResult.
方法
🌐 Methods
titlePath
Added in: v1.10返回从根步骤到此步骤的步骤标题列表。
🌐 Returns a list of step titles from the root step down to this step.
用法
testStep.titlePath();
返回
属性
🌐 Properties
annotations
Added in: v1.51适用于当前测试步骤的注释列表。
🌐 The list of annotations applicable to the current test step.
用法
testStep.annotations
类型
- [数组]<[对象]>
attachments
Added in: v1.50在步骤执行中通过 testInfo.attach() 附加的文件或缓冲区列表。
🌐 The list of files or buffers attached in the step execution through testInfo.attach().
用法
testStep.attachments
类型
- [数组]<[对象]>
category
Added in: v1.10步骤类别用于区分来源和详细程度不同的步骤。内置类别有:
🌐 Step category to differentiate steps with different origin and verbosity. Built-in categories are:
expect用于期望调用fixture用于夹具的设置和拆卸hook用于钩子的初始化和拆卸pw:api用于 Playwright API 调用。test.step用于 test.step API 调用。test.attach用于 testInfo.attach API 调用。
用法
testStep.category
类型
duration
Added in: v1.10运行时间以毫秒为单位。
🌐 Running time in milliseconds.
用法
testStep.duration
类型
error
Added in: v1.10步骤执行期间抛出的错误(如果有)。
🌐 Error thrown during the step execution, if any.
用法
testStep.error
类型
location
Added in: v1.10源中定义步骤的可选位置。
🌐 Optional location in the source where the step is defined.
用法
testStep.location
类型
params
Added in: v1.63步骤相关的参数(如果有的话)。例如,通过 Playwright API 调用生成的步骤包含目标 locator 和调用参数,例如 url,而 test.step() 的步骤则包含测试作者传入的参数。
🌐 Step-dependent parameters, when available. For example, steps produced by the Playwright API calls contain the target locator and the call arguments such as url, while test.step() steps contain the parameters passed by the test author.
// { locator: 'getByRole(\'button\')' }
await page.getByRole('button').click();
// { url: 'https://example.com' }
await page.goto('https://example.com');
// { locator: 'getByLabel(\'Password\')', value: 'secret' }
await page.getByLabel('Password').fill('secret');
// { orderId: 42 }
await test.step('checkout', async () => {
// ...
}, { params: { orderId: 42 } });
为了保持报告简洁,Playwright API 调用每次只报告一组精选的参数,长字符串值会被截断。无限制的参数,比如页面内容、评估的表达式或请求体,从不被报告。
🌐 To keep the reports small, Playwright API calls only report a curated set of arguments per call, and long string values are truncated. Unbounded arguments such as the page content, evaluated expressions or request bodies are never reported.
用法
testStep.params
类型
- [对象]<[字符串], [对象]>
parent
Added in: v1.10父步骤(如果有)。
🌐 Parent step, if any.
用法
testStep.parent
类型
startTime
Added in: v1.10此特定测试步骤的开始时间。
🌐 Start time of this particular test step.
用法
testStep.startTime
类型
steps
Added in: v1.10此步骤内的步骤列表。
🌐 List of steps inside this step.
用法
testStep.steps
类型
- [数组]<[测试步骤]>
subtitle
Added in: v1.63用户友好的测试步骤副标题,用来补充标题(如果有的话)。对于 Playwright API 调用,它是目标定位器或导航 URL。例如,一个 Click 步骤会把点击的定位器作为副标题。用户界面通常会把副标题显示在标题旁边或单独一行上。
🌐 User-friendly test step subtitle that complements the title, when available. For Playwright API calls, it is the target locator or the navigation url. For example, a Click step has the clicked locator as a subtitle. User interfaces typically render the subtitle next to the title or on a separate line.
// title `Click`, subtitle `getByRole('button')`
await page.getByRole('button').click();
// title `Navigate`, subtitle `example.com/index.html`
await page.goto('https://example.com/index.html');
用法
testStep.subtitle
类型
title
Added in: v1.10用户友好的测试步骤标题,例如 Click 或 Navigate。
🌐 User-friendly test step title, for example Click or Navigate.
用法
testStep.title
类型