# Write Playwright Tests for an Inertia.js App

Yes. An agent adds Playwright end-to-end tests to a Laravel and Inertia app: sign in, settings, password confirmation and account deletion, run in a real browser.

[Run this on Rush](https://cloud.getrush.ai/run/write-playwright-tests/inertia/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

PHP feature tests prove what the server sends. They cannot prove that the React page mounts, that a `<Form>` posts to the right route, or that a redirect swaps the page without a full reload. The agent begins with how the app boots. In a repository laid out like laravel/react-starter-kit, `package.json` has no `test` script and no Playwright, `.npmrc` sets `ignore-scripts=true`, and `composer setup` does the whole install: `composer install`, a copied `.env`, `php artisan key:generate`, `php artisan migrate --force`, `npm install` and `npm run build`. `.env.example` selects SQLite, a database session driver and `MAIL_MAILER=log`, with `APP_URL=http://localhost:8000`. `database/seeders/DatabaseSeeder.php` creates one verified user, `test@example.com`, and `UserFactory` gives it the password `password`.

It adds `@playwright/test` to `devDependencies`, installs Chromium explicitly with `npx playwright install --with-deps chromium` because the `.npmrc` setting stops package install scripts from running, and writes `playwright.config.ts` with a `webServer` that runs `php artisan serve` on port 8000 against the built assets in `public/build`. A global setup runs `php artisan migrate:fresh --seed` on a separate SQLite file named in the web server's environment, so a test run never touches a developer's `database/database.sqlite`. `tsconfig.json` includes only `resources/js`, so the agent gives the `e2e/` directory its own `tsconfig.json`, and checks the new files with `npm run check`, the kit's `vp check`, whose lint options set `denyWarnings` and `typeAware`.

Selectors come from the markup the kit already ships. Eleven elements carry a `data-test` attribute, among them `login-button`, `register-user-button`, `update-profile-button`, `update-password-button`, `confirm-password-button`, `delete-user-button`, `confirm-delete-user-button` and `logout-button`, and the form fields have stable ids such as `#email`, `#password` and `#current_password`. The agent configures `testIdAttribute: 'data-test'` so `getByTestId` reads them, and uses labels for the inputs. It writes one spec per journey. Sign in as the seeded user and land on `/dashboard`. Open `settings/profile`, change the name, press `update-profile-button` and wait for the toast that `use-flash-toast.ts` raises from the server's flash. Visit `settings/security`, which `routes/settings.php` wraps in `RequirePassword`, and pass through the `auth/confirm-password` screen first. Delete the account through the dialog and end as a guest on `/`.

Two properties of this app decide how the specs are written, and the agent reads both from the code. `FortifyServiceProvider` limits login to five attempts a minute per email and address, and the password route carries `throttle:6,1`, so the wrong-password cases use a fresh user per test instead of hammering the seeded one. And a newly registered user is unverified while `dashboard` sits behind the `verified` middleware, so the registration spec expects the `auth/verify-email` screen, then reads the verification link out of `storage/logs/laravel.log`, where the `log` mailer writes it, and follows it. `config/inertia.php` enables server-side rendering at `http://127.0.0.1:13714`, but `composer setup` builds only the client bundle, so the specs assert on visible elements after the client app mounts and do not depend on server-rendered HTML. Finally the agent adds a step to `.github/workflows/tests.yml` after `composer ci:check` that installs the browser and runs `npx playwright test`, and runs the suite itself with the HTML report and traces kept for failures.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add Playwright end-to-end tests to this Laravel and Inertia React app. Read package.json, .npmrc, composer.json (the setup and ci:check scripts), .env.example, config/inertia.php, config/fortify.php, routes/web.php, routes/settings.php, app/Providers/FortifyServiceProvider.php, database/seeders/DatabaseSeeder.php, database/factories/UserFactory.php, vite.config.ts, tsconfig.json, .github/workflows/tests.yml and the pages and components under resources/js that carry a data-test attribute. Install PHP and Composer if the sandbox lacks them, run composer setup, then add @playwright/test and install Chromium with npx playwright install --with-deps chromium. Write playwright.config.ts with testIdAttribute set to data-test, a webServer that runs php artisan serve on port 8000 with its own SQLite database file, and a global setup that runs migrate:fresh --seed on that file. Write specs under e2e/ for: sign in and reach the dashboard, sign out, a wrong password showing the error, registration through to a verified email using the link the log mailer writes, profile update with its toast, password change behind the password confirmation screen, and account deletion through the dialog. Respect the login and password rate limits by creating a fresh user for failure cases. Make the new files pass npm run check and type checking. Add a step to the tests workflow that runs the suite. Run npx playwright test until it passes without retries, and do not change application code. Open a pull request with the list of specs and the test output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The pull request adds `playwright.config.ts`, an `e2e/` directory with its specs, a global setup file and a `tsconfig.json`, a `test:e2e` script and the `@playwright/test` entry in `package.json`, lines in `.gitignore` for `playwright-report/` and `test-results/`, and one step in `.github/workflows/tests.yml`. Its description lists each spec with the journey it covers and the `data-test` ids it relies on, quotes the output of `npx playwright test`, and says which behaviours it read from the code and did not test, such as passkeys, which need a WebAuthn authenticator the specs do not emulate.

A reviewer looks at how the suite is isolated before anything else. The database file the web server uses must be the test one, and the workflow step must come after the build, because `php artisan serve` serves whatever is in `public/build`. They check that no spec waits on a fixed timeout and that the verification-link step reads only the newest entry in the log. They also decide whether the browser run belongs in the same job as `composer ci:check` or in a job of its own, since it lengthens every pull request's checks.

No file under `app/`, `routes/` or `resources/js` changes. If a journey cannot be driven because an element has no stable selector, the description names the element and proposes the `data-test` attribute, and leaves adding it to the team.

## Run it on every pull request that changes a page or a route

The specs themselves run on every pull request once the workflow step is merged, so the recurring job is keeping them complete. Create an automation on the Project with a `github` trigger on `pull_request.closed.merged` and a prompt that says: for the merged pull request named in the event, find pages under `resources/js/pages` or routes it added or changed that no spec in `e2e/` visits, write the missing specs, run the suite and open a pull request. The trigger adds the event after the prompt and fills in no placeholder.

## Why run it on Rush?

An end-to-end suite is only credible if it was run, and running this one takes a PHP runtime, a Node toolchain, a built frontend, a seeded database, a web server and a browser, all on one machine at once. A Rush run has that machine to itself: the agent installs what the sandbox lacks, starts `php artisan serve`, drives Chromium against it and reads the failures, and every command with its output stays in the run's transcript. A flaky spec is visible there as a pass followed by a fail, which is harder to see in a diff.

It also keeps the experiment off a developer's laptop. Nobody's local database is migrated or reseeded, no ports are held, and the person who asked reads a pull request with the report attached when the run ends.

## Frequently asked questions

### Why Playwright and not Laravel Dusk or Pest browser tests?

Any of them can drive this app. The request asks for Playwright because the frontend is TypeScript and the kit already lints and type-checks it with `npm run check` and `tsc --noEmit`, so the specs sit beside the code they exercise. To get Dusk or Pest's browser plugin instead, say so in the prompt; the journeys and the selectors stay the same.

### Does it need the SSR server running?

No. `config/inertia.php` has `ssr.enabled` set to `true`, but `composer setup` runs `npm run build`, not `npm run build:ssr`, and the specs wait for elements the client app renders. A project that deploys with SSR can ask for one extra spec that fetches a page's HTML without running scripts and checks the content is already there.

### How does it get past email verification in a test?

`.env.example` sets `MAIL_MAILER=log`, so the verification email is written to `storage/logs/laravel.log` instead of being sent. The registration spec reads the signed link from the newest log entry and opens it. Nothing is mocked: the link is the one Laravel generated for that user.

### Will the tests be flaky because of rate limiting?

They would be if every failure case reused one account. Login is limited to five attempts a minute per email and address, so the agent creates a separate user for each negative case through a small artisan call in the spec's setup. The seeded user is used for the successful journeys only.

## More Inertia.js jobs

- [Review Pull Requests on an Inertia.js App](https://getrush.ai/run/review-pull-requests/inertia/)
- [Write Feature Tests for an Inertia.js App](https://getrush.ai/run/write-feature-tests/inertia/)

## The same job on other stacks

- [Write Playwright Tests for a Laravel App](https://getrush.ai/run/write-playwright-tests/laravel/)
- [Write Playwright Tests for a Next.js App](https://getrush.ai/run/write-playwright-tests/nextjs/)
- [Write Playwright Tests for a Nuxt App](https://getrush.ai/run/write-playwright-tests/nuxt/)
- [Write Playwright Tests for a React Router App](https://getrush.ai/run/write-playwright-tests/react-router/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
