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

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

advalis/laravel-playwright
==========================

Laravel and Playwright E2E Testing

1.0.0(9mo ago)07MITPHPPHP &gt;=8.2

Since Aug 11Pushed 9mo agoCompare

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

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

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

[](#laravel-playwright)

This repository contains a Laravel and a Playwright library to help you write E2E tests for your Laravel application using [Playwright](https://playwright.dev/). It adds a set of endpoints to your Laravel application to allow Playwright to interact with it. You can do the following from your Playwright tests:

- Run artisan commands
- Create models using factories
- Run database queries
- Run PHP functions
- Update Laravel config while a test is running (until the test ends and calls `tearDown`).
- Registering a boot function to run on each Laravel request. You can use this feature to mock a service dependency, for example.
- Traveling to a specific time in the application during the test

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

[](#installation)

On Laravel side, install the package via composer:

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

On Playwright side, install the package via npm:

```
npm install @advalis/laravel-playwright
```

Laravel Config
--------------

[](#laravel-config)

You can configure the routes by adding an `e2e` key to your `config/app.php` file. The following options are available (default values are shown):

```
return [
    // ...

    'e2e' => [
        /**
        * The prefix for the testing endpoints that are used to interact with Playwright
        * Make sure to change `use.laravelBaseUrl` in playwright.config.ts if you change this
        */
        'prefix' => 'playwright',

        /**
        * The environments in which the testing endpoints are enabled
        * CAUTION: Enabling the testing endpoints in production can be a critical security issue
        */
        'environments' => ['local', 'testing'],
    ],
];
```

Playwright Config
-----------------

[](#playwright-config)

Set `use.laravelBaseUrl` in your `playwright.config.ts` file to the base URL of your testing endpoints. This is the URL of your application + the `prefix` you set in Laravel config.

```
export default defineConfig({
    // ...other
    use: {
        laravelBaseUrl: 'http://localhost/playwright',
    },
});
```

If you use Typescript, include the `LaravelOptions` type in the `defineConfig` function.

```
import type { LaravelOptions } from '@advalis/laravel-playwright';

export default defineConfig({
    use: {
        laravelBaseUrl: 'http://localhost/playwright',
    },
});
```

Setting up tests
----------------

[](#setting-up-tests)

In your Playwright tests, swap the `test` import from `@playwright/test` to `@advalis/laravel-playwright`.

```
- import { test } from '@playwright/test';
+ import { test } from '@advalis/laravel-playwright';

test('example', async ({ laravel }) => {
    laravel.artisan('migrate:fresh');
});
```

> **Note**: In practise, it is not recommended to import from `@advalis/laravel-playwright` directly on every test file, if you have many. Instead, create your own [test fixture](https://playwright.dev/docs/test-fixtures) extending `test` from `@advalis/laravel-playwright` and import that fixture in your tests.

Basic Usage
-----------

[](#basic-usage)

```
import { test } from '@advalis/laravel-playwright';

test('example', async ({ laravel }) => {

    // RUN ARTISAN COMMANDS
    // ====================
    const output = await laravel.artisan('migrate:fresh');
    // output.code: number - The exit code of the command
    // output.output: string - The output of the command
    // with parameters
    await laravel.artisan('db:seed', ['--class', 'DatabaseSeeder']);

    // TRUNCATE TABLES
    // ===============
    await laravel.truncate();
    // in specific DB connections
    await laravel.truncate(['connection1', 'connection2']);

    // CREATE MODELS FROM FACTORIES
    // ============================
    // Create a App\Models\User model
    // user will be an object of the model
    const user = await laravel.factory('User');
    // Create a App\Models\User model with attributes
    await laravel.factory('User', { name: 'John Doe' });
    // Create 5 App\Models\User models
    // users will be an array of the models
    const users = await laravel.factory('User', {}, 5);
    // Create a CustomModel model
    await laravel.factory('CustomModel');

    // RUN A DATABASE QUERY
    // ====================
    // Run a query
    await laravel.query('DELETE FROM users');
    // Run a query with bindings
    await laravel.query('DELETE FROM users WHERE id = ?', [1]);
    // Run a query on a specific connection
    await laravel.query('DELETE FROM users', [], { connection: 'connection1' });
    // Run a unprepared statement
    await laravel.query(`
        DROP SCHEMA public CASCADE;
        CREATE SCHEMA public;
        GRANT ALL ON SCHEMA public TO public;
    `, [], { unprepared: true });

    // RUN A SELECT QUERY
    // ==================
    // Run a select query
    // Returns an array of objects
    const blogs = await laravel.select('SELECT * FROM blogs');
    // Run a select query with bindings
    await laravel.select('SELECT * FROM blogs WHERE id = ?', [1]);
    // Run a select query on a specific connection
    await laravel.select('SELECT * FROM blogs', [], { connection: 'connection1' });

    // RUN A PHP FUNCTION
    // ==================
    // Run a PHP function
    // Returns the output of the function
    // Output is JSON encoded in Laravel and decoded in Playwright
    // The following examples call this function:
    // function sayHello($name) { return "Hello, $name!"; }
    const funcOutput = await laravel.callFunction('sayHello');
    // Run a PHP function with parameters
    await laravel.callFunction('sayHello', ['John']);
    // Run a PHP function with named parameters
    await laravel.callFunction('sayHello', { name: 'John' });
    // Run a static class method
    await laravel.callFunction("App\\MyAwesomeClass::method");

});
```

Dynamic Configuration
---------------------

[](#dynamic-configuration)

You can update Laravel config for **ALL** subsequent requests until the test ends.

```
import { test } from '@advalis/laravel-playwright';

test('example', async ({ laravel }) => {

    // SET DYNAMIC CONFIG
    // ==================
    // Update a config value
    // This value will be used in all subsequent requests sent to Laravel
    // until the test ends and calls `tearDown` (which is done automatically)
    await laravel.config('app.timezone', 'Europe/Paris');

    // TRAVEL TO A TIME
    // =================
    // Travel to a specific time in the application
    // This is similar to Laravel's `travelTo` method
    await laravel.travel('2022-01-01 12:00:00');

    // REGISTER A BOOT FUNCTION
    // ========================
    // Register a function to run while Laravel is booting
    // This is useful to mock a service dependency, for example
    await laravel.registerBootFunction('App\\E2EHelper::swapPaymentService');

});
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance58

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

272d ago

### Community

Maintainers

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

---

Top Contributors

[![waw3](https://avatars.githubusercontent.com/u/7088110?v=4)](https://github.com/waw3 "waw3 (1 commits)")

---

Tags

testinglaravele2eplaywright

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[hotmeteor/spectator

Testing helpers for your OpenAPI spec

3021.4M1](/packages/hotmeteor-spectator)[orchestra/workbench

Workbench Companion for Laravel Packages Development

8017.0M43](/packages/orchestra-workbench)[hyvor/laravel-playwright

Laravel and Playwright E2E Testing

3312.0k](/packages/hyvor-laravel-playwright)[guanguans/laravel-soar

SQL optimizer and rewriter for laravel. - laravel 的 SQL 优化器和重写器。

2227.8k](/packages/guanguans-laravel-soar)[spurwork/spectator

Testing helpers for your OpenAPI spec

3021.5k](/packages/spurwork-spectator)

PHPackages © 2026

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