How to use Laravel Dusk with Homestead on a Windows machine

profile picture

How to use Laravel Dusk with Homestead on a Windows machine

Alongside Laravel 5.4 update, a new tool came up : Laravel Dusk.

If you were used to run tests on your Laravel application, and particularly "Feature tests", you are most likely used to write test cases in which you can actually fill forms, click buttons, and expect to see a specific result.

After upgrading your Laravel application to 5.4, all those nice method (visits, clicks, etc.) are gone. They were moved to a new Laravel package : Laravel Dusk.

Why ?

Because Dusk can actually test javascript based actions and results, so you can now unittest that.

Now, if you are a windows user and you use Homestead for your local development, you'll have some issues with Dusk.

That is because your VM cannot properly open a browser and run the tests as it should be on a normal environement.

Solution in few lines :

SSH into homestead

vagrant ssh

Execute these lines

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg โ€“i google-chrome-stable_current_amd64.deb
apt-get install -y xvfb

Edit vendor/laravel/dusk/src/SupportsChrome.php. I know it's bad, but for now it's the only solution. We need to wait for a package update.

From :

    // Line 51
    ->setPrefix(realpath(__DIR__.'/../bin/chromedriver-'.static::driverSuffix()))

To :

    ->setPrefix('xvfb-run')
    ->setArguments([realpath(__DIR__.'/../bin/chromedriver-'.static::driverSuffix())])

Now try to run php artisan dusk again, and it should work correctly.

Note : I was using the last version of Homestead.

I hope it will work for you, and I hope the package will be fixed soon. Happy testing !

about me

profile picture

I consider myself as an IT Business Artisan. Or Consultant CTO. I'm a self-taught Web Developper, coach and teacher. My main work is helping and guiding digital startups.

more about me

follow me

newsletter

A weekly email with the latests articles

support my work

Start trading on binance
  • BTC

    BTC

    bc1qgw9a8hyqqwvcls9ln7vhql4mad0qkveutr2td7

  • ETH

    ETH

    0x3A720717Da03dB6f3c4a4Ff08BC64100205A79d0

2025 © My Dynamic Production SRL All rights Reserved.