0

I started a new Laravel application using Sail to have local development running in Docker, so it already started with a selenium/standalone-chrome container also.

Installed Dusk following docs, but running php artisan dusk from sail-8.3/app container gives following error:

  FAILED  Tests\Browser\HomePageTest > example                                                                    UnknownErrorException   
  unknown error: net::ERR_CONNECTION_REFUSED
  (Session info: chrome=126.0.6478.114)

  at vendor/php-webdriver/webdriver/lib/Exception/WebDriverException.php:146
    142▕                     throw new UnexpectedAlertOpenException($message, $results);
    143▕                 case 'unknown command':
    144▕                     throw new UnknownCommandException($message, $results);
    145▕                 case 'unknown error':
  ➜ 146▕                     throw new UnknownErrorException($message, $results);
    147▕                 case 'unknown method':
    148▕                     throw new UnknownMethodException($message, $results);
    149▕                 case 'unsupported operation':
    150▕                     throw new UnsupportedOperationException($message, $results);

      +5 vendor frames 
  6   tests/Browser/HomePageTest.php:18
  7   tests/Browser/HomePageTest.php:17

Following other SO answers to same problem I eve tried to run php artisan serve from within app container and then run php artisan dusk, but got the same outcome.

DuskTestCase.php

abstract class DuskTestCase extends BaseTestCase
{
    /**
     * Prepare for Dusk test execution.
     */
    #[BeforeClass]
    public static function prepare(): void
    {
        if (! static::runningInSail()) {
            static::startChromeDriver();
        }
    }

    /**
     * Create the RemoteWebDriver instance.
     */
    protected function driver(): RemoteWebDriver
    {
        $options = (new ChromeOptions)->addArguments(collect([
            $this->shouldStartMaximized() ? '--start-maximized' : '--window-size=1920,1080',
        ])->unless($this->hasHeadlessDisabled(), function (Collection $items) {
            return $items->merge([
                '--disable-gpu',
                '--headless=new',
            ]);
        })->all());

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

HomePageTest.php

class HomePageTest extends DuskTestCase
{
    use DatabaseMigrations;
    /**
     * A Dusk test example.
     */
    public function testExample(): void
    {
        $this->browse(function (Browser $browser) {
            $browser->visit('/')
                    ->assertSee('Login');
        });
    }
}

.env

Added DUSK_DRIVER_URL=http://selenium:4444

selenium/standalone-chrome container logs

07:43:16.595 INFO [LocalSessionMap.lambda$new$0] - Deleted session from local Session Map, Id: d6234a0ba83b4ac0de1e5c6b70fb616b
07:43:16.595 INFO [GridModel.release] - Releasing slot for session id d6234a0ba83b4ac0de1e5c6b70fb616b
07:43:16.596 INFO [SessionSlot.stop] - Stopping session d6234a0ba83b4ac0de1e5c6b70fb616b
07:43:17.150 INFO [LocalDistributor.newSession] - Session request received by the Distributor: 
 [Capabilities {browserName: chrome, goog:chromeOptions: {args: [--window-size=1920,1080, --disable-gpu, --headless=new]}}]
07:43:17.312 INFO [LocalNode.newSession] - Session created by the Node. Id: 8b9c90b80c4e711d8781e204ab55331f, Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 126.0.6478.114, chrome: {chromedriverVersion: 126.0.6478.63 (df799988fdc9..., userDataDir: /tmp/.org.chromium.Chromium...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:45535}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://172.22.0.6:4444/sessio..., se:cdpVersion: 126.0.6478.114, se:vnc: ws://172.22.0.6:4444/sessio..., se:vncEnabled: true, se:vncLocalAddress: ws://172.22.0.6: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:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
07:43:17.315 INFO [LocalDistributor.newSession] - Session created by the Distributor. Id: 8b9c90b80c4e711d8781e204ab55331f 
 Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 126.0.6478.114, chrome: {chromedriverVersion: 126.0.6478.63 (df799988fdc9..., userDataDir: /tmp/.org.chromium.Chromium...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:45535}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://172.22.0.6:4444/sessio..., se:cdpVersion: 126.0.6478.114, se:vnc: ws://172.22.0.6:4444/sessio..., se:vncEnabled: true, se:vncLocalAddress: ws://172.22.0.6: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:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
07:43:17.441 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "a9a833dc373529e36ebc4b22b4b6b57d","eventTime": 1721893397440430947,"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": "35","http.scheme": "HTTP","http.status_code": 500,"http.target": "\u002fsession\u002f8b9c90b80c4e711d8781e204ab55331f\u002furl"}}

07:43:17.869 INFO [LocalSessionMap.lambda$new$0] - Deleted session from local Session Map, Id: 8b9c90b80c4e711d8781e204ab55331f
07:43:17.870 INFO [GridModel.release] - Releasing slot for session id 8b9c90b80c4e711d8781e204ab55331f
07:43:17.872 INFO [SessionSlot.stop] - Stopping session 8b9c90b80c4e711d8781e204ab55331f

I see there is a warning here, but cannot understand it.

1 Answer 1

0

OK, found the problem, I missed a step in Dusk documentation related to runnning it with Sail: https://laravel.com/docs/11.x/sail#laravel-dusk

I just needed to run Docker containers using Sail instead of plain Docker command, so

# wrong
docker compose up -d

# correct
./vendor/bin/sail up -d

And then running Dusk tests via Sail too:

./vendor/bin/sail dusk
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.