Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Dusk: Facebook\WebDriver\Exception\UnknownErrorException: unknown error: net::ERR_CONNECTION_REFUSED

Running php artisan dusk get the error:

Facebook\WebDriver\Exception\UnknownErrorException: unknown error: net::ERR_CONNECTION_REFUSED
  (Session info: headless chrome=85.0.4183.83)

Versions:

  • OS: Windows 10 v1903 build 18362.1016
  • Chrome: 85.0.4183.83
  • Laravel: v6.18.37
  • Dusk: v5.11.0
  • Phpunit: v8.5.8

Tried:

  • Disable firewall
  • Set test website to use localhost (was myapp.local)
  • Can access all pages using Chrome browser
  • Check that vendor/laravel/dusk/bin/chromedriver-win.exe is executable (-rwxr-xr-x)
  • php artisan route:clear
  • php artisan cache:clear
  • php artisan config:clear
  • composer dump-autoload
  • google "Facebook\WebDriver\Exception\UnknownErrorException: unknown error: net::ERR_CONNECTION_REFUSED"

The server localhost:9515 appears to be running while tests executing as I get the following response in Chrome when trying it:

{
    value: {
        error: "unknown command",
        message: "unknown command: unknown command: ",
        stacktrace: "Backtrace: Ordinal0 [0x0037D383+3134339] Ordinal0 [0x0026A171+2007409] Ordinal0 [0x0010AEE8+569064] Ordinal0 [0x000AD12C+184620] Ordinal0 [0x000ACF0A+184074] Ordinal0 [0x00081FD7+8151] Ordinal0 [0x00082496+9366] Ordinal0 [0x00082B40+11072] Ordinal0 [0x00280CD9+2100441] GetHandleVerifier [0x004EB75A+1396954] GetHandleVerifier [0x004EB3D9+1396057] GetHandleVerifier [0x004F7126+1444518] GetHandleVerifier [0x004EBCE8+1398376] Ordinal0 [0x00277F51+2064209] Ordinal0 [0x00081D35+7477] Ordinal0 [0x00081991+6545] GetHandleVerifier [0x006BF31C+3312796] BaseThreadInitThunk [0x76986359+25] RtlGetAppContainerNamedObjectPath [0x771D7C24+228] RtlGetAppContainerNamedObjectPath [0x771D7BF4+180] (No symbol) [0x00000000] ",
    }
}

DuskTestCase driver:

/**
 * Create the RemoteWebDriver instance.
 *
 * @return \Facebook\WebDriver\Remote\RemoteWebDriver
 */
protected function driver()
{
    $options = (new ChromeOptions)->addArguments([
        '--disable-gpu',
        '--headless',
        '--window-size=1920,1080',
    ]);

    return RemoteWebDriver::create(
        'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
            ChromeOptions::CAPABILITY, $options
        )
    );
}

Does anyone have any clues on what else to try? Or does anyone else know a resolution?

like image 932
Trevor Avatar asked Aug 31 '20 23:08

Trevor


2 Answers

I faced the same issue and for me what worked was setting the APP_URL parameter in the .env file as:

APP_URL=http://127.0.0.1:8000

As that was the same port on which my php artisan serve would also serve the website i.e.

Laravel development server started: http://127.0.0.1:8000
like image 148
Coola Avatar answered Sep 27 '22 16:09

Coola


I'm putting this out there for others that might face the same thing as me.

It turns out Laravel Dusk expects us to run php artisan serve before running php artisan dusk! The ERR_CONNECTION_REFUSED error refers to not being able to connect to the http://localhost:8000 URL of the application itself, because it's not running.

This does make sense, but I simply didn't know and the documentation was not clear on that (I had to deduce it). The ChromeDriver, however, is started automatically by Dusk at execution time.

like image 39
Valeriu Paloş Avatar answered Sep 27 '22 18:09

Valeriu Paloş