GuidesEnd-to-end testing

Set up a Playwright suite

Create a Playwright suite from scratch, write your first real user-flow test, and run it on every pull request.

Playwright is the world's most popular open-source end-to-end testing framework. You write TypeScript code that drives a real browser and exercises your application the same way a user would.

By the end of this guide, you will have one real user-flow test in a new Playwright suite, running automatically on every pull request:

Pull request merge-gate loop: a pull request triggers a real browser to run your user flow. If it passes, merge the PR; if it fails, inspect the replay, fix and push back to the pull request.

Pick one flow you would be embarrassed to break

Most tutorials start with a smoke test that loads / and checks for a heading. That proves Playwright can open a browser, not that your product works.

Pick one flow you would be embarrassed to break. In BikeBook, our example bike-booking app, a great starter flow is:

  • Sign up as a new user
  • Add a new bike to the office fleet
  • Book that bike for the morning

Here is a replay of that passing test running on Endform:

Passed on main

Set up your suite

You need Node.js 24 or newer, an application URL to test (your own app, or our hosted BikeBook app at https://endform-playwright-guides.vercel.app), an AI_GATEWAY_API_KEY for generating steps locally, and a GitHub repository. Endform itself needs Node.js 22.15 or newer, but Playwright Intent needs 24.

  1. Initialize Playwright, Playwright Intent and Endform

    Scaffold a new Playwright suite, set up Playwright Intent, and connect the suite to Endform:

    npm init playwright@latest
    npm init playwright-intent@latest
    npm init endform@latest

    npm init endform signs you in and runs the example test on Endform.

    Set use.baseURL in playwright.config.ts to your app URL (or https://endform-playwright-guides.vercel.app to try BikeBook). Click any file below to expand its contents:

    Folder structure created by initialization
    5 files+50
  2. Write your first test

    Replace tests/example.spec.ts with tests/book-a-bike.spec.ts (or your own core user flow). Hover or click an ai.do(...) step to inspect the compiled Playwright code:

    tests/book-a-bike.spec.ts
    import { expect, test } from "playwright-intent"; test("a new user can sign up, add a bike, and book it", async ({  page,  ai,}) => {  const email = `user-${Date.now()}-${Math.random().toString(36).slice(2, 8)}@example.com`;   await page.goto("/sign-up");   await expect(page.getByRole("status")).toContainText("Booked Road 1");  await expect(    page.getByRole("listitem").filter({ hasText: "Road 1" }),  ).toContainText("morning");});
  3. Run it on Endform

    npx endform@latest test

    On the first run, Playwright Intent uses your configured model to generate a reviewable .intent/ TypeScript file for each ai.do(...) step. Commit .intent/ alongside your test so future runs execute deterministically from the cache without calling a model.

    Here is today's scheduled run of this test in Endform:

    1 test · clean app
  4. Run it on every pull request

    Add .github/workflows/e2e.yml (or replace the workflow created by Playwright) so every pull request runs your suite on Endform:

    .github/workflows/e2e.yml
    name: End-to-end tests
    
    on:
      pull_request:
        branches: [main]
    
    permissions:
      contents: read
      id-token: write
    
    jobs:
      e2e:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
          - uses: actions/setup-node@v4
            with:
              node-version: 24
          - run: npm ci
          - run: npx endform@latest test
            env:
              BASE_URL: ${{ vars.STAGING_URL }}

    For CI authentication, other providers, or testing per-PR preview deployments, see Set up Endform in CI, Test Vercel previews, and Test Netlify Deploy Previews. If you are testing a local dev server, see Test against a local server.

Last updated