Agent Skills
› cosmicstack-labs/mercury-agent-skills
› e2e-testing
e2e-testing
GitHub提供Playwright和Cypress的E2E测试最佳实践,涵盖选择器策略、API模拟、视觉测试及CI/CD集成。指导根据语言支持和并行执行需求选择工具,并规范测试结构与断言方式。
Trigger Scenarios
需要编写端到端测试脚本
选择Playwright或Cypress框架
配置测试可视化对比
设置CI流水线中的E2E测试任务
Install
npx skills add cosmicstack-labs/mercury-agent-skills --skill e2e-testing -g -y
SKILL.md
Frontmatter
{
"name": "e2e-testing",
"metadata": {
"tags": [
"e2e",
"testing",
"playwright",
"cypress",
"automation"
],
"author": "cosmicstack-labs",
"version": "1.0.0",
"category": "testing-qa"
},
"description": "Playwright and Cypress patterns, selectors, assertions, API mocking, visual testing, and CI\/CD"
}
E2E Testing
End-to-end testing with Playwright and Cypress.
Tool Choice
| Factor | Playwright | Cypress |
|---|---|---|
| Language | JS/TS, Python, C#, Java | JS/TS only |
| Browser support | Chromium, Firefox, WebKit | Chromium, Firefox, WebKit |
| Iframe support | Native | Limited |
| Network mocking | Route API | intercept() |
| Parallel execution | Built-in | Dashboard required |
Playwright Patterns
Selector Strategy (Priority Order)
getByRole()— best for accessibilitygetByText()— for text contentgetByTestId()— for complex componentsgetByLabel()— for form fieldslocator(CSS)— last resort
Test Structure
test.describe('Checkout Flow', () => {
test('completes purchase with valid card', async ({ page }) => {
await page.goto('/products');
await page.getByText('Add to Cart').first().click();
await page.getByRole('button', { name: 'Checkout' }).click();
await page.getByLabel('Card Number').fill('4242424242424242');
await page.getByRole('button', { name: 'Pay' }).click();
await expect(page.getByText('Thank you')).toBeVisible();
});
});
Visual Testing
- Use
await expect(page).toHaveScreenshot() - Maintain baseline screenshots in version control
- Run visual tests on CI with 1% threshold
- Use percy.io or Chromatic for cloud-based visual review
CI Integration
# GitHub Actions
- name: E2E Tests
run: npx playwright test
- uses: actions/upload-artifact
if: failure()
with:
name: playwright-report
path: playwright-report/
Version History
- 38e2523 Current 2026-07-05 19:42


