PHPackages                             leeovery/laravel-playwright - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. leeovery/laravel-playwright

ActiveLibrary[Testing &amp; Quality](/categories/testing)

leeovery/laravel-playwright
===========================

Backend stuff for Playwright e2e tests

v0.3.0(5mo ago)8175MITPHPPHP ^8.3

Since Dec 28Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/leeovery/laravel-playwright)[ Packagist](https://packagist.org/packages/leeovery/laravel-playwright)[ Docs](https://github.com/leeovery/laravel-playwright)[ RSS](/packages/leeovery-laravel-playwright/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (8)Versions (6)Used By (0)

Laravel Playwright
==================

[](#laravel-playwright)

[![Latest Version on Packagist](https://camo.githubusercontent.com/91260e5430cdf02268eccb118db4221687532492ef9d34b14704963f50f3f986/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c65656f766572792f6c61726176656c2d706c61797772696768742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/leeovery/laravel-playwright)[![Total Downloads](https://camo.githubusercontent.com/969eb65ccc7ccedc150b0f998b69afb3ebefea3334b11772db3f7a3266420966/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c65656f766572792f6c61726176656c2d706c61797772696768742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/leeovery/laravel-playwright)[![GitHub Actions](https://github.com/leeovery/laravel-playwright/actions/workflows/main.yml/badge.svg)](https://github.com/leeovery/laravel-playwright/actions/workflows/main.yml/badge.svg)

Backend utilities for Playwright e2e tests. Provides HTTP endpoints and commands to control your Laravel application during testing - manage databases, factories, authentication, migrations, and environment configuration from your Playwright tests.

Requirements
------------

[](#requirements)

- PHP 8.3+
- Laravel 11+

Installation
------------

[](#installation)

```
composer require leeovery/laravel-playwright --dev
```

Publish config and register service provider:

```
php artisan playwright:install
```

Configuration
-------------

[](#configuration)

The package config (`config/playwright.php`) includes:

- **Environments**: Control which environments expose the endpoints (default: `local,testing,playwright`)
- **Route prefix**: Customize the endpoint URL prefix (default: `__playwright__`)
- **Middleware**: Set middleware for routes (default: `web`)
- **Environment files**: Configure `.playwright.env` file handling
- **Factory settings**: Map model aliases and configure factory behaviors

Create a `.playwright.env` file for test-specific environment variables.

Features
--------

[](#features)

### HTTP Endpoints

[](#http-endpoints)

All endpoints are prefixed with `__playwright__` (configurable) and protected by environment checks:

#### Database Management

[](#database-management)

- `POST /create-database` - Create test database
- `POST /drop-database` - Drop test database
- `POST /migrate` - Run migrations (supports `?fresh=1&seed=1`)
- `POST /truncate` - Truncate specific tables

#### Factory &amp; Authentication

[](#factory--authentication)

- `POST /factory` - Create model instances via factories
- `POST /login` - Authenticate user (create or find existing)
- `POST /logout` - End session
- `POST /user` - Get current authenticated user

#### Utilities

[](#utilities)

- `POST /artisan` - Execute artisan commands
- `POST /routes` - Get application route list
- `GET /csrf` - Get CSRF token
- `POST /env-setup` - Swap to `.playwright.env`
- `POST /env-teardown` - Restore original `.env`

### Artisan Commands

[](#artisan-commands)

```
# Setup/teardown test environment
php artisan playwright:env-setup
php artisan playwright:env-teardown

# Database operations
php artisan db:create --database=playwright_test
php artisan db:drop --database=playwright_test
```

Usage Example
-------------

[](#usage-example)

From Playwright tests, interact with Laravel via HTTP:

```
// Setup environment
await request.post("http://localhost/__playwright__/env-setup");

// Run migrations
await request.post("http://localhost/__playwright__/migrate", {
  data: { fresh: true, seed: true },
});

// Create and login user
const user = await request.post("http://localhost/__playwright__/factory", {
  data: {
    model: "User",
    state: ["verified"],
    attributes: { email: "test@example.com" },
  },
});

await request.post("http://localhost/__playwright__/login", {
  data: { attributes: { email: "test@example.com" } },
});

// Teardown
await request.post("http://localhost/__playwright__/env-teardown");
```

### Factory State Parameters

[](#factory-state-parameters)

Pass complex state parameters to factories:

```
// Fetch model and pass to state method
data: {
  state: [
    { createdBy: ["model.User:100"] }, // Fetch User with id=100
  ];
}

// Use param aliases (configure in config/playwright.php)
data: {
  state: [{ endsAt: ["Carbon(2023-12-25 23:59:59)"] }];
}
```

Register param aliases in your service provider:

```
use Leeovery\LaravelPlaywright\Playwright;

Playwright::paramAlias('Carbon', fn($date) => new Carbon($date));
```

Security
--------

[](#security)

**Important**: This package exposes powerful endpoints that can manipulate your application. Only enable in non-production environments. The package includes middleware that blocks requests outside configured environments.

If you discover security issues, email .

Testing
-------

[](#testing)

```
composer test
composer test-coverage
```

Development
-----------

[](#development)

```
# Format code with Pint
composer pint

# Refactor code with Rector
composer rector
```

Credits
-------

[](#credits)

- [Lee Overy](https://github.com/leeovery)
- [All Contributors](../../contributors)

License
-------

[](#license)

MIT License. See [License File](LICENSE.md) for details.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance70

Regular maintenance activity

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~264 days

Total

5

Last Release

172d ago

PHP version history (3 changes)v0.0.1PHP ^8.1

v0.1.0PHP ^8.2

v0.3.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/93bafe84d227ffd47a06f36023d14a2ff6722bdcad9a3ab5bdcc66459eae463e?d=identicon)[leeovery](/maintainers/leeovery)

---

Top Contributors

[![leeovery](https://avatars.githubusercontent.com/u/1087804?v=4)](https://github.com/leeovery "leeovery (49 commits)")

---

Tags

leeoverylaravel-playwright

###  Code Quality

TestsPest

Static AnalysisRector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/leeovery-laravel-playwright/health.svg)

```
[![Health](https://phpackages.com/badges/leeovery-laravel-playwright/health.svg)](https://phpackages.com/packages/leeovery-laravel-playwright)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[timacdonald/log-fake

A drop in fake logger for testing with the Laravel framework.

4235.9M56](/packages/timacdonald-log-fake)[spatie/laravel-mail-preview

A mail driver to quickly preview mail

1.3k419.3k5](/packages/spatie-laravel-mail-preview)[christophrumpel/missing-livewire-assertions

This package adds missing livewire test assertions.

149336.0k9](/packages/christophrumpel-missing-livewire-assertions)[illuminate/testing

The Illuminate Testing package.

3315.6M113](/packages/illuminate-testing)[encodia/laravel-health-env-vars

Custom check for Spatie's Laravel Health - Ensure every .env variable you need has been set

20143.5k](/packages/encodia-laravel-health-env-vars)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
