Skip to content
·8 min read

End-to-End Testing with Playwright for AI-Built Apps

Write an offline practice test, then check saved results and access in a disposable copy of your app.

Share

Your booking page can still say “Reserved” after a change breaks the save. A browser test gives you a repeatable way to check what a customer can do and what they can find afterward. Start with a practice page that runs entirely in the browser, then use the same idea on an isolated copy of your app.

What does an end-to-end test check?

An end-to-end test follows a job through the pieces the customer uses. For a booking, that might mean choosing a time, reserving it and opening the saved appointment from a fresh browser session. A unit test could check whether one time is valid. An integration test could check whether the booking code saves to the database. The browser test checks the path the customer takes through the app.

Playwright can open a browser, click or type the way a customer does, and check an expected result. That last check is called an assertion. It is what makes a test fail when an important result goes missing. A passing assertion tells you what happened in that one case.

How do you set up a practice project?

Use a separate folder with a supported Node.js version installed. These commands create a small project for the example. They do not connect to your app.

mkdir playwright-practice
cd playwright-practice
npm init -y
npm init playwright@latest

Choose TypeScript, put the files in tests, and let Playwright install the browsers. Skip the generated GitHub Actions workflow if you want to use the small example below. Create tests/booking-practice.spec.ts. Leave the generated example files alone. The command for this exercise runs only the new file in the generated chromium project.

Before pointing any test at your own app, confirm that the address serves a disposable copy, that saves go to a separate test database and that sign-in uses test settings and accounts. Disable payments and messages or connect only a verified sandbox and test inbox you control. Use fake records. If you cannot confirm a connection, keep using the practice page before trying any write in your app.

How do you write your first browser check?

The practice page is a fixture, a small example with a known starting state. It shows a confirmation after you select a time and click Reserve. It has no database or external service. Paste this into the new test file.

import { expect, test } from '@playwright/test';

test('shows the selected booking time', async ({ page }) => {
  await page.context().setOffline(true);
  await page.setContent(`
    <form id="booking">
      <label for="slot">Time</label>
      <select id="slot" required>
        <option value="">Choose a time</option>
        <option value="15:00">Tuesday at 3:00</option>
      </select>
      <button type="submit">Reserve</button>
    </form>
    <p role="status" id="confirmation"></p>
    <script>
      document.getElementById('booking').addEventListener('submit', event => {
        event.preventDefault();
        const slot = document.getElementById('slot');
        document.getElementById('confirmation').textContent =
          'Reserved ' + slot.options[slot.selectedIndex].text;
      });
    </script>
  `);

  await page.getByLabel('Time').selectOption('15:00');
  await page.getByRole('button', { name: 'Reserve' }).click();
  await expect(page.getByRole('status')).toHaveText('Reserved Tuesday at 3:00');
});
npx playwright test tests/booking-practice.spec.ts --project=chromium

The test finds the field by its label and the button by its role and name. The final line waits for the exact confirmation. Try changing only the fixture’s 'Reserved ' to 'Unavailable ' and rerun the test. It should fail at the assertion. Restore the original text and run it again.

For the real booking flow, write a separate test that opens the confirmed test app and checks the saved record as the same test customer in a fresh browser session. A correct confirmation only proves what the first browser displayed. The Playwright walkthrough for checking a saved booking shows how to make that stronger check fail on purpose when a confirmation appears without a save.

When can you reuse a test sign-in?

Start by keeping login inside the test when login itself is the feature you are checking. For tests that only read existing information, you can use a setup project to sign in with a disposable account once and save its browser state with page.context().storageState({ path: 'playwright/.auth/user.json' }). In the project that uses that state, point use.storageState to the file and make the setup project a dependency. Wait until login has finished and the signed-in page appears before saving it.

Add playwright/.auth/ to .gitignore. That file can let someone act as the test account. Keep it out of shared logs, reports and uploaded files. Supply test credentials through your project’s existing environment setup. Keep them out of the test source. Share one account only when the tests can safely read it at the same time without changing shared data. Give tests that change settings or create records their own account and records, or reset the isolated fixture before each attempt.

How do you check a protected page while signed out?

For the next example, use a separate file in your app’s test suite. Set use.baseURL in that suite’s Playwright config to the confirmed test address. This sample assumes /dashboard redirects a signed-out visitor to /login on the same test site and that the protected dashboard contains a “Your bookings” heading. The check allows a query string, such as a return address after sign-in. Adapt the paths and labels to your app’s expected behavior.

// tests/signed-out.spec.ts
import { expect, test } from '@playwright/test';

test.use({ storageState: { cookies: [], origins: [] } });

test('asks a signed-out visitor to sign in', async ({ page, baseURL }) => {
  if (!baseURL) {
    throw new Error('Set use.baseURL to the confirmed test app address.');
  }
  const signInURL = new URL('/login', baseURL);

  await page.goto('/dashboard');
  await expect(page).toHaveURL(url =>
    url.origin === signInURL.origin && url.pathname === signInURL.pathname
  );
  await expect(page.getByRole('heading', { name: 'Sign in', exact: true })).toBeVisible();
  await expect(page.getByRole('heading', { name: 'Your bookings', exact: true })).toHaveCount(0);
});

The empty state overrides any saved sign-in from the project for this file. Keep shared helpers that sign in before a test out of this file. The browser check covers what the visitor sees. For private records, check separately that a second test account cannot read the first account’s saved booking.

Case in your isolated appStarting stateResult to check
Create a bookingOne fresh test slot and a disposable accountThe original account can open exactly one saved booking from a new session.
Try a time that is takenA test booking already existsThe screen offers another time and the app saves no extra booking.
Submit an incomplete formA fresh test slot and an empty required fieldThe form explains what is missing and saves no booking.

Use a fresh eligible slot and test account for each run that creates data, or explicitly reset the same records before each attempt in your disposable environment. A rerun can start with a clean browser while the test database still has the previous booking.

How do you run the practice check in GitHub Actions?

A CI job runs the check on a fresh machine when you push a change or open a pull request. For the practice project, commit package.json, package-lock.json, the Playwright config and the new test file. Put this in .github/workflows/booking-practice.yml. It runs the self-contained example. It does not start your app or use account credentials.

name: Booking practice
on: [push, pull_request]
permissions:
  contents: read
jobs:
  practice:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          persist-credentials: false
      - uses: actions/setup-node@v7
        with:
          node-version: 24
          package-manager-cache: false
      - run: npm ci
      - run: npx playwright install --with-deps chromium
      - run: npx playwright test tests/booking-practice.spec.ts --project=chromium

Before adding tests for your app to CI, arrange for the job to start a verified test copy with separate database, sign-in, payment and message settings. Put only test credentials in the job that needs them. Keep that job separate from the credential-free practice workflow. Use Playwright’s webServer option if the test runner should start and wait for your local test app. Match its address to use.baseURL and have the job fail if the test setup cannot be confirmed.

A report lists test results. Trace files, screenshots and videos depend on their own settings. For example, trace: 'retain-on-failure' in use keeps a trace of a failed run, even without retries. A trace can include page content and network details. Use fake data and keep recording off where sensitive details could appear. Review any retained files before sharing them. The workflow above uploads none.

How do you keep tests quick and repeatable?

Start with one browser and the handful of checks that would stop a release. Add other browsers when your audience or a known issue makes that coverage useful. Test files can run in parallel, so keep their accounts and saved records independent before increasing the number of workers. Start with one worker while you work out which records a test changes.

When a test fails, check the starting state and the exact assertion first. For example, a slot already taken before the test started tells you something different from an available slot that the app failed to save. Save the expected result alongside the observed result so the next run can prove whether you fixed it.

What should you automate next?

Use the next bug you find to choose a test. Write down the starting state, the smallest set of actions that reproduces the bug and the result the customer should get. Turn that result into an assertion. Run it against the broken test copy, then run the same check after the fix. Keep the check with the change so it runs the next time someone edits that part of the app.

PJ
Pranay Joshi

20+ years building products at scale. VP of Product & Engineering, startup founder, and AI coach. Helping dreamers turn ideas into reality with vibe coding.