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 !
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 meBTC
18SY81ejLGFuJ9KMWQu5zPrDGuR5rDiauM
ETH
0x519e0eaa9bc83018bb306880548b79fc0794cd08
XMR
895bSneY4eoZjsr2hN2CAALkUrMExHEV5Pbg8TJb6ejnMLN7js1gLAXQySqbSbfzjWHQpQhQpvFtojbkdZQZmM9qCFz7BXU
2024 © My Dynamic Production SRL All rights Reserved.