laravel/browser-kit-testing
Fluent BrowserKit-style testing for Laravel apps: make HTTP requests, navigate pages, assert response content, and interact with forms in functional tests. Install as a dev dependency and extend Laravel\BrowserKitTesting\TestCase to get started.
Http, DatabaseMigrations, RefreshDatabase), making it a natural choice for Laravel-centric projects.BaseTestCase) and a Composer install, reducing friction for adoption.--dev dependency, avoiding runtime overhead.Why BrowserKit?
Future-Proofing
Testing Scope
CI/CD Impact
visit(), type(), press()).assertSee, assertOldInput).TestCase class in one module at a time.composer.json for exact ranges).laravel/browsershot) may conflict; test in isolation.composer require laravel/browser-kit-testing --dev
Tests/TestCase.php to extend Laravel\BrowserKitTesting\TestCase.php artisan test
or via CI (e.g., GitHub Actions).--dev).composer.json to avoid surprises:
"laravel/browser-kit-testing": "^1.0"
assertSee matching wrong elements).actingAs() is used).dd($response->getContent()) to inspect raw responses.RefreshDatabase for non-DB tests.withoutMiddleware() for performance-critical tests.phpunit --group instead).browserkit) to track legacy tests separately.jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: composer install
- run: php artisan test --group=legacy
| Failure Type | Root Cause | Mitigation |
|---|---|---|
| Test Flakiness | Dynamic content (e.g., timestamps) | Use assertStringContains instead of exact matches. |
| CSRF Token Errors | Missing actingAs() or withSession() |
Ensure authentication is mocked. |
| Deprecated Methods | Laravel updates remove BrowserKit APIs | Subscribe to Laravel’s RFCs. |
| HTML Structure Changes | Frontend refactors break assertions | Use assertStringContains or CSS selectors. |
| Timeouts | Slow database queries | Optimize tests with withoutEvents(). |
CONTRIBUTING.md.// BrowserKit Example
$this->visit('/login')
->type('email@example.com', 'email')
->type('password', 'password')
->press('Login')
->assertSee('Dashboard');
// Native Laravel Alternative
$response = $this->post('/login', [
'email' => 'email@example.com',
'password' =>
How can I help you explore Laravel packages today?