laravel/dusk
Laravel Dusk is Laravel’s browser automation and testing tool, offering an expressive API for end-to-end tests. It runs with a bundled standalone ChromeDriver by default (no Selenium or JDK required), but can use other Selenium drivers if needed.
Laravel Dusk is a native fit for Laravel-based applications, offering seamless integration with the Laravel ecosystem. It leverages Laravel’s testing utilities (e.g., Tests\CreatesApplication) and integrates tightly with PHPUnit/Pest for test execution. The package’s architecture is modular, allowing for:
Laravel\Dusk\Page for maintainable test structures.Key strengths:
| Factor | Feasibility | Notes |
|---|---|---|
| Laravel Version | High | Supports LTS versions (10–13); drops legacy support (e.g., PHPUnit 9). |
| Testing Framework | High | Native PHPUnit/Pest integration; minimal setup for Laravel’s phpunit.xml. |
| CI/CD | High | Dockerized Chromedriver reduces setup complexity; CI-friendly (GitHub Actions, GitLab CI). |
| Monorepo/Modular Apps | Medium | Assumes monolithic Laravel structure; may require customization for microservices. |
| Legacy Systems | Low | Requires Laravel 8+; not suitable for non-Laravel PHP apps. |
Dependencies:
| Risk Area | Severity | Mitigation |
|---|---|---|
| Browser Driver Stability | Medium | Use bundled Chromedriver; monitor for Chrome/Chromedriver version conflicts. |
| Flaky Tests | High | Implement retry logic (e.g., waitFor()), avoid race conditions in async UI updates. |
| CI Environment Setup | Medium | Containerize tests (Docker) or use Laravel’s dusk:chrome-driver command. |
| Maintenance Overhead | Low | Active development (MIT license); align with Laravel’s release cycle. |
| Performance | Medium | Parallelize tests with Pest; optimize Chromedriver memory usage. |
Critical Questions for TPM:
waitFor() or custom assertions.| Component | Compatibility | Notes |
|---|---|---|
| Laravel Core | Native | Uses Tests\CreatesApplication, Artisan, and service container. |
| PHPUnit | High | Supports v12; includes stubs for phpunit.xml. |
| Pest | High | First-class support; Pest 3+ recommended. |
| Docker | High | Official Docker images for Chromedriver; CI-friendly. |
| Vue/React | Medium | Works with SPAs but may need waitFor() for async renders. |
| Tailwind CSS | High | No impact; tests interact with rendered HTML. |
| API Testing | Low | Dusk is UI-focused; pair with Laravel’s HTTP tests for backend coverage. |
Assessment Phase:
composer require laravel/dusk --dev).Setup:
composer require --dev laravel/dusk
php artisan dusk:install
phpunit.xml or pest.php to include Dusk tests..env.dusk for browser-specific configs (e.g., DUSK_DRIVER=chrome).Incremental Adoption:
CI/CD Integration:
- name: Run Dusk Tests
run: php artisan dusk
FROM laravel/dusk:latest
| Scenario | Compatibility | Workaround |
|---|---|---|
| Laravel 10–13 | Native | No changes needed. |
| PHP 8.4–8.5 | Native | Dusk v8.x+ supports both. |
| Pest Framework | Native | Use @test syntax; Pest 3+ recommended. |
| Custom Authentication | Medium | Extend DuskTestCase or use middleware in tests. |
| Headless Mode | Native | DUSK_HEADLESS=true in .env. |
| Multi-Tenancy | Medium | Use DuskTestCase::withSession() or custom test classes. |
| Visual Regression | Low | Integrate with tools like Percy or custom screenshot diffing. |
Prerequisites:
Order of Implementation:
Parallelization:
--parallel) for faster execution.UserTests, AdminTests).| Aspect | Effort | Notes |
|---|---|---|
| Test Updates | Medium | UI changes may break tests; use Page Objects to isolate selectors. |
| Chromedriver Updates | Low | Laravel Dusk auto-updates drivers; monitor for breaking changes. |
| Dependency Bloat | Low | Bundled Chromedriver reduces external deps; minimal runtime overhead. |
| Debugging | Medium | Screenshots/logs (php artisan dusk --screenshot) help diagnose flaky tests. |
Maintenance Tasks:
| Issue Type | Resolution Path |
|---|---|
| Flaky Tests | Add retries (waitFor()), isolate tests, or use try/catch for transient errors. |
| Browser Compatibility | Update Chromedriver or add Firefox/Edge drivers via DUSK_DRIVER_URL. |
| CI Failures | Debug with DUSK_DEBUG=true; check Docker resource limits. |
| Performance | Profile |
How can I help you explore Laravel packages today?