Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions api/browser/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,30 @@ declare module 'vitest/browser' {
如果自定义命令具有相同的名称,则它们将覆盖内置命令。
:::

<<<<<<< HEAD
### 自定义 `playwright` 命令 {#custom-playwright-commands}
=======
### Recording trace markers
Comment on lines +129 to +132
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Resolve leftover merge conflict markers

This file still contains Git conflict markers (<<<<<<<, =======, >>>>>>>), which means the merge was committed unresolved; Markdown tooling and site generation can surface these markers verbatim (or fail validation), and readers will see two competing section versions instead of one canonical document. Please resolve the conflict and keep only the intended content.

Useful? React with 👍 / 👎.


Custom commands can record [trace markers](/api/browser/context#mark) for the test that triggered them through `context.mark`. This is the server-side equivalent of `page.mark` and helps annotate the [trace view](/guide/browser/trace-view) with custom actions performed inside a command.

```ts
import type { BrowserCommand } from 'vitest/node'

export const uploadFixture: BrowserCommand<[name: string]> = async (
context,
name,
) => {
await context.mark(`upload start: ${name}`, { kind: 'action' })
// ... do server-side work
await context.mark(`upload done: ${name}`, { kind: 'action' })
}
```

`context.mark` is a no-op when browser tracing is not enabled or no test is currently running in the session. Unlike `page.mark`, it does not accept a callback form.

### Custom `playwright` commands
>>>>>>> 7df7a657dc941d7c21aac6ec9b42769a30a98ff0

Vitest 在命令上下文中公开了几个`playwright`特定属性。

Expand Down
2 changes: 2 additions & 0 deletions api/browser/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ await page.mark('submit flow', async () => {

::: tip
This method is useful only when [`browser.trace`](/config/browser/trace) is enabled.

A server-side equivalent is available on the [`BrowserCommandContext`](/api/browser/commands#recording-trace-markers) so [custom commands](/api/browser/commands#custom-commands) can record markers attributed to the test that triggered them.
:::

### frameLocator
Expand Down
2 changes: 1 addition & 1 deletion guide/browser/trace-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Trace entries are recorded automatically for:

Each entry captures the DOM state at that point, along with timing information, the selector, and the source location that triggered it.

Element highlighting is best-effort. Some provider-specific selectors, shadow DOM selectors, or elements that are not present in the captured snapshot may not be highlighted.
In Vitest UI, trace entries are streamed as the test runs, so you can inspect recorded steps before the test finishes. Long-running actions, `expect.element(...)` assertions, and callback `page.mark()` entries appear as in-progress steps first, then update with their final status and duration.

## Custom Trace Entries

Expand Down
Loading