Playwright Visual Testing & Browser Automation
A comprehensive skill for browser automation and visual testing using Playwright MCP server integration. This skill enables rapid UI testing, visual regression detection, automated browser interactions, and cross-browser validation for modern web applications.
When to Use This Skill
Use this skill when:
- Testing web applications across multiple browsers (Chromium, Firefox, WebKit)
- Implementing visual regression testing for UI changes
- Automating user interactions for QA and testing
- Validating responsive designs across different viewports
- Taking screenshots for documentation or bug reports
- Testing form submissions and user workflows
- Verifying accessibility of web interfaces
- Debugging browser-specific issues
- Creating automated E2E test suites
- Validating web applications before deployment
- Testing PWAs and single-page applications
- Capturing visual states for design reviews
Core Concepts
Playwright Browser Automation Philosophy
Playwright provides reliable end-to-end testing for modern web apps:
- Auto-wait: Automatically waits for elements to be actionable before interacting
- Web-first assertions: Retry assertions until they pass or timeout
- Cross-browser: Test on Chromium, Firefox, and WebKit with single API
- Accessibility snapshots: Navigate pages using semantic structure, not visual rendering
- Visual testing: Compare screenshots to detect visual regressions
- Network control: Intercept and mock network requests
- Multi-context: Test multiple scenarios in isolated browser contexts
Key Playwright Entities
- Browser: The browser instance (Chromium, Firefox, WebKit)
- Page: A single page/tab in the browser
- Locator: Element selector using accessibility tree
- Snapshot: Accessibility tree representation of page state
- Screenshot: Visual capture of page or element
- Network Request: HTTP requests made by the page
- Console Messages: Browser console output
- Dialog: Browser prompts, alerts, confirms
Visual Testing Workflow
- Navigate to the target page
- Wait for page to stabilize (animations, loading)
- Capture accessibility snapshot for context
- Take screenshot of page or specific elements
- Compare against baseline (optional)
- Validate visual appearance and functionality
- Document results and issues
Browser Lifecycle Management
browser_navigate
Navigate to a URL in the current page.
Parameters:
Example:
Best Practices:
- Use full URLs including protocol (https://)
- Wait for navigation to complete before taking actions
- Handle redirects and page transitions
browser_navigate_back
Navigate back to the previous page in history.
Parameters: None
Example:
Use Cases:
- Testing navigation flows
- Verifying back button behavior
- Multi-step form navigation
browser_close
Close the current browser page.
Parameters: None
When to Use:
- Clean up after testing
- Free system resources
- Reset browser state
browser_resize
Resize the browser viewport.
Parameters:
Common Viewports:
Example:
Page Inspection & Snapshots
browser_snapshot
Capture accessibility snapshot of the current page.
Parameters: None
Returns:
- Accessibility tree with semantic structure
- Element references (ref) for interactions
- Text content and roles
- Interactive elements and states
Why Use Snapshots:
- Better than screenshots for automation
- Semantic understanding of page structure
- Element references for precise interactions
- Faster than visual parsing
- Works without visual rendering
Example Snapshot Structure:
browser_take_screenshot
Take a screenshot of the current page or element.
Parameters:
Screenshot Types:
- Viewport Screenshot (default):
- Full Page Screenshot:
- Element Screenshot:
Best Practices:
- Use descriptive filenames with context
- PNG for UI elements (lossless)
- JPEG for photos/images (smaller size)
- Full page for documentation
- Element screenshots for focused testing
Browser Interaction
browser_click
Perform click on an element.
Parameters:
Examples:
- Basic Click:
- Right Click:
- Click with Modifier:
- Double Click:
browser_type
Type text into an editable element.
Parameters:
Examples:
- Form Input:
- Search with Submit:
- Character-by-Character (triggers key handlers):
browser_press_key
Press a keyboard key.
Parameters:
Common Keys:
Examples:
Fill multiple form fields at once.
Parameters:
Example:
browser_select_option
Select option from dropdown.
Parameters:
Example:
Multi-select:
browser_hover
Hover over an element.
Parameters:
Use Cases:
- Trigger tooltips
- Show dropdown menus
- Test hover states
- Reveal hidden elements
Example:
browser_drag
Drag and drop between elements.
Parameters:
Example:
Use Cases:
- Drag-and-drop interfaces
- Reordering lists
- File uploads
- Kanban boards
Advanced Interactions
browser_evaluate
Execute JavaScript in page context.
Parameters:
Examples:
- Page-level Script:
- Element-level Script:
Common Use Cases:
browser_file_upload
Upload files to file input.
Parameters:
Example:
Single File:
Cancel Upload:
Browser State & Debugging
browser_console_messages
Get console messages from the browser.
Parameters:
Returns:
- All console.log, console.error, console.warn messages
- Timestamps and message types
- JavaScript errors and stack traces
Examples:
- All Messages:
- Errors Only:
Use Cases:
- Debug JavaScript errors
- Monitor API failures
- Track console warnings
- Verify logging behavior
browser_network_requests
Get all network requests since page load.
Parameters: None
Returns:
- URL, method, status code
- Request/response headers
- Timing information
- Request/response bodies
Use Cases:
- Verify API calls
- Check resource loading
- Debug failed requests
- Monitor performance
- Validate analytics tracking
browser_handle_dialog
Respond to browser dialogs.
Parameters:
Dialog Types:
- alert: Information message
- confirm: Yes/No choice
- prompt: Text input request
- beforeunload: Page navigation warning
Examples:
- Accept Alert:
- Dismiss Confirm:
- Answer Prompt:
browser_wait_for
Wait for conditions before proceeding.
Parameters:
Examples:
- Wait for Text:
- Wait for Removal:
- Fixed Wait:
Best Practices:
- Prefer waiting for specific conditions over fixed time
- Use for dynamic content loading
- Wait for animations to complete
- Ensure page stability before screenshots
Tab Management
browser_tabs
Manage browser tabs.
Parameters:
Actions:
- List Tabs:
- New Tab:
- Close Tab:
- Switch Tab:
Use Cases:
- Multi-tab workflows
- Testing tab-specific features
- Opening links in new tabs
- Managing multiple sessions
Browser Installation
browser_install
Install the browser specified in config.
Parameters: None
When to Use:
- First-time setup
- "Browser not installed" errors
- Updating browser version
- CI/CD environment setup
Visual Testing Workflow Patterns
Pattern 1: Basic Visual Regression Test
Scenario: Verify homepage hasn't changed visually
Pattern 2: Responsive Design Testing
Scenario: Test layout across devices
Scenario: Test multi-step form submission
Pattern 4: Element-Specific Visual Testing
Scenario: Test individual component changes
Pattern 5: Cross-Browser Testing
Scenario: Verify consistency across browsers
Pattern 6: E2E User Journey Testing
Scenario: Complete user workflow validation
Pattern 7: Accessibility Snapshot Testing
Scenario: Verify semantic structure and accessibility
Browser Automation Best Practices
Screenshot Best Practices
- Consistent Naming Convention
- Filename Organization
- Full Page vs Viewport
- Use full page for documentation
- Use viewport for regression testing
- Element screenshots for components
- Consider page length for full-page captures
- Image Format Selection
- PNG: UI elements, text, sharp edges (lossless)
- JPEG: Photos, backgrounds, large images (smaller size)
- Use PNG by default for testing
Snapshot vs Screenshot Strategy
Use Snapshots When:
- Automating interactions
- Testing functionality
- Verifying structure
- Checking accessibility
- Need element references
- Testing dynamic content
Use Screenshots When:
- Visual regression testing
- Documentation
- Bug reports
- Design reviews
- Stakeholder presentations
- Visual comparisons
Use Both When:
- Comprehensive testing
- Debugging visual issues
- Creating test reports
- Documenting complex flows
Waiting Strategies
- Wait for Specific Elements
- Wait for Animations
- Wait for Network Idle
- Dynamic Content
Interaction Reliability
- Always Use Snapshots First
- Verify Element State
- Handle Dynamic Elements
- Error Recovery
- Batch vs Individual Entry
- Validation Testing
- Multi-Step Forms
Network Monitoring
- Track API Calls
- Performance Testing
- Debug Failed Requests
Development Acceleration Strategies
Strategy 1: Test Template Creation
Create reusable test patterns:
Strategy 2: Automated Screenshot Organization
Organize screenshots systematically:
Strategy 3: Parallel Multi-Browser Testing
Test across browsers efficiently:
Strategy 4: Visual Regression Automation
Automate visual comparison workflow:
Strategy 5: Component Library Testing
Test design system components:
Troubleshooting
Common Issues
Screenshot appears blank
- Wait for page to load: browser_wait_for
- Check if element is visible: browser_snapshot
- Ensure page has rendered: Add delay
- Verify URL is correct
Element not found for interaction
- Take fresh snapshot: browser_snapshot
- Check element ref is current
- Wait for element to appear: browser_wait_for
- Verify element exists in snapshot
Browser not launching
- Run browser_install
- Check MCP server configuration
- Verify browser binary path
- Check system permissions
Screenshot differs from expected
- Check viewport size: browser_resize
- Wait for animations: browser_wait_for
- Ensure font loading complete
- Disable dynamic content (timestamps, ads)
Form submission fails
- Verify all required fields filled
- Check validation errors: browser_snapshot
- Wait for submit button to be enabled
- Check console for JavaScript errors: browser_console_messages
Network requests not captured
- Call browser_network_requests after action
- Ensure page has completed requests
- Check for request failures
- Verify request timing
Dialog not handled
- Set up browser_handle_dialog before triggering
- Accept or dismiss appropriately
- Provide promptText for prompt dialogs
- Test dialog in advance
Debugging Workflow
- Capture Current State
- Isolate Issue
- Document Problem
Practical Examples
Example 1: Homepage Visual Regression
Test homepage hasn't visually changed:
Test login form functionality:
Example 3: Responsive Design Check
Test responsive layout:
Example 4: Component State Testing
Test button states:
Example 5: E2E Checkout Flow
Test complete checkout process:
Example 6: Accessibility Testing
Test keyboard navigation and structure:
Example 7: Network Debugging
Debug failed API calls:
Example 8: Dialog Handling
Test confirmation dialogs:
Example 9: Tab Management
Test multi-tab workflow:
Example 10: Animation Testing
Test loading animations:
Quick Reference
Essential Commands
Common Viewport Sizes
Test Organization Template
Resources
Skill Version: 1.0.0
Last Updated: October 2025
Skill Category: Browser Automation, Visual Testing, Quality Assurance
Compatible With: Playwright MCP Server, Chromium, Firefox, WebKit