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

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

hyvor/laravel-playwright
========================

Laravel and Playwright E2E Testing

2.0.2(1y ago)3419.9k↑53.3%5[1 issues](https://github.com/hyvor/laravel-playwright/issues)[2 PRs](https://github.com/hyvor/laravel-playwright/pulls)MITPHPPHP &gt;=8.2CI passing

Since May 28Pushed 1y ago3 watchersCompare

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

READMEChangelog (9)Dependencies (4)Versions (19)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 hyvor/laravel-playwright
```

On Playwright side, install the package via npm:

```
npm install @hyvor/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 '@hyvor/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 `@hyvor/laravel-playwright`.

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

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

> **Note**: In practise, it is not recommended to import from `@hyvor/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 `@hyvor/laravel-playwright` and import that fixture in your tests.

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

[](#basic-usage)

```
import { test } from '@hyvor/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 '@hyvor/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

44

—

FairBetter than 90% of packages

Maintenance41

Moderate activity, may be stable

Popularity40

Moderate usage in the ecosystem

Community13

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 97% 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 ~81 days

Recently: every ~15 days

Total

9

Last Release

479d ago

Major Versions

0.0.1 → 1.0.02024-04-03

1.0.0 → 2.0.1-beta12024-08-03

1.0.1 → 2.0.1-beta22025-01-10

PHP version history (3 changes)0.0.1PHP ^8.1 || ^8.2

1.0.0PHP ^8.2 || ^8.3

2.0.1-beta2PHP &gt;=8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/53796347?v=4)[HYVOR](/maintainers/HYVOR)[@hyvor](https://github.com/hyvor)

---

Top Contributors

[![supun-io](https://avatars.githubusercontent.com/u/44988673?v=4)](https://github.com/supun-io "supun-io (32 commits)")[![Konafets](https://avatars.githubusercontent.com/u/363363?v=4)](https://github.com/Konafets "Konafets (1 commits)")

---

Tags

testinglaravele2eplaywright

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[laracasts/testdummy

Easy test stubs

4671.4M38](/packages/laracasts-testdummy)[davestewart/sketchpad

An innovative front-end environment for interactive Laravel development

29512.9k1](/packages/davestewart-sketchpad)[guanguans/laravel-soar

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

2248.4k](/packages/guanguans-laravel-soar)[srlabs/laravel-testing-utilities

Helper utilities for testing Laravel Applications

1011.9k](/packages/srlabs-laravel-testing-utilities)

PHPackages © 2026

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