CI for Laravel

Testing with Laravel Dusk

Laravel Dusk uses the Chrome browser (in headless mode) to run tests against the rendered HTML/Javascript of your application.

🔴 This documentation is for accounts created before February 28th, 2023 (if you have not moved to the newer "Fly" build system).

Setting up Dusk in Chipper CI

Dusk sends web requests to the port defined in either APP_URL or APP_DOMAIN environment variables. We'll assume port 8000 will be used for the web server.

This requires the following setup.

1. Environment Variables

Dusk will only read environment variables from a .env or .env.dusk.{environment} file.

Be sure your .env or .env.dusk.{environment} file includes APP_URL and, optionally, APP_DOMAIN environment variables.


Note that if your repository includes a .env.dusk.* file, this will override other environment variables. Be sure that if this file exists, it has the correct APP_URL and/or APP_DOMAIN configured and that you use the --env flag in your php artisan dusk command to match this file.

This environment behavior for Dusk tests is explained further in the environment precedence documentation.

Because Dusk only reads from the .env or .env.dusk.{environment} file, it will need to contain database/cache connection details (as documented here). For example:

# These should be included in your .env file
# This example is if you're using MySQL/MariaDB


2. Pipeline Step

Dusk requires a web server to be running in order to send web requests to it.

Please use the following script to run your Dusk tests:

# Important: Update the chrome driver version to the build container's
# current version of google-chrome
GOOGLE_CHROME_VERSION=`google-chrome --version | cut -d " " -f3 | cut -d "." -f1`
php artisan dusk:chrome-driver $GOOGLE_CHROME_VERSION

# Listen on port 8000 for web requests
# Use this instead of "php artisan serve"
php -S -t public 2>/dev/null &

php artisan dusk

You can tweak this as needed, for example if you want to set a specific environment to Dusk: php artisan dusk --env=ci