Playwrightdeveloper-tools

Playwright E2E Testing for AI SaaS | SpeedMVPs

End-to-end tests that cover your application's critical user flows are one of the most valuable quality safeguards you can have in a production AI product. Playwright is the leading browser automation framework for E2E testing, maintained by Microsoft, and it runs tests across Chromium, Firefox, and WebKit in a single test suite. SpeedMVPs integrates Playwright into AI SaaS products to cover the paths that users actually take: signing up, connecting to the AI feature, completing a key workflow, and managing their account. These tests run in CI on every pull request, catching regressions before they reach production. For UK regulated sector AI products, automated E2E test coverage is also part of the software quality evidence expected by NHS Digital DSPT and MHRA software as a medical device guidance: demonstrating that critical user flows are tested on every code change is a meaningful assurance control for regulated software. Playwright's accessibility testing integration with axe-core also provides automated WCAG 2.1 AA regression checks on key pages, which is relevant for NHS deployments where accessibility compliance is a procurement requirement. SpeedMVPs, based in Hemel Hempstead and delivering AI MVPs in 2-3 weeks at a GBP 8,000 fixed price, includes a Playwright test suite covering the core user journeys as a standard deliverable. Tests are configured to run in GitHub Actions CI on every pull request, LLM calls are mocked for determinism and speed, and the test suite documentation explains how to add new tests and interpret failures. Full ownership is transferred on delivery.

What Playwright Tests Cover in an AI Product

Playwright E2E tests operate at the browser level, simulating real user interactions. For an AI SaaS product, the test suite SpeedMVPs builds covers: the authentication flow (sign up, email verification if applicable, sign in, password reset), the core AI feature workflow (submitting a query or document, waiting for the AI response, verifying the response is displayed), the billing flow (selecting a plan, completing checkout, verifying plan tier is reflected in the application), and the account management flow (updating profile, managing subscription, signing out). These flows are the backbone of the product, and a regression in any of them causes immediate user impact. Playwright tests catch these regressions in CI before they reach real users.

Handling Async AI Responses in Tests

Testing AI features in Playwright requires handling the asynchronous nature of LLM responses. A test that submits a query and immediately checks for a response will fail because the LLM call takes seconds. Playwright's auto-waiting mechanism handles most async scenarios: waitForSelector waits for an element to appear, waitForResponse can wait for a specific API response to complete. SpeedMVPs designs AI feature tests to wait for the response container to appear and contain content rather than checking immediately after submission. For streaming responses, the test waits for the streaming indicator to disappear before asserting the response content. In CI, LLM calls can be mocked using Playwright's route interception to avoid actual API costs and ensure test determinism, with a small number of integration tests that call the real API to verify the integration.

Test Data and Environment Isolation

Playwright tests need a reliable test environment with known data. SpeedMVPs sets up a dedicated test environment (typically the CI database seeded with known test data) and uses Playwright's setup project feature to create a test user and authenticate before the tests run. The authenticated session is saved to a cookie file and reused across tests, so each test does not need to go through the login flow, which significantly reduces test run time. Database state is reset between test runs using a seed script, ensuring tests run against a known baseline. For billing tests, Stripe or Lemon Squeezy test mode is used so no real payments are processed.

Parallelisation and CI Integration

Playwright runs tests in parallel by default, distributing tests across multiple worker processes. For a test suite of 30-50 test cases, Playwright can typically complete in under 3 minutes with appropriate parallelisation. In GitHub Actions, SpeedMVPs uses the Playwright sharding feature to split tests across multiple CI runners, further reducing wall-clock time. The Playwright GitHub Actions integration provides inline test failure reports directly in the pull request check, showing screenshots and videos of failed tests without needing to download the CI artifacts. This makes diagnosing test failures fast for developers who are not familiar with the test infrastructure.

Accessibility Testing with Playwright

Playwright integrates with the axe-core accessibility testing library to check pages for accessibility violations automatically as part of the E2E test suite. SpeedMVPs adds an axe check to the key pages in the test suite (home, login, main product page, settings) so accessibility regressions are caught in CI alongside functional regressions. For AI products where inclusivity is important, such as tools intended for use across a range of user abilities or tools deployed in the NHS context where WCAG 2.1 AA compliance is often required, this automated accessibility testing provides a baseline check. It does not replace manual accessibility review but catches common issues like missing alt text, incorrect ARIA attributes, and keyboard navigation failures.

What SpeedMVPs Delivers

Playwright test suite delivered as part of an AI MVP build includes: Playwright configuration for Chromium, Firefox, and WebKit (or Chromium only for faster CI), test setup with authenticated user state, tests covering the core user journeys (authentication, core AI feature, billing, account management), CI integration in GitHub Actions with sharding for parallel execution, test data seeding scripts, mocked LLM responses for deterministic AI feature tests, and documentation covering how to run tests locally, how to add new tests, and how to debug failures. The test suite is version-controlled alongside the application code and full ownership is transferred on delivery.

Frequently Asked Questions

Does Playwright work with Next.js App Router?+

Yes. Playwright tests the running application, not the framework internals, so it works with any Next.js configuration including App Router, Pages Router, and server components. The tests interact with the browser as a user would, which is framework-agnostic. SpeedMVPs runs a local Next.js server in production mode for Playwright tests to catch issues that only appear in the built application.

Should we mock LLM API calls in Playwright tests?+

For most E2E tests, yes. Mocking LLM calls makes tests faster, deterministic, and free (no API costs). Playwright's route interception can intercept the LLM API call and return a pre-defined response, allowing the test to verify that the application displays the response correctly without depending on the LLM's actual output. A smaller number of integration tests that call the real LLM API verify the end-to-end integration, but these run less frequently and are excluded from the PR quality gate.

How many E2E tests are reasonable for an AI MVP?+

A well-targeted test suite of 20-50 E2E tests covering the critical user journeys is more valuable than 200 tests covering every edge case. SpeedMVPs focuses the initial test suite on the flows that, if broken, would make the product unusable for most users. Additional tests are added as the product grows and new flows become critical. The principle is that every failing test should be something a real user would notice immediately.

Can Playwright test mobile browser behaviour?+

Yes. Playwright supports device emulation, simulating the viewport size, touch events, and user agent of mobile devices. SpeedMVPs configures mobile device emulation for tests covering key mobile flows. For React Native mobile apps, Playwright is not the right tool (Detox or Maestro is more appropriate for native app testing), but for progressive web apps or mobile-responsive Next.js applications, Playwright mobile emulation covers the mobile browser experience.

Does Playwright test catch visual design regressions?+

Playwright supports screenshot-based visual comparison testing using the toHaveScreenshot assertion. This captures a screenshot of an element or page and compares it against a stored baseline, failing if the visual output changes. SpeedMVPs can configure visual regression tests for key components or pages where design accuracy is critical. However, visual regression tests are sensitive to minor rendering differences and require baseline maintenance, so we apply them selectively rather than to every page.

Want automated E2E testing protecting your AI product from day one? Get a free consultation at speedmvps.co.uk

Get a Free Quote