laravel/dusk
Laravel Dusk is Laravel’s browser automation and end-to-end testing tool, offering a clean, expressive API for driving real browsers. Runs with a bundled standalone Chromedriver by default (no Selenium/JDK required), but supports other drivers too.
Laravel Dusk is a native fit for Laravel-based applications, offering seamless integration with the Laravel ecosystem. It leverages Laravel’s testing utilities (PHPUnit/Pest) and follows Laravel’s conventions (e.g., Tests/Browsers directory structure). The package abstracts Selenium/Chromedriver complexity behind a fluent API, making it ideal for:
screenshot() or elementScreenshot()).Key Strengths:
--headless=new by default (faster CI runs) but supports visual testing.Potential Gaps:
Tests\CreatesApplication).| Aspect | Feasibility | Notes |
|---|---|---|
| Laravel Compatibility | ⭐⭐⭐⭐⭐ | Works out-of-the-box with Laravel 10–13. Backward-compatible with older versions. |
| PHPUnit/Pest | ⭐⭐⭐⭐⭐ | Supports both frameworks; Pest integration is polished (e.g., uses(DuskTestCase)). |
| CI/CD | ⭐⭐⭐⭐ | Requires Docker/VMs for Chromedriver (or headless Chrome). GitHub Actions/GitLab CI templates available. |
| Monorepos | ⭐⭐⭐ | Assumes standard Laravel directory structure; may need path adjustments in monorepos. |
| Legacy Systems | ⭐⭐ | Older Laravel versions (<9.x) may need polyfills or manual driver config. |
Critical Dependencies:
pdo_sqlite, fileinfo (for Laravel’s testing utilities).| Risk Area | Severity | Mitigation |
|---|---|---|
| Flaky Tests | High | Use waitFor() assertions, disable animations (--disable-gpu --no-sandbox), and run in CI containers. |
| CI Setup Complexity | Medium | Template: GitHub Actions for Dusk. |
| Browser Driver Issues | Medium | Pin Chromedriver versions in composer.json or use DUSK_DRIVER_URL for custom drivers. |
| Performance | Medium | Parallelize tests with Pest’s --parallel or PHPUnit’s --group. |
| Visual Regression | Low | Use screenshot() with baseline comparisons (e.g., Applitools integration). |
Key Questions for TPM:
test()->on($browser)) or PHPUnit’s structure?Dusk is optimized for:
laravelsail or custom images).--parallel or PHPUnit’s --group to reduce test time.Anti-Patterns:
| Phase | Actions | Tools/Commands |
|---|---|---|
| Setup | Install Dusk: composer require --dev laravel/dusk. |
composer require |
| Configuration | Publish Dusk assets: php artisan dusk:install. Configure DUSK_BROWSER in .env. |
php artisan dusk:install |
| Test Infrastructure | Set up Chromedriver (auto-installed or manual). Configure CI with Docker. | php artisan dusk:chrome-driver |
| Test Development | Write tests in tests/Browser. Use DuskTestCase or PestTestCase. |
php artisan make:dusk TestName |
| CI Integration | Add Dusk to CI workflow (e.g., GitHub Actions). Use php artisan dusk or ./vendor/bin/pest. |
Custom CI script or template |
| Optimization | Parallelize tests, cache dependencies, and optimize Chromedriver. | Pest --parallel, Docker layer caching |
Example Migration Steps:
composer.json:
"require-dev": {
"laravel/dusk": "^8.5",
"pestphp/pest": "^3.0" // Optional
}
composer require --dev laravel/dusk
php artisan dusk:install
use Laravel\Dusk\TestCase;
test('login test', function () {
$this->browse(function (Browser $browser) {
$browser->visit('/login')
->type('email', 'user@example.com')
->type('password', 'password')
->press('Login')
->assertPathIs('/dashboard');
});
});
php artisan serve
php artisan dusk
jobs:
test:
runs-on: ubuntu-latest
services:
chrome:
image: selenium/standalone-chrome:latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
- run: composer install
- run: php artisan dusk
| Component | Compatibility | Notes |
|---|---|---|
| Laravel Versions | 10–13 (full) | v8.5.0 explicitly supports Laravel 13; v8.2.14+ supports Laravel 12. |
| PHP Versions | 8.4–8.5 | PHP 8.5 compatibility added in v8.3.4; PHP 8.3 in v8.2.12. |
| PHPUnit | 12.x | v8.3.0+ supports PHPUnit 12.2; v8.2. |
How can I help you explore Laravel packages today?