How to disable headless mode in Laravel 5.5 (Dusk 2.0)?
Now Laravel 5.5 uses Dusk 2.0 with headless mode active by default. Anybody know how to change this to execute Laravel Dusk tests like before (seeing the browser opening and executing tests)?
One small thing to remember, don't use env() calls in your code. env() should only be called from your config files, and then use the config() call in your code. Otherwise you will run into issues if you try and cache your config values.
For anyone landing here in 2023, using Laravel 10, just add an env variable :
DUSK_HEADLESS_DISABLED=true
Then change your DuskTestCase file's hasHeadlessDisabled function as follows:
protected function hasHeadlessDisabled() : bool
{
return env('DUSK_HEADLESS_DISABLED', false);
}
You will see the browser again. This also helps you not change the DuskTestCase file which you need to change again before committing if you are running your tests in CI.
Make sure to set the value to false in your .env.ci or your GitHub actions secrets.