Natural Language Control
Prompt: “Test checkout flow with visual regression detection”
Result: Complete user journey with screenshot comparison
Ta treść nie jest jeszcze dostępna w Twoim języku.
PRD: Intelligent E2E Testing System
Requirements: Create comprehensive end-to-end tests that simulate real user journeys, adapt to UI changes, and provide 99.5%+ reliability across browsers and devices using AI-powered automation.
Plan: Leverage Playwright MCP for direct browser control, combined with Cursor IDE and Claude Code for natural language test creation and maintenance.
Todo:
E2E testing evolves from scripted interactions to intelligent user simulation. AI understands user intent, generates realistic test scenarios, and maintains tests as your application changes.
Natural Language Control
Prompt: “Test checkout flow with visual regression detection”
Result: Complete user journey with screenshot comparison
Smart Element Detection
AI finds elements using multiple strategies: data attributes, ARIA labels, semantic HTML
Visual Intelligence
Automatically detects layout shifts, color changes, and broken UI components
Cross-Platform Testing
Single prompt generates tests for desktop, tablet, and mobile viewports
Scenario: Testing a complete purchase flow from product browsing to order confirmation with multiple user personas.
# PRD: E-commerce Checkout End-to-End Testing# Requirements: Test complete purchase flow across different user types and devices
"Using Playwright MCP, create comprehensive checkout tests:
User Personas:1. Guest user (mobile, slow connection)2. Registered user (desktop, fast connection)3. Premium member (tablet, medium connection)
Test Flow for Each Persona:1. Navigate to product catalog2. Search and filter products3. Add multiple items to cart4. Apply discount codes5. Proceed to checkout6. Fill shipping information7. Select payment method8. Complete purchase9. Verify order confirmation
Validations Required:- Visual regression at each step- Performance metrics (< 3s page loads)- Accessibility compliance (WCAG 2.1 AA)- Cross-browser compatibility- Mobile responsiveness- Error handling (payment failures, out of stock)- Analytics event tracking"
// AI generates comprehensive E2E test suiteimport { test, expect, devices } from '@playwright/test';import { UserPersona, ProductCatalog, CheckoutFlow } from './test-helpers';
// AI creates persona-based test configurationsconst personas = [ { name: 'guest_mobile', device: devices['iPhone 12'], connection: 'slow-3g', user: null }, { name: 'registered_desktop', device: devices['Desktop Chrome'], connection: 'fast', user: UserPersona.build('returning_customer') }, { name: 'premium_tablet', device: devices['iPad Pro'], connection: 'medium', user: UserPersona.build('premium_member') }];
personas.forEach(persona => { test.describe(`Checkout Flow - ${persona.name}`, () => { test.use({ ...persona.device });
test.beforeEach(async ({ page, context }) => { // AI sets up network conditions if (persona.connection === 'slow-3g') { await context.setNetworkConditions({ download: 500 * 1024, upload: 500 * 1024, latency: 2000 }); }
// Login if registered user if (persona.user) { await page.goto('/login'); await page.fill('[data-testid="email"]', persona.user.email); await page.fill('[data-testid="password"]', persona.user.password); await page.click('[data-testid="login-submit"]'); await page.waitForURL('/dashboard'); } });
test('complete purchase journey', async ({ page }) => { // Step 1: Navigate to catalog const startTime = Date.now(); await page.goto('/products'); await page.waitForLoadState('networkidle');
// AI adds performance assertions const catalogLoadTime = Date.now() - startTime; expect(catalogLoadTime).toBeLessThan(3000);
// Visual regression check await expect(page).toHaveScreenshot(`catalog-${persona.name}.png`);
// Step 2: Search and filter await page.fill('[data-testid="search-input"]', 'laptop'); await page.click('[data-testid="search-submit"]'); await page.waitForSelector('[data-testid="product-list"]');
// Apply filters await page.click('[data-testid="price-filter-500-1000"]'); await page.waitForTimeout(1000); // Allow filter to apply
// Step 3: Add products to cart const products = page.locator('[data-testid="product-card"]'); const productCount = await products.count();
// Add first two products for (let i = 0; i < Math.min(2, productCount); i++) { await products.nth(i).locator('[data-testid="add-to-cart"]').click();
// Wait for cart animation await page.waitForSelector('[data-testid="cart-counter"]');
// Verify cart count increased const cartCount = await page.textContent('[data-testid="cart-counter"]'); expect(parseInt(cartCount)).toBe(i + 1); }
// Step 4: Apply discount code await page.click('[data-testid="cart-icon"]'); await page.click('[data-testid="discount-toggle"]'); await page.fill('[data-testid="discount-input"]', 'SAVE10'); await page.click('[data-testid="apply-discount"]');
// Verify discount applied await expect(page.locator('[data-testid="discount-applied"]')) .toContainText('10% off');
// Step 5: Proceed to checkout await page.click('[data-testid="checkout-button"]'); await page.waitForURL('/checkout');
// Visual check of checkout page await expect(page).toHaveScreenshot(`checkout-${persona.name}.png`);
// Step 6: Fill shipping (if guest user) if (!persona.user) { await page.fill('[data-testid="shipping-email"]', 'guest@example.com'); await page.fill('[data-testid="shipping-name"]', 'John Doe'); await page.fill('[data-testid="shipping-address"]', '123 Main St'); await page.fill('[data-testid="shipping-city"]', 'San Francisco'); await page.fill('[data-testid="shipping-zip"]', '94105'); }
// Step 7: Select payment await page.click('[data-testid="payment-card"]'); await page.fill('[data-testid="card-number"]', '4242424242424242'); await page.fill('[data-testid="card-expiry"]', '12/25'); await page.fill('[data-testid="card-cvc"]', '123');
// Step 8: Complete purchase await page.click('[data-testid="place-order"]');
// Step 9: Verify order confirmation await page.waitForURL('/order-confirmation/*');
await expect(page.locator('[data-testid="order-success"]')) .toContainText('Order placed successfully');
// Verify order details await expect(page.locator('[data-testid="order-number"]')) .toBeVisible();
// Final visual check await expect(page).toHaveScreenshot(`confirmation-${persona.name}.png`);
// Accessibility validation await expect(page).toPassAccessibilityAudit(); }); });});
Scenario: Using natural language commands to control browsers directly without writing test code.
# PRD: Direct Browser Control via MCP# Plan: Use Playwright MCP for natural language browser automation
# First, install and connect to Playwright MCP"Install Playwright MCP server:npx -y @playwright/mcp@latest"
# Connect to MCP server"Connect to Playwright MCP server for direct browser control"
# Natural language browser automation"Using Playwright MCP:
1. Launch browser and navigate to https://example-shop.com2. Take screenshot of homepage3. Click on 'Products' in navigation4. Search for 'wireless headphones'5. Click on first product result6. Take screenshot of product page7. Click 'Add to Cart' button8. Navigate to cart page9. Verify product is in cart10. Take final screenshot
For each step, validate the page loaded correctly and elements are visible"
# MCP Response (AI executes each command):# ✓ Browser launched successfully# ✓ Navigated to https://example-shop.com# ✓ Screenshot saved: homepage.png# ✓ Clicked 'Products' navigation# ✓ Search completed for 'wireless headphones'# ✓ First product clicked# ✓ Screenshot saved: product-page.png# ✓ Added to cart successfully# ✓ Cart page loaded# ✓ Product verified in cart# ✓ Screenshot saved: cart-final.png
# PRD: Complex User Journey Testing# Requirements: Test multi-step workflows with error handling
"Using Playwright MCP, execute this complex test scenario:
Scenario: New user registration and first purchase
1. Navigate to registration page2. Fill out registration form: - Email: testuser@example.com - Password: SecurePass123! - Confirm password: SecurePass123! - Accept terms and conditions3. Submit registration4. Handle email verification (mock)5. Login with new credentials6. Browse product catalog7. Add 3 different items to cart8. Apply discount code 'WELCOME10'9. Proceed to checkout10. Fill shipping information11. Enter test payment details12. Complete purchase13. Verify order confirmation
Error Handling:- If any step fails, take screenshot- Retry failed actions up to 3 times- Log detailed error information- Continue with next test if critical failure
Validation:- Screenshot at each major step- Verify page titles and key elements- Check for JavaScript errors- Validate accessibility at checkout- Measure performance metrics"
# AI executes entire workflow with intelligent error handling# and provides detailed execution report
Scenario: Detecting visual changes across application updates with intelligent diff analysis.
// PRD: Visual Regression Testing System// Plan: Use Playwright MCP for screenshot management
// Use Playwright MCP for screenshots"Using Playwright MCP:1. Take full-page screenshots2. Compare with baseline images3. Identify visual differences4. Generate diff reports"
// AI-enhanced visual regression testingtest.describe('Visual Regression Suite', () => { // AI generates visual test scenarios const viewports = [ { width: 375, height: 667, name: 'mobile' }, { width: 768, height: 1024, name: 'tablet' }, { width: 1920, height: 1080, name: 'desktop' } ];
test('homepage visual consistency', async ({ page }) => { for (const viewport of viewports) { await page.setViewportSize(viewport); await page.goto('/');
// AI-powered visual comparison const screenshot = await page.screenshot({ fullPage: true, animations: 'disabled' });
// AI analyzes visual differences const analysis = await ai.compareVisual({ current: screenshot, baseline: `homepage-${viewport.name}.png`, threshold: 0.1, ignoreRegions: [ { selector: '.dynamic-content' }, { selector: '[data-testid="timestamp"]' } ] });
if (analysis.hasDifferences) { console.log('AI Analysis:', analysis.summary); // AI suggests whether differences are intentional expect(analysis.isIntentional).toBe(true); } } });});
Scenario: Creating tests that automatically adapt to UI changes and selector modifications.
// Self-healing locator strategiesclass SmartLocator { constructor(private page: Page) {}
async findElement(intent: string): Promise<Locator> { // Primary strategy: data-testid let element = this.page.locator(`[data-testid="${intent}"]`);
if (!(await element.count())) { // Fallback: semantic HTML element = this.page.getByRole('button', { name: new RegExp(intent, 'i') }); }
if (!(await element.count())) { // AI-powered fallback const selector = await this.ai.findElement({ intent, screenshot: await this.page.screenshot(), dom: await this.page.content() });
element = this.page.locator(selector); }
return element; }}
// Usage in teststest('self-healing login test', async ({ page }) => { const smart = new SmartLocator(page);
// These will adapt to UI changes await (await smart.findElement('email-input')).fill('user@example.com'); await (await smart.findElement('password-input')).fill('password123'); await (await smart.findElement('login-submit')).click();});
Scenario: Validating application behavior across different browsers, devices, and operating systems.
// AI-driven cross-browser testingconst browsers = ['chromium', 'firefox', 'webkit'];
browsers.forEach(browserName => { test.describe(`${browserName} tests`, () => { test.use({ browserName });
test('cross-browser compatibility', async ({ page }) => { await page.goto('/');
// AI detects browser-specific issues const issues = await ai.detectCompatibilityIssues({ browser: browserName, page: await page.screenshot(), metrics: await page.metrics() });
expect(issues).toHaveLength(0);
// Browser-specific adjustments if (browserName === 'webkit') { // AI knows Safari quirks await page.waitForTimeout(100); } }); });});
// Cypress with AI-powered commandsCypress.Commands.add('aiClick', (selector) => { // AI finds best way to click element cy.window().then(async (win) => { const element = await ai.findClickableElement({ selector, viewport: win.innerWidth, dom: win.document.body.innerHTML });
cy.get(element.selector) .scrollIntoView() .should('be.visible') .click({ force: element.needsForce }); });});
describe('Cross-browser E2E', () => { it('works across all browsers', () => { cy.visit('/');
// AI-powered interactions cy.aiClick('login'); cy.aiType('email', 'user@example.com'); cy.aiClick('submit');
// AI validates result cy.aiAssert('login successful'); });});
# PRD: Automated User Journey Testing# Requirements: Test realistic user paths through the application
# Plan:"Use Playwright MCP to:1. Analyze current page structure2. Identify interactive elements3. Generate realistic user paths4. Execute and validate journeys"
# Todo:# - [ ] Connect to Playwright MCP# - [ ] Map application navigation# - [ ] Generate persona-based journeys# - [ ] Execute journey tests# - [ ] Collect performance metrics
// AI creates realistic user journeysclass UserJourneyGenerator { async generateJourney(persona: UserPersona): Promise<TestJourney> { const journey = await ai.createJourney({ persona: { type: persona.type, // 'power-user', 'first-time', 'mobile' goals: persona.goals, constraints: persona.constraints }, application: { type: 'e-commerce', features: await this.analyzeFeatures() } });
return { name: journey.name, steps: journey.steps.map(step => ({ action: step.action, validation: step.expectedOutcome, alternatives: step.fallbackActions })) }; }}
// Test multiple user journeystest.describe('User Journey Tests', () => { const personas = [ { type: 'first-time', goals: ['browse', 'purchase'] }, { type: 'returning', goals: ['reorder', 'track'] }, { type: 'mobile', goals: ['quick-buy'] } ];
personas.forEach(persona => { test(`${persona.type} user journey`, async ({ page }) => { const generator = new UserJourneyGenerator(); const journey = await generator.generateJourney(persona);
for (const step of journey.steps) { // Execute step await page.evaluate(step.action);
// Validate outcome const result = await step.validation(page); expect(result.success).toBe(true);
// Capture metrics await captureStepMetrics(page, step.name); } }); });});
// Performance metrics during E2E teststest('checkout flow performance', async ({ page }) => { const metrics = new PerformanceCollector();
// Monitor throughout the journey page.on('load', () => metrics.capture('pageLoad')); page.on('domcontentloaded', () => metrics.capture('domReady'));
// Navigate and interact await page.goto('/products'); metrics.mark('products-loaded');
await page.click('[data-product-id="123"]'); metrics.mark('product-selected');
await page.click('button:has-text("Add to Cart")'); metrics.mark('added-to-cart');
// AI analyzes performance const analysis = await ai.analyzePerformance({ metrics: metrics.getAll(), budgets: { 'products-loaded': 2000, 'added-to-cart': 500 } });
expect(analysis.violations).toHaveLength(0);
// Generate performance report await generatePerformanceReport({ journey: 'checkout', metrics: analysis, suggestions: analysis.aiSuggestions });});
// Comprehensive accessibility testingtest.describe('Accessibility Compliance', () => { test('WCAG 2.1 AA compliance', async ({ page }) => { await page.goto('/');
// Run axe-core with AI enhancement const violations = await page.evaluate(async () => { const results = await window.axe.run();
// AI categorizes and prioritizes violations return ai.analyzeA11yViolations({ violations: results.violations, context: { pageType: 'landing', userFlow: 'initial-visit' } }); });
// AI suggests fixes for (const violation of violations) { console.log(` Issue: ${violation.description} Impact: ${violation.impact} AI Fix: ${violation.suggestedFix} Code: ${violation.codeSnippet} `); }
expect(violations.filter(v => v.impact === 'critical')).toHaveLength(0); });
test('keyboard navigation', async ({ page }) => { await page.goto('/');
// AI tests keyboard accessibility const keyboardTest = await ai.testKeyboardNavigation({ startElement: 'body', expectedFlow: ['nav', 'main', 'footer'], interactions: ['tab', 'enter', 'escape'] });
expect(keyboardTest.accessible).toBe(true); });});
// Mobile-specific E2E teststest.describe('Mobile Experience', () => { test.use({ viewport: { width: 375, height: 812 }, // iPhone X hasTouch: true, isMobile: true });
test('mobile checkout flow', async ({ page }) => { await page.goto('/');
// Test touch interactions await page.tap('[data-testid="menu-burger"]'); await expect(page.locator('.mobile-menu')).toBeVisible();
// Swipe to browse products await page.locator('.product-carousel').swipe('left');
// Test mobile-specific features await page.tap('text=Add to Cart');
// Verify mobile optimizations const mobileOptimizations = await ai.checkMobileOptimizations({ viewport: await page.viewportSize(), performance: await page.metrics(), interactions: ['tap', 'swipe', 'pinch'] });
expect(mobileOptimizations.score).toBeGreaterThan(90); });});
Playwright MCP for Browser Control
# Direct browser manipulation"Use Playwright MCP to navigate to /products""Take screenshot of current page""Click on the first product""Validate product details are visible"
Database MCP for Test Data
# Set up test data"Connect to PostgreSQL MCP and:1. Create test user accounts2. Add sample products3. Clear test data after runs"
GitHub MCP for Test Results
# Report test status"Use GitHub MCP to:1. Comment test results on PR2. Update commit status3. Link to test reports"
Test User Journeys
// Focus on complete user flowstest('end-to-end purchase', async ({ page }) => { await completePurchaseJourney(page, { product: 'laptop', payment: 'credit-card', shipping: 'express' });});
Use Page Objects
// Maintainable page object patternclass LoginPage { constructor(private page: Page) {}
async login(email: string, password: string) { await this.page.fill('#email', email); await this.page.fill('#password', password); await this.page.click('button[type="submit"]'); }}
Handle Async Operations
// Smart waiting strategiesawait page.waitForLoadState('networkidle');await page.waitForSelector('.content', { state: 'visible'});
Parallel Execution
// Run tests in paralleltest.describe.parallel('Product Tests', () => { test('product A', async ({ page }) => { /* ... */ }); test('product B', async ({ page }) => { /* ... */ });});
# PRD: Continuous E2E Testing Pipeline# Plan: Integrate E2E tests with CI/CD using GitHub Actions
"Using GitHub MCP (if available) or standard GitHub Actions:1. Set up test matrix for browsers2. Configure Playwright MCP in CI3. Run tests on PR and push4. Generate test reports"
# GitHub Actions E2E workflowname: E2E Tests
on: push: branches: [main] pull_request:
jobs: e2e-tests: runs-on: ubuntu-latest strategy: matrix: browser: [chromium, firefox, webkit]
steps: - uses: actions/checkout@v3
- name: Install Playwright run: npx playwright install --with-deps ${{ matrix.browser }}
- name: Run E2E Tests run: | npm run test:e2e -- \ --browser=${{ matrix.browser }} \ --reporter=html \ --retries=2 env: AI_API_KEY: ${{ secrets.AI_API_KEY }}
- name: Upload Reports if: always() uses: actions/upload-artifact@v3 with: name: playwright-report-${{ matrix.browser }} path: playwright-report/
- name: AI Test Analysis if: failure() run: | npm run analyze:test-failures -- \ --report=playwright-report \ --suggest-fixes