claude-code/claude-zh/commands/e2e.md

53 lines
1.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# /e2e — 自動化端對端測試 (E2E Testing)
使用 Playwright 或 Cypress 規劃並執行自動化瀏覽器測試。
## 使用方式
```bash
/e2e <測試情境描述>
```
## 功能說明
此指令會呼叫 **e2e-runner** agent位於 `agents/e2e-runner.md`
1. **環境檢查**:偵測安裝的是 Playwright 還是 Cypress。
2. **計畫**:定義測試步驟(導覽、互動、斷言)。
3. **實作**:撰寫測試程式碼並儲存。
4. **執行**:執行測試並擷取結果(包含錯誤截圖)。
5. **修復**:如果測試失敗,自動修復程式碼並重試。
## 使用範例
```bash
/e2e 測試使用者登入流程並驗證儀表板載入
/e2e 驗證購物車在重新整理後仍保持正確數量
/e2e 檢查所有導覽列連結是否導向正確頁面
```
## 支援的框架
| 框架 | 偵測指標 | 指令 |
|-----------|-----------|---------|
| **Playwright** | `playwright.config.ts` | `npx playwright test` |
| **Cypress** | `cypress.config.ts` | `npx cypress run` |
## 測試產生規範
- **Page Object Model (POM)**:若專案已在使用則遵循此模式。
- **Selectors**:優先使用 `data-testid` > `aria-label` > `placeholder` > `text`
- **抗脆弱性**包含顯式等待Explicit waits與正確的斷言。
- **清理**:測試完成後負責清理測試資料。
## 報告結果
會話結束時,您將收到:
-**通過**:測試成功完成的摘要。
-**失敗**:錯誤訊息、失敗行號以及(若可用)截圖路徑。
## 注意事項
- e2e 測試通常耗時較長。
- 確保相關的開發伺服器Dev Server已在背景執行。
- 針對新功能開發,建議先執行 `/plan`