Skip to content

Implement pest --record command for browser test generation#221

Closed
J87NL wants to merge 12 commits into
pestphp:5.xfrom
J87NL:4.x
Closed

Implement pest --record command for browser test generation#221
J87NL wants to merge 12 commits into
pestphp:5.xfrom
J87NL:4.x

Conversation

@J87NL

@J87NL J87NL commented May 23, 2026

Copy link
Copy Markdown

As more code (and tests) gets written by AI, (browser)tests matter more than ever.
Not just as a safety net, but as the source of truth.

vendor/bin/pest --record (or php artisan test --record) opens a real browser, lets you click through your app, fill and save forms, close the browser, give the test a name and Pest writes a ready-to-run test to tests/Browser/.

vendor/bin/pest --record --visit=/checkout
vendor/bin/pest --record --auth --migrate-fresh --seed --visit=/dashboard
vendor/bin/pest --record --url=https://pestphp.com

This implementation is based on my POC https://github.com/ComfyCodersBV/laravel-pest-recorder which I talked about with Nuno at Laracon EU.

Pest-browserrecorder-demo.mp4

What's in here:

  • Full record flow: auto-starts Laravel test server, opens Playwright recorder, you can navigate, fill forms, make assertions.
  • Event sanitizer: deduplicates fills, removes noise, cleans up navigations
  • Code generator: maps Playwright events to Pest Browser format
  • Auth support: --auth or --user bootstraps a factory user with a session cookie; generated test uses actingAs(). Built in auth for Laravel included, manual override option possible for other frameworks or extended authentication.
  • RECORDING.md usage guide
  • Most original options of playwright codegen supported & more like the --url=... flag.

nunomaduro and others added 12 commits April 8, 2026 23:08
* chore: pin GitHub Actions to commit SHAs

* chore: pin GitHub Actions to commit SHAs
Add --server/--migrate-fresh/--seed flags and auto-detect login sequences
- Record.php: add --server (starts `php artisan serve`), --env, --migrate-fresh, --seed options
- TestGenerator: strip password form fills and inject actingAs(factory()) automatically; pass $actingAs when --acting-as is set
- Locator: use Selector::getByLabelSelector for textbox/searchbox/combobox roles
- README: document --server (env mismatch problem), expand --acting-as section, fix example output
…using factory session, remove login sequence auto-detection, add RECORDING.md
…neration into a dedicated Laravel script, and fix various recorder issues
**As more code (and tests) gets written by AI, (browser)tests matter more than ever. Not just as a safety net, but as the source of truth.** 

`vendor/bin/pest --record` (or `php artisan test --record`) opens a real browser, lets you click through your app, fill and save forms, close the browser, give the test a name and Pest writes a ready-to-run test to tests/Browser/. 

```bash
vendor/bin/pest --record --visit=/checkout
vendor/bin/pest --record --auth --migrate-fresh --seed --visit=/dashboard
vendor/bin/pest --record --url=https://pestphp.com
```

This implementation is based on my POC https://github.com/ComfyCodersBV/laravel-pest-recorder which I talked about with Nuno at Laracon EU.

https://github.com/user-attachments/assets/6c39b3e7-89aa-4131-92b7-3ed8400f5859


What's in here:
- Full record flow: auto-starts Laravel test server, opens Playwright recorder, you can navigate, fill forms, make assertions.
- Event sanitizer: deduplicates fills, removes noise, cleans up navigations
- Code generator: maps Playwright events to Pest Browser format
- Auth support: `--auth` or `--user` bootstraps a factory user with a session cookie; generated test uses actingAs(). Built in auth for Laravel included, manual override option possible for other frameworks or extended authentication.
- RECORDING.md usage guide
- Most original options of `playwright codegen` supported & more like the `--url=...` flag.
@nunomaduro

Copy link
Copy Markdown
Member

Can you target 5.x branch as i would like to make this "part" of pest 5?

@J87NL J87NL changed the base branch from 4.x to 5.x May 24, 2026 12:48
@J87NL

J87NL commented May 24, 2026

Copy link
Copy Markdown
Author

Opened a new PR with the 5.x-target branch at #222

@J87NL J87NL closed this May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants