> ## Documentation Index
> Fetch the complete documentation index at: https://e2e.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# HTML 报告

> 添加 e2e HTML 报告器，为每次运行生成包含所有测试的错误、步骤、截图和视频的单页报告，并在 CI 中共享。

HTML 报告是一个单页文件，展示整次运行的结果：按文件分组列出每个测试及其尝试记录、错误、步骤、截图和视频。无需启动服务器即可直接从磁盘打开，因此可以作为 CI 产物保存并在之后查看。

![e2e HTML 报告的运行页面：五个按文件分组的测试，三个通过、一个不稳定、一个失败。](https://e2e.com/docs/images/html-report/run.png)

## 添加报告器

安装 `@e2e-dev/html-reporter`：

<CodeGroup>
```bash npm
npm install --save-dev @e2e-dev/html-reporter
```

```bash pnpm
pnpm add -D @e2e-dev/html-reporter
```

```bash bun
bun add -d @e2e-dev/html-reporter
```
</CodeGroup>

将它添加到 `reporters` 中（与 `list` 并列），并为失败的测试开启视频录制，以便报告能够回放：

```ts title="e2e.config.ts"

export default {
  targets: [{ engine: web(), app: { url: 'http://localhost:3000' } }],
  reporters: ['list', htmlReporter()],
  video: 'retain-on-failure',
} satisfies E2EConfig;
```

即使未开启 `video`，或所用引擎不支持录制，报告仍会展示错误信息、步骤以及引擎在失败时截取的截图。其他录制模式请参阅 [`video`](https://e2e.com/docs/zh/reference/config#video)。

## 打开报告

测试运行生成报告后，e2e 会在其旁边写入 `.e2e/report.html`，并在摘要下方打印路径：

```text
      Tests  1 failed | 3 passed | 1 flaky (5)
HTML report  .e2e/report.html
```

直接在浏览器中打开该文件，或运行 `e2e report` 打开最近一次生成的报告：

<CodeGroup>
```bash npm
npx e2e report
```

```bash pnpm
pnpm exec e2e report
```

```bash bun
bunx e2e report
```
</CodeGroup>

运行页面按文件列出测试，最严重的状态排在最前。你可以使用状态标签页和搜索框缩小列表范围。搜索支持匹配测试标题、文件名和标签。在多个测试目标上运行时，还会按测试目标显示标签页。

## 查看失败的测试

选择一个测试即可打开其详情页。

![e2e HTML 报告中的失败测试：显示预期文本与实际文本，以及暂停在失败步骤上的视频。](https://e2e.com/docs/images/html-report/failed-test.png)

- **尝试记录（Attempts）**。经过重试的测试会为每次尝试提供独立标签页，因此不稳定测试仍会保留失败那次尝试的证据。
- **错误（Error）**。展示失败信息、预期结果与应用实际显示的内容。点击 **copy prompt** 可将其复制为适合编码智能体使用的提示词，其中包含步骤以及已生成的追踪页面、截图和视频路径。
- **视频（Video）**。每个步骤都链接到录像中对应的时刻。
- **步骤（Steps）**。展开任意步骤即可查看其对应的测试代码上下文。
- **失败现场（At failure）**。展示失败步骤发生时的截图和屏幕语义树。

默认情况下，失败或不稳定的测试还会生成一份包含相同证据的 Markdown [追踪页面](https://e2e.com/docs/zh/debugging#open-the-trace-page)，供智能体读取。

## 从 CI 共享报告

默认情况下，报告页面会链接 `.e2e/results/` 中的截图和视频。请将报告和该目录作为同一个产物上传，以保证链接有效：

```yaml title=".github/workflows/e2e.yml"
- name: Upload HTML report
  if: ${{ !cancelled() }}
  uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
  with:
    name: e2e-html-report
    path: |
      .e2e/report.html
      .e2e/results
    retention-days: 7
```

下载该产物并解压，然后打开 `report.html`。

<Warning>
视频不会做任何遮罩处理，因此输入的密码会明文显示在画面中。在分享产物或内嵌媒体资源的报告页面前，请先检查视频内容。详见[仍可能泄露的内容](https://e2e.com/docs/zh/security#what-can-still-leak)。
</Warning>

如果希望只分享单个文件，可设置 `htmlReporter({ media: 'embed' })`。此时截图和视频会直接内嵌到页面中，文件体积也会随录制数量增加而变大。由托管浏览器或设备服务保存的视频仍保持为链接。设置 `media: 'none'` 则不包含媒体文件，生成体积小巧的纯文本页面。完整选项列表请参阅 [`htmlReporter()`](https://e2e.com/docs/zh/reference/reporters#htmlreporter)。

## 下一步

<CardGroup cols={2}>
  <Card title="调试运行" icon="bug" href="/debugging">
    追踪页面、有头模式重跑以及单步调试测试。
  </Card>
  <Card title="GitHub Actions" icon="/images/integrations/github-actions.svg" href="/ci/github-actions">
    运行测试并上传结果的完整工作流配置。
  </Card>
</CardGroup>
