Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Pest Plugin Browser Laravel Package

pestphp/pest-plugin-browser

Pest Plugin for Browser adds browser testing capabilities to Pest, helping you write expressive end-to-end tests for your PHP applications. Part of the Pest ecosystem—see pestphp.com for docs and setup guidance.

View on GitHub
Deep Wiki
Context7

Getting Started

Install the plugin via Composer (composer require pestphp/pest-plugin-browser --dev), then run pest --init to scaffold the initial Pest setup if not already done. This plugin enables asynchronous browser interaction testing—ideal for real-time UI validation (e.g., WebSocket-driven Livewire apps or real-time dashboards). First use case: test that a Livewire component emits an event when a user types in an input field—without stubbing or waiting for full page reloads.

Implementation Patterns

  • Use browser()->connect() to establish a WebSocket connection to your app (typically the test server started via pest()->beforeEach(fn () => $this->startServer())).
  • Chain methods like browser()->waitForText('Hello') or browser()->emit('event-name', ['data' => 'value']) inside test closures for reactive UI assertions.
  • Pair with pestphp/pest-plugin-laravel to leverage Laravel’s testing helpers (e.g., actingAs()) before opening the browser connection.
  • For integration, start an HTTP/WebSocket server in tests/BrowserTest.php (or a base test class), then broadcast events using Browser::emit() or consume them with browser()->on('event', fn (...) => ...).
  • Example workflow:
    it('updates live chat message', function () {
        $user = User::factory()->create();
        $this->actingAs($user)->get('/chat');
    
        browser()->connect('ws://localhost:8080/chat')
            ->emit('message', ['text' => 'Hi!'])
            ->waitForText('Hi!')
            ->assertSee('Hi!');
    });
    

Gotchas and Tips

  • Requires ext-sockets and PHP 8.3+—verify this in your environment before installing.
  • The plugin uses Amp’s async HTTP/WebSocket server—ensure your test server doesn’t block; run in background or use defer/async where applicable.
  • Connection timeouts are common—extend default timeout via browser()->withTimeout(10) if testing slow endpoints.
  • Debug connection issues by enabling verbose logging: Pest::beforeEach(fn () => $this->app->make('log')->setLogLevel('debug')).
  • You must start your app’s WebSocket endpoint manually in tests (e.g., via Artisan::call('websockets:serve'))—this plugin does not auto-start backend servers.
  • The plugin’s maturity is low (only README docs); inspect the source at src/ for under-documented features like browser()->broadcast() or onBroadcast().
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport