PHPackages                             franbarbalopez/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. franbarbalopez/laravel-playwright

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

franbarbalopez/laravel-playwright
=================================

A Laravel Package to use Laravel testing functionality into Playwright

0.2.0-alpha(1y ago)3522↓50%MITPHPPHP ^8.2CI passing

Since Mar 17Pushed 1y ago2 watchersCompare

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

READMEChangelog (2)Dependencies (7)Versions (3)Used By (0)

 [![Latest Version on Packagist](https://camo.githubusercontent.com/6bc7aecde6ae658b8b5ec1abe17eb2d5154430ba0dbaef694a7b90f52cda1381/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6672616e62617262616c6f70657a2f6c61726176656c2d706c61797772696768742e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/6bc7aecde6ae658b8b5ec1abe17eb2d5154430ba0dbaef694a7b90f52cda1381/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6672616e62617262616c6f70657a2f6c61726176656c2d706c61797772696768742e7376673f7374796c653d666c61742d737175617265) [![GitHub Tests Action Status](https://camo.githubusercontent.com/f3db5c8a4a3d10b825e2e64527acd122c4ccfe30df0e719d22ca2ecb1163f8ab/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6672616e62617262616c6f70657a2f6c61726176656c2d706c61797772696768742f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/f3db5c8a4a3d10b825e2e64527acd122c4ccfe30df0e719d22ca2ecb1163f8ab/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6672616e62617262616c6f70657a2f6c61726176656c2d706c61797772696768742f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265) [![Total Downloads](https://camo.githubusercontent.com/b65aaa67e477a96476099ee728587148946f00a7cbfe863ed9af8543854ced5d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6672616e62617262616c6f70657a2f6c61726176656c2d706c61797772696768742e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/b65aaa67e477a96476099ee728587148946f00a7cbfe863ed9af8543854ced5d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6672616e62617262616c6f70657a2f6c61726176656c2d706c61797772696768742e7376673f7374796c653d666c61742d737175617265) [![License](https://camo.githubusercontent.com/cb064e4cfbb3b8a23a7c00d96322da94f3407a71be319d6871b75d303ce9a4b4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6672616e62617262616c6f70657a2f6c61726176656c2d706c61797772696768742e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/cb064e4cfbb3b8a23a7c00d96322da94f3407a71be319d6871b75d303ce9a4b4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6672616e62617262616c6f70657a2f6c61726176656c2d706c61797772696768742e7376673f7374796c653d666c61742d737175617265)

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

[](#laravel-playwright)

A Laravel package that integrates Laravel testing functionality with Playwright. Use Laravel's powerful factories, authentication and other features directly in your Playwright tests.

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

[](#installation)

Warning

**ALPHA RELEASE** – This package is in the **alpha phase**, meaning its structure may change significantly. It is recommended for internal testing and controlled environments only.

### Requirements

[](#requirements)

- PHP 8.2+
- Laravel 11+

### Via composer

[](#via-composer)

```
composer require franbarbalopez/laravel-playwright:0.2.0-alpha --dev
```

### Setup

[](#setup)

After installing the package, run the installation command:

```
php artisan laravel-playwright:install
```

This will:

- Install Playwright if it's not already installed
- Ask for your Playwright tests directory location
- Copy the necessary JavaScript helper files

Important

After installation, you must uncomment and update the `baseURL` in your playwright config file.

Usage
-----

[](#usage)

### Factories

[](#factories)

#### Creating Models using Factories

[](#creating-models-using-factories)

```
const user = await factory(page, {
    model: 'App\\Models\\User'
})
```

You may create a collection of many models using the `count` property:

```
const users = await factory(page, {
    model: 'App\\Models\\User',
    count: 3,
})
```

##### Applying States

[](#applying-states)

```
const users = await factory(page, {
    model: 'App\\Models\\User',
    count: 5,
    states: ['suspended'],
})
```

##### Overriding Attributes

[](#overriding-attributes)

```
const user = await factory(page, {
    model: 'App\\Models\\User',
    attributes: {
        name: 'Abigail Otwell',
    },
})
```

#### Factory Relationships

[](#factory-relationships)

##### Has Many Relationships

[](#has-many-relationships)

```
const user = await factory(page, {
    model: 'App\\Models\\User',
    relationships: [
        {
            method: 'has',
            name: 'posts'
            related: 'App\\Models\\Post',
            count: 3,
        }
    ]
})
```

You may override attributes of the related model using `attributes` property inside the relationship object:

```
const user = await factory(page, {
    model: 'App\\Models\\User',
    relationships: [
        {
            method: 'has',
            name: 'posts'
            related: 'App\\Models\\Post',
            count: 3,
            attributes: {
                title: 'New Post Title',
            }
        }
    ]
})
```

If you want the posts to be retrieved with the parent model you should use the `load` property:

```
const user = await factory(page, {
    model: 'App\\Models\\User',
    load: ['posts'],
    relationships: [
        {
            method: 'has',
            name: 'posts'
            related: 'App\\Models\\Post',
            count: 3,
            states: ['published'],
        }
    ]
})
```

##### Belongs To Relationships

[](#belongs-to-relationships)

```
const posts = await factory(page, {
    model: 'App\\Models\\Post',
    count: 3,
    relationships: [
        {
            method: 'for',
            name: 'user'
            related: 'App\\Models\\User',
            attributes: {
                name: 'Jessica Archer',
            }
        }
    ]
})
```

You could also use an id of a model generated previously:

```
const posts = await factory(page, {
    model: 'App\\Models\\Post',
    count: 3,
    relationships: [
        {
            method: 'for',
            name: 'user'
            related: 'App\\Models\\User',
            model_id: 1,
        }
    ]
})
```

##### Many to Many Relationships

[](#many-to-many-relationships)

```
const user = await factory(page, {
    model: 'App\\Models\\User',
    load: ['roles'],
    relationships: [
        {
            method: 'has',
            name: 'roles'
            related: 'App\\Models\\Role',
            count: 3,
        }
    ]
})
```

###### Pivot Table Attributes

[](#pivot-table-attributes)

```
const user = await factory(page, {
    model: 'App\\Models\\User',
    load: ['roles'],
    relationships: [
        {
            method: 'hasAttached',
            name: 'roles'
            related: 'App\\Models\\Role',
            count: 2,
            pivotAttributes: {
                assigned_at: '2025-03-17 18:00:00',
            },
        }
    ]
})
```

#### Polymorphic Relationships

[](#polymorphic-relationships)

##### Morph To Relationships

[](#morph-to-relationships)

As in Laravel you could use here the relationships way with the `for` method.

##### Polymorphic Many to Many Relationships

[](#polymorphic-many-to-many-relationships)

You can create this relationships using the `has` and `hasAttached` methods way as if we were doing this on Laravel.

### CSRF Token

[](#csrf-token)

```
const token = await csrfToken(page)
```

### Authentication

[](#authentication)

```
// Login with existing user by ID
const user = await login(page, { id: 1 })

// Create and login a new user
const newUser = await login(page, {
    attributes: {
        name: 'Test User',
        email: 'test@example.com',
    }
})

// Get the current user
const currentUser = await user(page)

// Logout
await logout(page)
```

Artisan Commands
----------------

[](#artisan-commands)

You can execute any Laravel Artisan command from your Playwright tests using the `artisan` endpoint. This is useful for resetting the database, clearing caches, or running any custom Artisan command during your end-to-end tests.

### Usage Example (JavaScript)

[](#usage-example-javascript)

```
await page.request.post('/__playwright__/artisan', {
    data: {
        command: 'migrate:fresh',
        parameters: {
            '--seed': true,
        }
    }
})
```

- `command`: The Artisan command you want to run (e.g., `migrate:fresh`, `cache:clear`, `route:list`).
- `parameters`: (Optional) An object with any parameters or options you want to pass to the command.

#### Example: List all routes in JSON format

[](#example-list-all-routes-in-json-format)

```
await page.request.post('/__playwright__/artisan', {
    data: {
        command: 'route:list',
        parameters: {
            '--format': 'json'
        }
    }
})
```

#### Error Handling

[](#error-handling)

If you try to run a non-existent command, the endpoint will return a 500 error.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance50

Moderate activity, may be stable

Popularity22

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 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 ~53 days

Total

2

Last Release

367d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5fac6595ce2d805f6e5a18e77e4b66fc8da6435ac13ca4870c5e7ed874fc4c15?d=identicon)[franbarbalopez](/maintainers/franbarbalopez)

---

Top Contributors

[![franbarbalopez](https://avatars.githubusercontent.com/u/57897024?v=4)](https://github.com/franbarbalopez "franbarbalopez (25 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/franbarbalopez-laravel-playwright/health.svg)](https://phpackages.com/packages/franbarbalopez-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)[illuminate/testing

The Illuminate Testing package.

3315.6M113](/packages/illuminate-testing)[christophrumpel/missing-livewire-assertions

This package adds missing livewire test assertions.

149336.0k9](/packages/christophrumpel-missing-livewire-assertions)[calebdw/larastan-livewire

A Larastan / PHPStan extension for Livewire.

43482.4k3](/packages/calebdw-larastan-livewire)[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)
