- How do I install Laravel Dusk in a Laravel 13 project?
- Run `composer require --dev laravel/dusk` and publish the config with `php artisan dusk:install`. This sets up the `Tests/Browser` directory and configures Dusk to use Chrome by default. Ensure your `php.ini` includes `pdo_sqlite` and `fileinfo` extensions.
- Can I use Laravel Dusk with Pest instead of PHPUnit?
- Yes, Dusk fully supports Pest. Replace `uses(DuskTestCase)` with `uses(DuskTestCase)->in('pest')` in your test classes. Pest’s syntax (e.g., `test('login', fn () => ...)`) works seamlessly with Dusk’s browser methods like `browse()` and `visit()`.
- What Laravel versions does Dusk support?
- Dusk officially supports Laravel 10–13. For Laravel 9.x, use Dusk v7.x; older versions may require manual Chromedriver configuration. Check the [Laravel docs](https://laravel.com/docs/dusk) for version-specific setup guides.
- How do I run Dusk tests in GitHub Actions without flakiness?
- Use a Docker container with Chrome and Chromedriver pre-installed (e.g., `mcr.microsoft.com/playwright/chromium`). Add `--headless=new` to your Chrome flags and use `waitFor()` assertions to handle dynamic content. Example: `DUSK_DRIVER_CHROME_OPTIONS='--no-sandbox --disable-gpu'`.
- Can I test Firefox or Edge with Dusk?
- Yes, but you’ll need to install the respective Selenium drivers (e.g., `geckodriver` for Firefox). Configure the driver in `.env` with `DUSK_DRIVER=firefox` and set `DUSK_DRIVER_URL` to the driver’s path. Firefox requires additional flags like `--marionette`.
- How do I compare screenshots for visual regression testing?
- Use `screenshot()` in your test to capture an element or page, then compare it against a baseline (e.g., `assertScreenshotMatches($path)`). Tools like Applitools or custom scripts can automate baseline updates. Store baselines in `tests/Browser/screenshots/`.
- Why are my Dusk tests failing intermittently in CI?
- Flakiness often stems from race conditions or slow network requests. Use `waitFor()` with selectors (e.g., `waitFor('.button')->toBeVisible()`) and disable animations with Chrome flags (`--disable-gpu --no-sandbox`). Run tests in headless mode for consistency.
- Do I need JDK or Selenium Server for Dusk?
- No, Dusk bundles Chromedriver by default and doesn’t require JDK or a standalone Selenium Server. It uses a direct WebDriver connection. For other browsers (Firefox/Edge), you’ll need their respective drivers but no Selenium Server.
- How can I parallelize Dusk tests to speed up CI?
- Use Pest’s `--parallel` flag or PHPUnit’s `--group` to split tests across workers. Configure your CI to run multiple containers with shared storage for screenshots. Example: `pest --parallel --workers=4`. Avoid parallelizing tests that modify shared state.
- What’s the best alternative to Dusk for Laravel E2E testing?
- Consider **Playwright** (via `laravel-playwright`) for cross-browser testing with better mobile emulation, or **Cypress** (with custom Laravel integration). Playwright supports Chromium, Firefox, and WebKit natively, while Cypress offers real-time debugging. Dusk remains simpler for Laravel-specific workflows.