v1.0.0 cosmicstack-labs
E2E Testing
Playwright and Cypress patterns, selectors, assertions, API mocking, visual testing, and CI/CD
View source0 downloads
e2etestingplaywrightcypressautomation
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/More in Testing & QA
View all →Testing & QAv1.0.0
Test Strategy
Test pyramid, risk-based testing, test planning, coverage metrics, and SDLC integration
testingstrategyqa
Testing & QAv1.0.0
Accessibility Testing
WCAG 2.1/2.2 audit, axe, Lighthouse, manual testing, screen reader testing, and remediation
accessibilitya11ytesting
Testing & QAv1.0.0
API Testing
REST and GraphQL testing, Postman/Insomnia patterns, contract testing, schema validation, and monitoring
apitestingrest