Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kayaker323's avatar

Laravel dusk - won't run via sail dusk or php artisan test

I'm having some issues and have exhausted my research.

My challenges are as follows:

sail dusk hangs and doesn't complete. My only browser test is:

<?php

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) {
            $browser->visit('/login')
                    ->assertSee('Email')
                    ->assertSee('Password');
        });
    }
}

Running tests via php artisan dusk gives me the following error for all tests:

Caused by
PDOException: PDO::__construct(): php_network_getaddresses: getaddrinfo for mysql failed: nodename nor servname provided, or not known

My .env file where it relates to database connection:

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel
FORWARD_DB_PORT=3306
DB_USERNAME=sail
DB_PASSWORD=password

I have the same issue when executing php artisan migrate. I'm not sure if it's possible to configure a your dev environment such that local commands like migrate that rely on a db connection can work locally connecting to the db container just as well as when using sail artisan migrate

php artisan test has the same problem (I added the Browser folder to phpunit.xml manifest so standard test runs both feature and browser tests).

When I try to run sail artisan test, all my non-browser tests work fine, but as soon as it hits the browser tests, I get the error:

  Curl error thrown for http POST to /session with params: {"capabilities":{"firstMatch":[{"browserName":"chrome","goog:chromeOptions":{"args":["--window-size=1920,1080","--disable-gpu","--headless"]}}]},"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"args":["--window-size=1920,1080","--disable-gpu","--headless"]}}}

Failed to connect to localhost port 9515 after 0 ms: Connection refused

I've tried installing chrome / chromium in the sail container using apt-get and sail root-shell but this didn't resolve the issue.

Hoping for help as I'm stumped!

0 likes
6 replies
kayaker323's avatar

I'm going to ignore sail artisan test, php artisan test and php artisan dusk for now and just focus on sail dusk. When I follow these instructions:

https://stackoverflow.com/questions/65993340/connection-refused-while-runing-laravel-dusk-with-laravel-sail https://stackoverflow.com/questions/65569147/laravel-sail-dusk-selenium-connection-refused

And add a .env.dusk.local file to the project with the following contents:

APP_URL=http://laravel.test

The test runs, but unfortunately the screenshot shows a 500 error.

Without the separate .env.dusk.local, I just get the following error:

Facebook\WebDriver\Exception\UnknownErrorException: unknown error: net::ERR_CONNECTION_REFUSED
  (Session info: headless chrome=107.0.5304.87)
1 like
kayaker323's avatar

Welp... after running php artisan optimize running sail dusk with APP_URL=http://laravel.test also gives me the connection refused error, and I see a blank page in Dusk's screenshots folder.

kayaker323's avatar

Clearing the cache puts me back in the 500 error case for the attempts using the .env.dusk.local approach

kayaker323's avatar

Ok, I removed all my docker images and pulled again and rebuilt. I'm seeing the same set of issues, but I happened to have my sail up running without the background flag and noticed the following lines

coverletterly-app-selenium-1      | 23:41:36.819 INFO [LocalDistributor.newSession] - Session request received by the Distributor:
coverletterly-app-selenium-1      |  [Capabilities {browserName: chrome, goog:chromeOptions: {args: [--window-size=1920,1080, --disable-gpu, --headless]}}, Capabilities {browserName: chrome, chromeOptions: {args: [--window-size=1920,1080, --disable-gpu, --headless]}, platform: ANY}]
coverletterly-app-selenium-1      | Starting ChromeDriver 107.0.5304.87 (f59ffb32abf8c01e9aa298400314bfdf0221b02f-refs/branch-heads/5304@{#1093}) on port 1104
coverletterly-app-selenium-1      | Only local connections are allowed.
coverletterly-app-selenium-1      | Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
coverletterly-app-selenium-1      | ChromeDriver was started successfully.
coverletterly-app-selenium-1      | [1670283696.834][SEVERE]: bind() failed: Cannot assign requested address (99)
coverletterly-app-selenium-1      | 23:41:37.066 INFO [LocalNode.newSession] - Session created by the Node. Id: baa611ad079f64038fcf30e8d194df96, Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 107.0.5304.87, chrome: {chromedriverVersion: 107.0.5304.87 (f59ffb32abf8..., userDataDir: /tmp/.org.chromium.Chromium...}, goog:chromeOptions: {debuggerAddress: localhost:33495}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: LINUX, proxy: Proxy(), se:cdp: http://localhost:33495, se:cdpVersion: 107.0.5304.87, se:vncEnabled: true, se:vncLocalAddress: ws://172.22.0.3:7900, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
coverletterly-app-selenium-1      | 23:41:37.068 INFO [LocalDistributor.newSession] - Session created by the Distributor. Id: baa611ad079f64038fcf30e8d194df96
coverletterly-app-selenium-1      |  Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 107.0.5304.87, chrome: {chromedriverVersion: 107.0.5304.87 (f59ffb32abf8..., userDataDir: /tmp/.org.chromium.Chromium...}, goog:chromeOptions: {debuggerAddress: localhost:33495}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: LINUX, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://172.22.0.3:4444/sessio..., se:cdpVersion: 107.0.5304.87, se:vnc: ws://172.22.0.3:4444/sessio..., se:vncEnabled: true, se:vncLocalAddress: ws://172.22.0.3:7900, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
coverletterly-app-selenium-1      | 23:41:37.157 WARN [SeleniumSpanExporter.lambda$export] - {"traceId": "d59e8b4dabc8989aaed377c19c5c82e8","eventTime": 1670283697156587750,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "selenium:4444","http.method": "POST","http.request_content_length": "40","http.scheme": "HTTP","http.status_code": 500,"http.target": "\u002fsession\u002fbaa611ad079f64038fcf30e8d194df96\u002furl"}}
coverletterly-app-selenium-1      |
coverletterly-app-selenium-1      | 23:41:37.637 INFO [LocalSessionMap.lambda$newLARACASTS_SNIPPET_PLACEHOLDER] - Deleted session from local Session Map, Id: baa611ad079f64038fcf30e8d194df96
coverletterly-app-selenium-1      | 23:41:37.638 INFO [GridModel.release] - Releasing slot for session id baa611ad079f64038fcf30e8d194df96
coverletterly-app-selenium-1      | 23:41:37.638 INFO [SessionSlot.stop] - Stopping session baa611ad079f64038fcf30e8d194df96

Going to try to figure out why it can't bind to the address...

1 like
kayaker323's avatar

Some success! Setting APP_URL="0.0.0.0:80" in .env.dusk.local allows sail dusk to work!!! sail test still fails in the same way though... :/

shamaseen's avatar

in my case all I needed to do is to delete the .env.dusk.local file, even tho it was an identical copy of the .env file.

Please or to participate in this conversation.