Having been playing with Dusk for the last couple of days, I became aware that several people were trying to use it in a slightly different way from my approach. Several people were asking on the testing channel on Slack about how to get it working on Homestead. Having managed to get it running on Codeship, I thought that people would be able to simply apply the changes I had made on Homestead. Turned out there was a little more setup to do.
I have only quickly pieced this together in a single project environment, so there may be some subtleties I’ve missed. But I have got my tests running successfully with the following steps, so hopefully this will be of some assistance to people.
Installing the requirements on Homestead
After my experience with Codeship, I had a feeling that the issues would centre around getting chrome to run in a headless fashion on ubuntu. A quick google led me to this gist, from which I have cribbed shamelessly and without spending too much time digging into each component involved:
# makes sure all your repos are up to date sudo apt-get update# chrome dependencies I think sudo apt-get -y install libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4# chromium is what I had success with on Codeship, so seemed a good option sudo apt-get install chromium-browser# XVFB for headless applications sudo apt-get -y install xvfb gtk2-engines-pixbuf# fonts for the browser sudo apt-get -y install xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable# support for screenshot capturing sudo apt-get -y install imagemagick x11-apps
Once all this has run through, you need to fire up
xvfb on your homestead box. If you’re planning to do this on a regular basis, you’ll want to get this setup on boot, but for the sake of testing things out:
Xvfb -ac :0 -screen 0 1280x1024x16 &
Note the argument of
:0 which is consistent with the
DISPLAY setting in the Laravel call to chromedriver-linux (see
After these changes, I also did some work to change the capabilities called for by the
DuskTestCase as per my approach for the Codeship automation. But out of curiosity I rolled these back and was still able to run the tests successfully.
If you are still having problems, take a look at the post I wrote on Automation yesterday to see if these tweaks can help.