Using Laravel Dusk with Vagrant Homestead

If you are using Laravel Homestead and you want to use Laravel Dusk to test your application, you can find some problems.

For example, if you create a basic test


namespace Tests\Browser;

use Laravel\Dusk\Browser;
use Tests\DuskTestCase;

class ExampleTest extends DuskTestCase
     * A basic browser test example.
     * @return void
    public function testBasicExample()
        $this->browse(function (Browser $browser) {
                ->assertSee('Forgot your password?');;

When you try to execute it, you can get an error

$ php artisan dusk
PHPUnit 5.7.13 by Sebastian Bergmann and contributors.

E 1 / 1 (100%)

Time: 1.23 seconds, Memory: 10.00MB

There was 1 error:

1) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY"}}

Failed to connect to localhost port 9515: Connection refused


Tests: 1, Assertions: 0, Errors: 1.

To resolve it, you have to install google-chrome in the Vagrant Homestead machine:

$ wget -q -O - | sudo apt-key add -
$ sudo sh -c 'echo "deb [arch=amd64] stable main" >> /etc/apt/sources.list.d/google-chrome.list'
$ sudo apt-get update && sudo apt-get install -y google-chrome-stable

Then you have to install Xvfb

$ sudo apt-get install -y xvfb

Then you have to start the ChromeDriver. Your current directory must be the main directory of your project

$ ./vendor/laravel/dusk/bin/chromedriver-linux --port=8888

Starting ChromeDriver 2.25.426924 (649f9b868f6783ec9de71c123212b908bf3b232e) on port 8888
Only local connections are allowed.

Then add the project to the /etc/hosts in your Vagrant Homestead machine

Open another SSH connection to the Vagrant Homestead machine and execute

$ Xvfb :0 -screen 0 1280x960x24 &

to run the xvfb server.

Return to the first console and execute the tests

$ php artisan dusk
PHPUnit 5.7.13 by Sebastian Bergmann and contributors.

. 1 / 1 (100%)

Time: 4.79 seconds, Memory: 10.00MB

OK (1 test, 2 assertions)

Now you can see the tests in execution.



  1. is including port? my application run on (show home page)

  2. No, I include the “” string in the “/etc/hosts” file in my Vagrant Homestead virtual machine without any port, because I use the default port on the nginx server.

  3. for some reason I cannot run ‘./vendor/laravel/dusk/bin/chromedriver-linux –port=8888’ i.e. permission denied

    so i need to run this chmod
    chmod 755 vendor/laravel/dusk/bin/*

    the rest are the same

    virtualbox 5.1.22
    vagrant 1.95
    laravel 5.4 (upgraded from 5.3)

  4. I have the same issue but my website is not running under a virtual machine elsewhere in my own.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.