Playwright and Claude Code: AI-Powered Testing and Web Automation

Featured image for Playwright and Claude Code: AI-Powered Testing and Web Automation

Playwright is Microsoft’s browser automation framework — the modern standard for end-to-end testing, web scraping, and browser-based workflows. Claude Code writes Playwright tests and automation scripts fluently, turning natural language test descriptions into reliable, production-grade test suites.

This combination eliminates one of the most tedious parts of software development: writing and maintaining tests. Here’s how we use it at Markana Media for both client projects and our own operations.

Why Playwright and Claude Code Work So Well Together

Testing is one of Claude Code’s strongest use cases because tests have clear pass/fail criteria. Claude Code can write the test, run it, check if it passes, and iterate if it doesn’t — the full agentic loop in action.

Playwright specifically pairs well because:

  • Well-documented API: Playwright has excellent, consistent documentation that Claude Code’s training data includes. It generates idiomatic Playwright code, not hacky workarounds.
  • Auto-waiting: Playwright automatically waits for elements to be ready before interacting with them, which means Claude Code’s generated tests are reliable without explicit wait logic.
  • Cross-browser: Tests run on Chromium, Firefox, and WebKit with no code changes. Claude Code sets up the configuration correctly.
  • Built-in assertions: Playwright’s assertion library is rich and specific. Claude Code uses the right assertions for each scenario — toBeVisible(), toHaveText(), toHaveURL() — making tests clear and maintainable.

Writing Tests in Natural Language

The simplest way to generate Playwright tests is describing them conversationally:

“Write Playwright tests for our login page. Test: successful login with valid credentials, failed login with wrong password shows an error message, empty form submission shows validation errors, forgot password link navigates to the reset page, and login redirects to the dashboard.”

Claude Code reads your login page code, understands the selectors and form structure, and writes a complete test file with all five test cases. Each test uses proper page object patterns, descriptive test names, and specific assertions.

More complex example: “Write end-to-end tests for our checkout flow. Test the full path from adding an item to cart, entering shipping info, selecting payment method, applying a discount code, and completing the order. Verify the confirmation page shows the correct order summary.”

Claude Code handles multi-step flows naturally — navigating between pages, filling forms, clicking buttons, and asserting results at each step.

Test Suite Generation for Existing Projects

One of the highest-value workflows is generating a test suite for an existing project that has no tests. This is a common situation — a project launched quickly, tests were planned “later,” and later never came.

Ask Claude Code: “Analyze this project and generate a comprehensive Playwright test suite. Cover all pages, forms, navigation, authentication flows, and critical user journeys. Use page object patterns and organize tests by feature.”

Claude Code reads your codebase, identifies all routes and interactive elements, and generates a structured test suite. For a typical marketing site, this might produce 30-50 tests covering:

  • Page loading and rendering for every route
  • Navigation and menu interactions
  • Form submissions and validation
  • Responsive behavior at different viewport sizes
  • External link verification
  • SEO elements (meta tags, structured data, canonical URLs)
  • Performance thresholds (page load time, Largest Contentful Paint)

Going from zero tests to comprehensive coverage in a single Claude Code session is a massive quality improvement for any project.

Web Scraping and Data Collection

Playwright isn’t just for testing — it’s a powerful web automation tool. Combined with Claude Code, it handles complex scraping and data collection tasks:

Competitor monitoring: “Write a Playwright script that visits each competitor’s pricing page, extracts their plan names, prices, and feature lists, and saves the data as JSON. Handle pagination if their pricing has multiple tiers.” Claude Code writes the scraper with proper error handling, rate limiting, and data extraction.

Content auditing: “Crawl our website and check every page for: missing meta descriptions, broken images, pages without H1 tags, and external links that return 404. Generate a report sorted by severity.” This replaces expensive SEO crawling tools for basic audits.

SERP monitoring: “Search Google for our top 10 target keywords and record our ranking position, the top 3 competitors, and any featured snippets. Save the data with today’s date for trend tracking.” Automated rank tracking without a SaaS subscription.

Form testing across environments: “Submit our contact form on staging, production, and the new redesign preview with test data. Verify the confirmation page, check that the email notification fires, and compare the behavior across all three environments.” Multi-environment validation in one script.

CI/CD Integration

Playwright tests generated by Claude Code integrate naturally into your CI/CD pipeline:

GitHub Actions: “Set up a GitHub Action that runs our Playwright tests on every pull request. Use parallel test execution across Chromium, Firefox, and WebKit. Upload test reports and failure screenshots as artifacts.”

Claude Code writes the workflow YAML, configures the Playwright container, sets up test sharding for speed, and handles artifact upload. Tests that fail block the PR merge, preventing regressions from reaching production.

Visual regression testing: “Add visual regression tests to our CI pipeline. Take screenshots of every page, compare them against baseline images, and flag any visual differences above a 1% threshold.” Playwright’s screenshot comparison combined with image diffing catches CSS regressions that functional tests miss.

Post-deployment smoke tests: “After each deployment, run a smoke test suite that verifies the homepage loads, the contact form submits, the blog loads posts, and the service pages render correctly. Alert us on Slack if anything fails.” Automated post-deploy verification prevents embarrassing production issues.

Maintaining Tests Over Time

The biggest challenge with test suites isn’t writing them — it’s maintaining them as the application evolves. Claude Code helps here too:

“Our checkout flow changed — the discount code field moved to the cart page instead of the payment page. Update all affected tests.” Claude Code reads the test suite, identifies which tests reference the discount code field, and updates them to match the new flow.

“We’re getting flaky tests in the search functionality tests. Diagnose why they fail intermittently and fix them.” Claude Code analyzes the test code, identifies timing issues or race conditions, and implements proper waits or retry logic.

“We added 5 new pages to the site this week. Generate tests for them following the same patterns as our existing tests.” Claude Code reads the existing test conventions and creates consistent new tests.

Start Testing Today

If your project has zero tests, getting started is simple: open your project in Claude Code and say “set up Playwright and write tests for the critical user flows.” In 30 minutes, you’ll have a functional test suite that catches regressions and gives you confidence when shipping changes.

For teams that need comprehensive test coverage, automated QA pipelines, or web automation solutions, our website and development team builds these systems as part of our project delivery. Every site we launch includes automated testing from day one. Let’s discuss your testing needs.