PHP package Laravel Dusk (initially released in April 2018) allows Laravel Framework applications to run browser tests with minimal configuration. The target browser can be configured but out-of-the-box it is setup to run tests in Google Chrome via Chromedriver. Well what about other web browsers?

Attempting to escape the far-reaching tentacles of surveillance capital, last year I uninstalled Chrome and replaced it with Mozilla Firefox and DuckDuckGo. But I still wished to locally run browsers tests on Laravel apps. Thankfully W3C’s WebDriver recommendation in June 2018 provided a clear path for other browsers to add automated testing. Geckodriver for Gecko-based browsers (including Firefox) has been stable since late 2019 so a Laravel Dusk integration is actually very easy now.

TLDR;

Add Firefox support by installing a package I have created. Run these commands to pull it into your project through Composer:

composer require --dev derekmd/laravel-dusk-firefox
php artisan dusk:install-firefox

Then run Laravel Dusk tests as normal:

php artisan dusk

This will direct browser tests to the Firefox browser you have installed on the local machine.

Why isn’t Firefox support part of Laravel Dusk?

This new package started as an exploratory dev branch meant for Laravel Dusk itself however I discovered the package depends on a feature that deviates from the W3C spec. Chromedriver and PhantomJS‘s headless browser implement additional end points from the Selenium spec. Geckodriver only covers the open WebDriver API which doesn’t have the commands.GetLog endpoint. Dusk uses it to capture JavaScript errors and write them to a debug .log file.

My “laravel/dusk” GitHub issue comments go into further detail on this. The Laravel Dusk feature (currently) is not covered in the official docs but the limitation led to a decision not to officially support Mozilla Firefox.

Thing is – you can still capture some JavaScript errors when running Geckodriver. Mozilla Firefox has a profile configuration for sending console output to the process’ stdout stream. In my package I made an effort to cleanup additional debugging so only JavaScript-related output is captured and written to the .log file. e.g., when a JS syntax error occurs.

Other Features

If you want to run tests in both Firefox and Google Chrome, the package supports this. Test suites running in continuous integration environments may also target either browser. Read more in the “derekmd/laravel-dusk-firefox” documentation on GitHub.