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

Dusk Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

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:

  • End-to-end (E2E) testing of user flows (authentication, form submissions, UI interactions).
  • Regression testing of critical paths (e.g., checkout, payment processing).
  • Visual regression testing via screenshots (e.g., screenshot() or elementScreenshot()).
  • Cross-browser testing (supports Chrome, Firefox, Edge via Selenium drivers).

Key Strengths:

  • Laravel-first design: Tight coupling with Laravel’s service container, Artisan, and testing utilities.
  • Modern PHP support: Actively maintained for PHP 8.4–8.5 and Laravel 10–13.
  • Pest integration: First-class support for Pest PHP (alternative to PHPUnit).
  • Headless/non-headless flexibility: Uses Chrome’s --headless=new by default (faster CI runs) but supports visual testing.

Potential Gaps:

  • Non-Laravel PHP apps: Requires Laravel’s testing infrastructure (e.g., Tests\CreatesApplication).
  • Mobile testing: Limited to desktop browsers (no native mobile emulation).
  • Performance overhead: Selenium-based tests are slower than unit tests (requires CI optimization).

Integration Feasibility

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:

  • Chromedriver: Auto-installed by Dusk but requires Docker or system-level permissions in CI.
  • PHP Extensions: pdo_sqlite, fileinfo (for Laravel’s testing utilities).
  • Browser Versions: Chrome/Edge/Firefox must match Chromedriver’s supported versions (e.g., Chrome 127+ for v8.5.0).

Technical Risk

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:

  1. CI Strategy: Will tests run in Docker containers, VMs, or local dev environments? (Affects Chromedriver setup.)
  2. Test Scope: Are tests limited to critical paths (low risk) or broad E2E coverage (higher flakiness)?
  3. Browser Matrix: Beyond Chrome, do you need Firefox/Edge? (Requires additional Selenium drivers.)
  4. Legacy Support: If using Laravel <10, are there breaking changes in Dusk v8.x?
  5. Pest vs. PHPUnit: Does the team prefer Pest’s syntax (e.g., test()->on($browser)) or PHPUnit’s structure?

Integration Approach

Stack Fit

Dusk is optimized for:

  • Laravel 10–13 (with PHP 8.4–8.5).
  • Testing Stack:
    • PHPUnit 12.x (default) or Pest 3.x (recommended for modern workflows).
    • Selenium WebDriver (via Chromedriver, FirefoxDriver, etc.).
    • Docker (for CI isolation; e.g., laravelsail or custom images).
  • CI/CD:
    • GitHub Actions, GitLab CI, or CircleCI with pre-configured Dusk workflows.
    • Parallelization: Pest’s --parallel or PHPUnit’s --group to reduce test time.

Anti-Patterns:

  • Mixed with non-Laravel apps: Dusk assumes Laravel’s service container and Artisan.
  • Overuse in CI: E2E tests should be gated (e.g., run nightly or on feature branches).

Migration Path

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:

  1. Add Dusk to composer.json:
    "require-dev": {
        "laravel/dusk": "^8.5",
        "pestphp/pest": "^3.0" // Optional
    }
    
  2. Install and Configure:
    composer require --dev laravel/dusk
    php artisan dusk:install
    
  3. Write a Test (Pest example):
    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');
        });
    });
    
  4. Run Locally:
    php artisan serve
    php artisan dusk
    
  5. CI Setup (GitHub Actions):
    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
    

Compatibility

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.
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