Dusk: Failed to connect to localhost port 9515: Connection refused

Created on 3 Jun 2019  ·  9Comments  ·  Source: laravel/dusk

  • Dusk Version: 5.1.0
  • Laravel Version: 5.8.19
  • PHP Version: 7.3.4
  • Database Driver & Version: no database used

Description:

With new Laraval and Dusk install, 'php artisan dusk' fails with 'Failed to connect to localhost port 9515: Connection refused'.

Steps To Reproduce:

Windows 10 Pro 1809 17763.529 host
VirtualBox: 6.0.8-130520
Vagrant: 2.2.4

New Install
// Removed all previous boxes and VirtualBox VMs
vagrant box add laravel/homestead --box-version=7.2.1
git checkout v8.5.5
./init.bat
// Edited Homestead.yaml folders and sites
// Added virtual hosts to C:\Windows\System32\drivers\etc\hosts
vagrant up --provision

// In VirtualBox Homestead VM,
composer create-project --prefer-dist laravel/laravel laravel-latest
// Laravel v5.8.19 installed.
// In .env, set APP_URL=http://laravel-latest.local
vagrant@homestead:~/code$ ping laravel-latest.local
PING laravel-latest.local (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.019 ms

// Site http://laravel-latest.local loads fine on Chrome and Firefox (both from Windows).

vagrant@homestead:~/code/laravel-latest$ phpunit
PHPUnit 7.5.12 by Sebastian Bergmann and contributors.
.. 2 / 2 (100%)
Time: 1.86 seconds, Memory: 14.00 MB
OK (2 tests, 2 assertions)

vagrant@homestead:~/code/laravel-latest$ composer require --dev laravel/dusk
1/3: http://repo.packagist.org/p/provider-latest$9c83c7223326d76be2c66f5037e654d1262e6cdabc6a44cd41c21bcb00b52cab.json
2/3: http://repo.packagist.org/p/provider-2019-04$791bf93a6143c7c753dafb79b165fef2bcfc0b028b685b55c2de65710ff81fb5.json
3/3: http://repo.packagist.org/p/provider-2019-01$015cb94160eed3cccc28a2fd376e1fe63e5c508004a379250351d23e64f0d437.json
Finished: success: 3, skipped: 0, failure: 0, total: 3
Using version ^5.1 for laravel/dusk
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
1/2: https://codeload.github.com/facebook/php-webdriver/legacy.zip/bd8c740097eb9f2fc3735250fc1912bc811a954e
2/2: https://codeload.github.com/laravel/dusk/legacy.zip/a6ac3e6489dc774445aa9459cdc332104591634a
Finished: success: 2, skipped: 0, failure: 0, total: 2
Package operations: 2 installs, 0 updates, 0 removals

  • Installing facebook/webdriver (1.6.0): Loading from cache
  • Installing laravel/dusk (v5.1.0): Loading from cache
    facebook/webdriver suggests installing ext-SimpleXML (For Firefox profile creation)
    Writing lock file
    Generating optimized autoload files

Illuminate\Foundation\ComposerScripts::postAutoloadDump
@php artisan package:discover --ansi
Discovered Package: beyondcode/laravel-dump-server
Discovered Package: fideloper/proxy
Discovered Package: laravel/dusk
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.

vagrant@homestead:~/code/laravel-latest$ php artisan dusk:install
Dusk scaffolding installed successfully.
Downloading ChromeDriver binaries...
ChromeDriver binaries successfully installed for version 74.0.3729.6.

vagrant@homestead:~/code/laravel-latest$ php artisan dusk
PHPUnit 7.5.12 by Sebastian Bergmann and contributors.

E 1 / 1 (100%)

Time: 1.68 seconds, Memory: 14.00 MB

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","chromeOptions":{"binary":"","args":["--disable-gpu","--headless","--window-size=1920,1080"]}}}

Failed to connect to localhost port 9515: Connection refused

/home/vagrant/code/laravel-latest/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:292
/home/vagrant/code/laravel-latest/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:126
/home/vagrant/code/laravel-latest/tests/DuskTestCase.php:40
/home/vagrant/code/laravel-latest/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:192
/home/vagrant/code/laravel-latest/vendor/laravel/framework/src/Illuminate/Support/helpers.php:816
/home/vagrant/code/laravel-latest/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:193
/home/vagrant/code/laravel-latest/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:93
/home/vagrant/code/laravel-latest/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:64
/home/vagrant/code/laravel-latest/tests/Browser/ExampleTest.php:21

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

// No screenshot files created.

// Try chromedriver directly…
vagrant@homestead:~/code/laravel-latest$ vendor/laravel/dusk/bin/chromedriver-linux
vendor/laravel/dusk/bin/chromedriver-linux: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

// Try installing libnss3 in homestead linux
vagrant@homestead:~/code/laravel-latest$ sudo apt-get update
vagrant@homestead:~/code/laravel-latest$ sudo apt-get install libnss3

// Run dusk again. Error changes...
vagrant@homestead:~/code/laravel-latest$ php artisan dusk
PHPUnit 7.5.12 by Sebastian Bergmann and contributors.

E 1 / 1 (100%)

Time: 2.02 seconds, Memory: 14.00 MB

There was 1 error:

1) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\UnknownServerException: unknown error: cannot find Chrome binary
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 4.15.0-47-generic x86_64)

/home/vagrant/code/laravel-latest/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:114
/home/vagrant/code/laravel-latest/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:326
/home/vagrant/code/laravel-latest/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:126
/home/vagrant/code/laravel-latest/tests/DuskTestCase.php:40
/home/vagrant/code/laravel-latest/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:192
/home/vagrant/code/laravel-latest/vendor/laravel/framework/src/Illuminate/Support/helpers.php:816
/home/vagrant/code/laravel-latest/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:193
/home/vagrant/code/laravel-latest/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:93
/home/vagrant/code/laravel-latest/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:64
/home/vagrant/code/laravel-latest/tests/Browser/ExampleTest.php:21

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

// Run chromedriver directly again
vagrant@homestead:~/code/laravel-latest$ vendor/laravel/dusk/bin/chromedriver-linux
Starting ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}) on port 9515
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.

bug needs more info

Most helpful comment

Homestead no longer supports Dusk out of the box.

You can install the required packages manually:

sudo apt-get update
sudo apt-get -y install libnss3 chromium-browser

Enabling the webdriver feature in Homestead.yaml should also work, but doesn't for me:

webdriver: true

All 9 comments

Pretty much in the dark at what's going on here. I can't even get the basic example of Dusk to run atm. Getting:

http:\/\/localhost:9515\/ - Failed to load resource: the server responded with a status of 404 (Not Found)

Any help with figuring this out if much appreciated.

Homestead no longer supports Dusk out of the box.

You can install the required packages manually:

sudo apt-get update
sudo apt-get -y install libnss3 chromium-browser

Enabling the webdriver feature in Homestead.yaml should also work, but doesn't for me:

webdriver: true

The webdriver feature will be fixed in the next release: https://github.com/laravel/homestead/pull/1177

@grwbond can you try the next version of Homestead to see if that fixes your problem?

Upgrading to 8.0.0-alpha2 did not fix the problem, however sudo apt-get -y install chromium-browser did resolve the issue. All green now on ExampleTest.php.

Thank you Dries and Jonas.

Doing @staudenmeir update worked for me. I had been using dusk and just tried today for the first time in a while and got this error.

Tests are running again.

Well almost. It's not pulling the correct DB connection. I specified SQLlite in my .env.dusk.local file, but it's trying to login with mysql all of a sudden. That's new.

What's weirder is even if I default all env variables to the laravel dusk sqllite setup, it still tries to pull default MySQL settings.

1) Tests\Browser\ExampleTest::testExample
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"w3c":false,"binary":"","args":["--disable-gpu","--headless","--window-size=1920,1080"]}}}

Failed to connect to localhost port 9515: Connection refused
ERRORS!

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

Hi
I encounter the same issue, I google and try some way they are won't work, eventually, I just run the same command then it works

➜ social git:(master) php artisan dusk
PHPUnit 8.5.2 by Sebastian Bergmann and contributors.

. 1 / 1 (100%)

Time: 3.03 seconds, Memory: 18.00 MB

OK (1 test, 1 assertion)

Running php artisan dusk:install and then re-opening my terminal window to re-run the test suite (via php artisan dusk) resolved the issue for me 👍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

godruoyi picture godruoyi  ·  6Comments

joanlopez picture joanlopez  ·  5Comments

bruno-barros picture bruno-barros  ·  6Comments

digitlimit picture digitlimit  ·  4Comments

guirociozanini picture guirociozanini  ·  6Comments