Project 35: Chrome Browser Testing Automation
Project 35: Chrome Browser Testing Automation
Build an agent that uses Chrome browser integration to perform visual regression testing, accessibility audits, and end-to-end user flow testing with AI-powered assertions that understand page content semantically.
Quick Reference
| Attribute | Value |
|---|---|
| Difficulty | Advanced (Level 3) |
| Time Estimate | 1-2 weeks |
| Primary Language | TypeScript |
| Alternative Languages | Python, JavaScript |
| Prerequisites | Projects 1-5, 20 (Web Scraper with Browser MCP) |
| Key Topics | Browser automation, visual regression, accessibility auditing, AI-powered assertions |
| Kiro CLI Concepts | Chrome MCP, computer use, screenshot analysis, hooks |
| Main Book Reference | โWeb Application Testing with Puppeteerโ by Jay Huang |
1. Learning Objectives
By completing this project, you will:
- Master Chrome browser automation through MCP: Control browser sessions, navigate pages, and interact with elements programmatically
- Implement visual regression testing: Capture screenshots, compare against baselines, and detect visual changes
- Build accessibility auditing systems: Analyze pages for WCAG compliance using DOM analysis and AI interpretation
- Create AI-powered assertions: Use natural language to describe expected behaviors and let AI verify them
- Generate comprehensive test reports: Produce human-readable reports with screenshots, findings, and recommendations
2. Deep Theoretical Foundation
2.1 The Evolution of Browser Testing
Browser testing has evolved through several paradigms, each building on the previous:
BROWSER TESTING EVOLUTION
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โ GENERATION 1: Record and Playback โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โข Selenium IDE, record mouse clicks โ
โ โข Brittle - breaks with any UI change โ
โ โข No understanding of what's being tested โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ GENERATION 2: Programmatic Automation โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โข Selenium WebDriver, Puppeteer, Playwright โ
โ โข Code-based selectors (CSS, XPath) โ
โ โข Still requires explicit assertions โ
โ โข Maintenance burden with UI changes โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ GENERATION 3: Visual Testing โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โข Percy, Chromatic, Applitools โ
โ โข Screenshot comparison โ
โ โข Catches visual regressions โ
โ โข Can't verify behavior โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ GENERATION 4: AI-Powered Testing (THIS PROJECT) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โข Natural language test descriptions โ
โ โข Semantic understanding of pages โ
โ โข Self-healing selectors โ
โ โข Intelligent assertions โ
โ โ
โ Example: โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ "Verify the checkout button is prominently displayed โ โ
โ โ and enabled when items are in the cart" โ โ
โ โ โ โ
โ โ AI interprets: โ โ
โ โ โข Find checkout button (semantic search, not CSS selector) โ โ
โ โ โข Check visibility and prominence (size, color, position) โ โ
โ โ โข Verify enabled state (not disabled, clickable) โ โ
โ โ โข Check cart state (items present in cart indicator) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
2.2 Chrome DevTools Protocol (CDP)
The Chrome MCP uses CDP to control the browser. Understanding CDP is essential:
CHROME DEVTOOLS PROTOCOL ARCHITECTURE
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โ KIRO CLI CHROME MCP CHROME โ
โ โโโโโโโโ โโโโโโโโโโ โโโโโโ โ
โ โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โ
โ โ โ Commands โ โ CDP โ โ โ
โ โ Agent โ โโโโโโโโโโโโโถ โ MCP โ โโโโโโโโโโโโโถ โ Browser โ โ
โ โ โ โ Server โ โ โ โ
โ โ โ โโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโ โ โ โ
โ โ โ Results โ โ Events โ โ โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โ
โ โ
โ CDP DOMAINS (commonly used): โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ Page Domain โ
โ โโโ navigate(url) โ Load a page โ
โ โโโ captureScreenshot() โ Take screenshot โ
โ โโโ getFrameTree() โ Get frame structure โ
โ โ
โ DOM Domain โ
โ โโโ getDocument() โ Get DOM tree โ
โ โโโ querySelector() โ Find element โ
โ โโโ getBoxModel() โ Element dimensions โ
โ โ
โ Input Domain โ
โ โโโ dispatchMouseEvent() โ Mouse actions โ
โ โโโ dispatchKeyEvent() โ Keyboard input โ
โ โโโ setFiles() โ File upload โ
โ โ
โ Accessibility Domain โ
โ โโโ getFullAXTree() โ Accessibility tree โ
โ โโโ queryAXTree() โ Query by role/name โ
โ โ
โ Runtime Domain โ
โ โโโ evaluate() โ Execute JavaScript โ
โ โโโ callFunctionOn() โ Call function on object โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
2.3 Visual Regression Testing Patterns
Visual regression testing catches unintended visual changes:
VISUAL REGRESSION TESTING WORKFLOW
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โ BASELINE CAPTURE โ
โ โโโโโโโโโโโโโโโโ โ
โ โ
โ 1. Navigate to page โ
โ 2. Wait for stable state (no animations, loaded images) โ
โ 3. Capture screenshot โ
โ 4. Store as baseline with metadata โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Baseline: /products page โ โ
โ โ Captured: 2024-12-22T10:30:00Z โ โ
โ โ Viewport: 1920x1080 โ โ
โ โ File: baselines/products-desktop.png โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ COMPARISON โ
โ โโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โ โ Baseline โ โ Current โ โ Diff โ โ
โ โ โ โ โ โ โ โ
โ โ โโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโ โ โ
โ โ โ Header โ โ โ โ Header โ โ โ โ โโโโโโโโโ โ โ โ
โ โ โโโโโโโโโโโโโค โ vs โ โโโโโโโโโโโโโค โ = โ โโโโโโโโโโโโโค โ โ
โ โ โ Products โ โ โ โ Products โ โ โ โ โโโโโโโโ โ โ โ
โ โ โ [A] [B] โ โ โ โ [A] [B] [C]โ โ โ โ [C]โ โ โ
โ โ โโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโ โ โ
โ โ โ โ โ โ New element! โ โ
โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โ โ
โ Diff Algorithm: โ
โ โข Pixel-by-pixel comparison โ
โ โข Perceptual hashing for fuzzy matching โ
โ โข Ignore regions for dynamic content โ
โ โข Tolerance threshold for anti-aliasing โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ DECISION MATRIX โ
โ โโโโโโโโโโโโโโโ โ
โ โ
โ Diff Percentage Action Example โ
โ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ 0% PASS No changes โ
โ 0.1% - 1% REVIEW Minor shift, anti-aliasing โ
โ 1% - 5% WARNING Layout change, new element โ
โ > 5% FAIL Major redesign โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
2.4 Accessibility Auditing with WCAG
Web Content Accessibility Guidelines (WCAG) define standards for accessible web content:
WCAG COMPLIANCE LEVELS
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โ LEVEL A (Minimum) โ
โ โโโโโโโโโโโโโโโโโ โ
โ โ
โ Must-have accessibility features: โ
โ โข All images have alt text โ
โ โข Form inputs have labels โ
โ โข Links have descriptive text โ
โ โข Page has proper heading structure โ
โ โข Keyboard navigation works โ
โ โ
โ AI Check: โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ [A11y] Checking Level A compliance... โ โ
โ โ โโโ Images: 12 found, 2 missing alt text โ โ โ
โ โ โโโ Forms: 5 inputs, all labeled โ โ โ
โ โ โโโ Links: 23 found, 1 empty text โ โ โ
โ โ โโโ Headings: Proper h1โh2โh3 structure โ โ โ
โ โ โโโ Keyboard: All interactive elements focusable โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ LEVEL AA (Standard) โ
โ โโโโโโโโโโโโโโโโโโโ โ
โ โ
โ Enhanced accessibility: โ
โ โข Color contrast ratio โฅ 4.5:1 (normal text) โ
โ โข Color contrast ratio โฅ 3:1 (large text) โ
โ โข Text resizable to 200% without loss โ
โ โข Focus indicators visible โ
โ โข Error messages descriptive โ
โ โ
โ AI Check: โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ [A11y] Checking Level AA compliance... โ โ
โ โ โโโ Contrast: 3 elements below ratio โ โ โ
โ โ โ โโโ .button-secondary: 2.8:1 (needs 4.5:1) โ โ
โ โ โโโ Text resize: Layout intact at 200% โ โ โ
โ โ โโโ Focus: All elements have visible focus โ โ โ
โ โ โโโ Errors: 2 forms have generic error text โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ LEVEL AAA (Enhanced) โ
โ โโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ Highest accessibility: โ
โ โข Color contrast ratio โฅ 7:1 (normal text) โ
โ โข Sign language for video content โ
โ โข Extended audio descriptions โ
โ โข Reading level appropriate โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
2.5 AI-Powered Assertions
Traditional assertions are brittle. AI-powered assertions understand intent:
TRADITIONAL VS AI-POWERED ASSERTIONS
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โ TRADITIONAL ASSERTION โ
โ โโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ expect(page.locator('.btn-checkout')).toBeVisible() โ
โ expect(page.locator('.btn-checkout')).toBeEnabled() โ
โ expect(page.locator('.cart-count')).toHaveText('3') โ
โ โ
โ Problems: โ
โ โข Class name changes break tests โ
โ โข Doesn't verify visual prominence โ
โ โข Can't handle dynamic content โ
โ โข No semantic understanding โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ AI-POWERED ASSERTION โ
โ โโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ "The checkout button should be prominently displayed, โ
โ enabled, and the cart should show items are present" โ
โ โ
โ AI Analysis: โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ โ
โ โ 1. Find checkout button (semantic search) โ โ
โ โ โโโ Look for button with text containing "checkout" โ โ
โ โ โโโ Or button with aria-label related to checkout โ โ
โ โ โโโ Found: <button class="primary-action">Checkout</button> โ โ
โ โ โ โ
โ โ 2. Verify "prominently displayed" โ โ
โ โ โโโ Size: 200x50px (larger than average button) โ โ
โ โ โโโ Position: Above fold, right side (common CTA position) โ โ
โ โ โโโ Color: High contrast #FF6B00 on white โ โ
โ โ โโโ Result: PROMINENT โ โ โ
โ โ โ โ
โ โ 3. Verify "enabled" โ โ
โ โ โโโ Check: not [disabled] attribute โ โ
โ โ โโโ Check: aria-disabled !== "true" โ โ
โ โ โโโ Check: opacity > 0.5 โ โ
โ โ โโโ Result: ENABLED โ โ โ
โ โ โ โ
โ โ 4. Verify "cart shows items" โ โ
โ โ โโโ Find cart indicator (icon with number/badge) โ โ
โ โ โโโ Check badge shows number > 0 โ โ
โ โ โโโ Result: HAS ITEMS โ โ โ
โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ Benefits: โ
โ โข Self-healing (finds elements by intent, not selector) โ
โ โข Verifies visual aspects (prominence, visibility) โ
โ โข Understands semantic meaning โ
โ โข Natural language documentation โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
3. Complete Project Specification
3.1 What You Will Build
A Kiro CLI agent that:
- Controls Chrome browser sessions through MCP
- Executes user flows with natural language descriptions
- Performs visual regression testing with baseline comparison
- Runs accessibility audits against WCAG guidelines
- Uses AI to interpret pages and verify assertions
- Generates comprehensive HTML reports with screenshots
3.2 Functional Requirements
| Requirement | Description |
|---|---|
| Browser Control | Navigate, click, type, scroll through Chrome MCP |
| User Flow Testing | Execute multi-step test scenarios |
| Visual Regression | Compare screenshots against baselines |
| Accessibility Audit | Check WCAG A/AA compliance |
| AI Assertions | Verify expectations using natural language |
| Report Generation | Create HTML reports with findings |
| Baseline Management | Create, update, and manage visual baselines |
3.3 Non-Functional Requirements
- Reliability: Handle flaky tests with smart waits and retries
- Performance: Complete full test suite in reasonable time
- Maintainability: Natural language tests are self-documenting
- Portability: Tests work across different environments
4. Solution Architecture
4.1 System Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CHROME BROWSER TESTING AGENT โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ CLI INTERFACE โ โ
โ โ โ โ
โ โ kiro-cli chat โ โ
โ โ > "Test the checkout flow on staging.example.com" โ โ
โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ TEST ORCHESTRATOR โ โ
โ โ โ โ
โ โ โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ โ โ
โ โ โ Flow Parser โ โ Test Executor โ โ Result โ โ โ
โ โ โ โ โ โ โ Aggregator โ โ โ
โ โ โ โข Parse steps โ โ โข Run tests โ โ โ โ โ
โ โ โ โข Extract โ โ โข Capture โ โ โข Collect โ โ โ
โ โ โ assertions โ โ screenshots โ โ results โ โ โ
โ โ โ โข Build plan โ โ โข Verify โ โ โข Generate โ โ โ
โ โ โ โ โ assertions โ โ report โ โ โ
โ โ โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ โ โ
โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ TESTING COMPONENTS โ โ
โ โ โ โ
โ โ โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ โ โ
โ โ โ Visual Tester โ โ A11y Auditor โ โ AI Asserter โ โ โ
โ โ โ โ โ โ โ โ โ โ
โ โ โ โข Screenshot โ โ โข DOM analysis โ โ โข NL parsing โ โ โ
โ โ โ โข Baseline โ โ โข WCAG checks โ โ โข Screenshot โ โ โ
โ โ โ comparison โ โ โข AXE-core โ โ analysis โ โ โ
โ โ โ โข Diff report โ โ integration โ โ โข Semantic โ โ โ
โ โ โ โ โ โ โ verification โ โ โ
โ โ โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ โ โ
โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ CHROME MCP โ โ
โ โ โ โ
โ โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ โ
โ โ โ Navigation โ โ Interaction โ โ Analysis โ โ โ
โ โ โ โ โ โ โ โ โ โ
โ โ โ โข Navigate โ โ โข Click โ โ โข Screenshot โ โ โ
โ โ โ โข Wait โ โ โข Type โ โ โข DOM tree โ โ โ
โ โ โ โข Reload โ โ โข Scroll โ โ โข A11y tree โ โ โ
โ โ โ โ โ โข Select โ โ โข Evaluate โ โ โ
โ โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ โ
โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
4.2 Test Flow Data Structures
// Core types for browser testing
interface TestFlow {
name: string;
description: string;
baseUrl: string;
steps: TestStep[];
config: TestConfig;
}
interface TestStep {
id: string;
description: string; // Natural language description
action?: ActionSpec;
assertion?: AssertionSpec;
visual?: VisualSpec;
accessibility?: AccessibilitySpec;
}
interface ActionSpec {
type: 'navigate' | 'click' | 'type' | 'scroll' | 'wait' | 'select';
target?: string; // CSS selector, text, or natural language description
value?: string;
options?: {
timeout?: number;
waitFor?: 'visible' | 'hidden' | 'stable';
};
}
interface AssertionSpec {
type: 'ai' | 'element' | 'text' | 'url';
description: string; // Natural language for AI assertions
selector?: string;
expected?: string | RegExp;
}
interface VisualSpec {
type: 'full-page' | 'element' | 'viewport';
selector?: string;
baseline?: string;
threshold?: number; // 0-1, percentage of allowed difference
ignoreRegions?: { x: number; y: number; width: number; height: number }[];
}
interface AccessibilitySpec {
level: 'A' | 'AA' | 'AAA';
rules?: string[]; // Specific rules to check
exclude?: string[]; // Rules to skip
}
interface TestConfig {
viewport: { width: number; height: number };
timeout: number;
retries: number;
screenshotOnFailure: boolean;
recordVideo: boolean;
}
interface TestResult {
flow: string;
status: 'passed' | 'failed' | 'skipped';
duration: number;
steps: StepResult[];
screenshots: Screenshot[];
accessibility?: AccessibilityResult;
visual?: VisualResult;
}
interface StepResult {
step: TestStep;
status: 'passed' | 'failed' | 'skipped';
duration: number;
error?: string;
screenshot?: string;
aiAnalysis?: string;
}
interface VisualResult {
baseline: string;
current: string;
diff?: string;
diffPercentage: number;
status: 'match' | 'mismatch' | 'new-baseline';
}
interface AccessibilityResult {
level: 'A' | 'AA' | 'AAA';
score: number; // 0-100
issues: AccessibilityIssue[];
}
interface AccessibilityIssue {
rule: string;
impact: 'critical' | 'serious' | 'moderate' | 'minor';
element: string;
description: string;
fix: string;
}
5. Phased Implementation Guide
Phase 1: Browser Control Foundation (Days 1-3)
Goals:
- Establish Chrome MCP connection
- Implement basic navigation and interaction
- Capture screenshots
Tasks:
- Set up Chrome MCP integration
- Implement navigate, click, type actions
- Add screenshot capture
- Build wait/stability detection
- Create simple test runner
Milestone Checkpoint:
$ kiro-cli chat
> "Navigate to https://example.com and take a screenshot"
[Chrome MCP] Connecting to browser...
โ Chrome session established
โ Navigating to https://example.com
โ Page loaded (1.2s)
โ Screenshot captured: screenshot-20241222-103000.png
Hint 1: Use networkidle wait condition to ensure all resources are loaded before screenshots.
Phase 2: User Flow Testing (Days 4-6)
Goals:
- Parse natural language test descriptions
- Execute multi-step flows
- Report step-by-step results
Tasks:
- Create test flow parser
- Implement step execution engine
- Add error handling and retries
- Build result aggregation
- Create console progress output
Milestone Checkpoint:
> "Test the login flow:
1. Navigate to /login
2. Enter email 'test@example.com'
3. Enter password 'password123'
4. Click the login button
5. Verify redirect to dashboard"
[Test: Login Flow]
โโโ Step 1: Navigate to /login โ
โโโ Step 2: Enter email 'test@example.com' โ
โโโ Step 3: Enter password โ
โโโ Step 4: Click login button โ
โโโ Step 5: Verify redirect to dashboard โ
Flow completed: 5/5 steps passed (2.3s)
Hint 2: For finding elements, try multiple strategies in order: exact text, aria-label, placeholder, then CSS selector.
Phase 3: Visual Regression (Days 7-9)
Goals:
- Implement baseline management
- Build image comparison
- Generate visual diff reports
Tasks:
- Create baseline storage system
- Implement pixel-by-pixel comparison
- Add perceptual diff algorithm
- Build ignore region support
- Generate HTML diff reports
Milestone Checkpoint:
> "Run visual regression on /products page"
[Visual Test: /products]
โโโ Baseline: baselines/products-desktop.png
โโโ Current: current/products-desktop.png
โโโ Comparing...
โ
โ Diff: 3.2% (threshold: 1%)
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ Changes detected: โ
โ โ โข New element at (850, 320): "Sale" badge โ
โ โ โข Price changed: $29.99 โ $24.99 โ
โ โ โข Layout shift: Product grid moved 5px right โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโ Status: FAILED (above threshold)
Generated: reports/visual-diff-products.html
Hint 3: Use a tolerance of 0.1% for anti-aliasing differences, but flag anything above 1% for human review.
Phase 4: Accessibility Auditing (Days 10-11)
Goals:
- Implement WCAG checks
- Integrate with accessibility tree
- Generate compliance reports
Tasks:
- Build accessibility tree analyzer
- Implement WCAG rule checks
- Add contrast ratio calculation
- Create issue categorization
- Generate accessibility report
Milestone Checkpoint:
> "Run accessibility audit on /checkout"
[Accessibility Audit: /checkout]
โโโ Level: AA
โโโ Score: 87/100
โ
โโโ Issues Found: 6
โ โโโ CRITICAL (1)
โ โ โโโ Form input missing label: #card-number
โ โ
โ โโโ SERIOUS (2)
โ โ โโโ Contrast ratio 2.8:1 on .hint-text (needs 4.5:1)
โ โ โโโ Focus not visible on .link-terms
โ โ
โ โโโ MODERATE (2)
โ โ โโโ Missing heading structure (h1 โ h3, skipped h2)
โ โ โโโ Tab order not logical in address form
โ โ
โ โโโ MINOR (1)
โ โโโ Image without alt: decorative-border.png
โ
โโโ Report: reports/a11y-checkout.html
Phase 5: AI-Powered Assertions (Days 12-14)
Goals:
- Implement natural language assertion parsing
- Use AI to analyze screenshots
- Build semantic element finding
Tasks:
- Create assertion parser
- Implement screenshot analysis with AI
- Build semantic element finder
- Add confidence scoring
- Create detailed assertion reports
Milestone Checkpoint:
> "Verify the checkout button is prominent and enabled when cart has items"
[AI Assertion]
โโโ Analyzing page...
โ
โโโ Finding checkout button:
โ โโโ Found: <button>Proceed to Checkout</button> at (1050, 450)
โ
โโโ Checking prominence:
โ โโโ Size: 200x48px (large for context) โ
โ โโโ Position: Above fold, primary action area โ
โ โโโ Color: High contrast #FF6B00 on white โ
โ โโโ Result: PROMINENT โ
โ
โโโ Checking enabled state:
โ โโโ Disabled attribute: false โ
โ โโโ Aria-disabled: not set โ
โ โโโ Visual opacity: 100% โ
โ โโโ Result: ENABLED โ
โ
โโโ Checking cart state:
โ โโโ Cart icon found at (1150, 25)
โ โโโ Badge shows "3" items
โ โโโ Result: HAS ITEMS โ
โ
โโโ Assertion: PASSED โ
6. Testing Strategy
6.1 Testing the Test Framework
describe('VisualComparison', () => {
it('should detect no difference for identical images', async () => {
const baseline = await loadImage('test-fixtures/page-a.png');
const current = await loadImage('test-fixtures/page-a.png');
const result = await compareImages(baseline, current);
expect(result.diffPercentage).toBe(0);
expect(result.status).toBe('match');
});
it('should detect differences above threshold', async () => {
const baseline = await loadImage('test-fixtures/page-a.png');
const current = await loadImage('test-fixtures/page-b.png');
const result = await compareImages(baseline, current, { threshold: 0.01 });
expect(result.diffPercentage).toBeGreaterThan(0.01);
expect(result.status).toBe('mismatch');
});
it('should ignore specified regions', async () => {
const baseline = await loadImage('test-fixtures/with-date.png');
const current = await loadImage('test-fixtures/with-different-date.png');
const result = await compareImages(baseline, current, {
ignoreRegions: [{ x: 10, y: 10, width: 100, height: 20 }]
});
expect(result.status).toBe('match');
});
});
6.2 Accessibility Audit Tests
describe('AccessibilityAuditor', () => {
it('should detect missing alt text', async () => {
const html = `
<img src="photo.jpg">
<img src="icon.png" alt="">
<img src="logo.png" alt="Company Logo">
`;
const issues = await auditAccessibility(html, { level: 'A' });
expect(issues).toContainEqual(expect.objectContaining({
rule: 'img-alt',
impact: 'critical'
}));
expect(issues.filter(i => i.rule === 'img-alt')).toHaveLength(2);
});
it('should check contrast ratios', async () => {
const html = `
<p style="color: #777; background: #fff;">Low contrast text</p>
`;
const issues = await auditAccessibility(html, { level: 'AA' });
expect(issues).toContainEqual(expect.objectContaining({
rule: 'color-contrast',
impact: 'serious'
}));
});
});
7. Common Pitfalls and Debugging
7.1 Common Issues
| Pitfall | Symptom | Solution |
|---|---|---|
| Flaky tests | Random failures | Add smart waits, use stable selectors |
| Screenshot timing | Captures mid-animation | Wait for networkidle + animation complete |
| Element not found | Selector breaks | Use semantic finding (text, role, label) |
| Baseline drift | Too many false positives | Update baselines intentionally, use ignore regions |
| Slow tests | Suite takes too long | Parallelize, reuse browser sessions |
7.2 Debugging Strategies
1. Enable verbose logging:
> "Run tests with debug output"
[DEBUG] Navigating to /products
[DEBUG] Waiting for networkidle...
[DEBUG] Network idle after 1.2s
[DEBUG] Finding element: "Add to Cart button"
[DEBUG] Strategy 1 (text): Found 0 matches
[DEBUG] Strategy 2 (aria-label): Found 3 matches
[DEBUG] Strategy 3 (role=button): Found 1 match (best fit)
[DEBUG] Clicking element at (450, 320)
2. Capture failure screenshots:
[FAILED] Step 3: Click checkout button
Failure details:
โโโ Error: Element not interactable
โโโ Element: <button disabled>Checkout</button>
โโโ Reason: Button is disabled (cart is empty)
โโโ Screenshot: failures/checkout-step3.png
3. Interactive debugging:
> "Pause test and let me inspect the page"
[PAUSED] Test paused at step 3
Browser window is visible for inspection.
Type 'continue' to resume or 'abort' to stop.
8. Extensions and Challenges
8.1 Beginner Extensions
- Add support for mobile viewport testing
- Implement cookie consent handling
- Create reusable test snippets library
8.2 Intermediate Extensions
- Build cross-browser testing (Firefox, Safari)
- Add video recording of test runs
- Implement parallel test execution
8.3 Advanced Extensions
- Machine learning for flaky test detection
- Auto-generate tests from user session recordings
- Self-healing selector system
9. Real-World Connections
9.1 Industry Tools
| Tool | Similar Pattern | Company |
|---|---|---|
| Percy | Visual regression | BrowserStack |
| Applitools | Visual AI testing | Applitools |
| Playwright | Browser automation | Microsoft |
| Cypress | E2E testing | Cypress.io |
| Axe | Accessibility testing | Deque |
9.2 Professional Applications
- CI/CD Integration: Run visual and accessibility tests on every PR
- Design Systems: Ensure component consistency across updates
- Compliance: Maintain WCAG compliance for legal requirements
- Regression Prevention: Catch unintended changes before production
10. Self-Assessment Checklist
Understanding Verification
- I understand Chrome DevTools Protocol basics
- I can explain visual regression testing workflow
- I know WCAG A, AA, AAA levels
- I understand AI-powered vs traditional assertions
- I can describe baseline management strategies
Implementation Verification
- Browser control works (navigate, click, type)
- Multi-step test flows execute correctly
- Visual comparison detects differences
- Accessibility audit finds issues
- AI assertions interpret page content
Integration Verification
- Full test suite runs on a real website
- Reports are generated with useful information
- Baseline management works correctly
- Tests are stable (not flaky)
11. Completion Criteria
Minimum Viable Completion
- Control Chrome through MCP
- Execute basic user flows
- Capture and compare screenshots
- Run simple accessibility checks
- Generate text-based reports
Full Completion
- AI-powered semantic assertions
- Full visual regression with diffs
- Comprehensive accessibility auditing
- HTML reports with screenshots
- Baseline management system
Excellence (Going Above and Beyond)
- Cross-browser support
- Video recording
- Self-healing selectors
- Parallel execution
- CI/CD integration templates
This guide was expanded from LEARN_KIRO_CLI_MASTERY.md. For the complete learning path, see the README.