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

kayaker323's avatar

Laravel dusk appears to hang and retry creating chromedriver when logging in as user

I'm having a hard time troubleshooting a basic browser test in laravel sail (sail dusk --filter SubscriptionTest). All feature tests work fine, no browser tests work consistently.

The simplest version of the test:

<?php

namespace Tests\Browser;

use App\Models\User;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;

class SubscriptionTest extends DuskTestCase
{
    use DatabaseMigrations;

    /**
     * Test that a user can purchase a subscription
     *
     * @return void
     */
    public function testPurchase()
    {
       $user = User::factory()->create();

        $this->browse(function (Browser $browser, User $user) {
            $browser->visit('/login')
                ->type('email', $user->email)
                ->type('password', 'password')
                ->press('LOG IN');
            });
	}
}

(I know there are no assertions here - I'm trying to isolate the issue with dusk). I have an .env.testing file that is identical to my .env except for DB_DATABASE=testing

The test runs successfully if I remove the parts typing in data from the user the factory creates, like the email.

public function testPurchase()
    {
       //$user = User::factory()->create();

        $this->browse(function (Browser $browser) {
            $browser->visit('/login')
                //->type('email', $user->email)
                //->type('password', 'password')
                ->press('LOG IN');
            });
	}

I've also tried php artisan config:clear but this doesn't allow the test to run consistently either.

When I add a breakpoint and step through code, I see it hitting Illuminate's retry helper attempting to create the remote webdriver here

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

In the most recent case, after 5 tries, the webdriver was created and the test completes.

Output from sail up

laravel-app-selenium-1      | 20:35:39.659 INFO [LocalNode.lambda$new] - Session id 46ec0e924a126e91f0bf0d7523d05abe timed out, stopping...
laravel-app-selenium-1      | 20:35:39.731 INFO [LocalSessionMap.lambda$newLARACASTS_SNIPPET_PLACEHOLDER] - Deleted session from local Session Map, Id: 46ec0e924a126e91f0bf0d7523d05abe
laravel-app-selenium-1      | 20:35:39.731 INFO [GridModel.release] - Releasing slot for session id 46ec0e924a126e91f0bf0d7523d05abe
laravel-app-selenium-1      | 20:35:39.731 INFO [SessionSlot.stop] - Stopping session 46ec0e924a126e91f0bf0d7523d05abe
laravel-app-selenium-1      | 20:35:39.744 INFO [LocalDistributor.newSession] - Session request received by the Distributor:
laravel-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}]
laravel-app-selenium-1      | Starting ChromeDriver 107.0.5304.87 (f59ffb32abf8c01e9aa298400314bfdf0221b02f-refs/branch-heads/5304@{#1093}) on port 26894
laravel-app-selenium-1      | Only local connections are allowed.
laravel-app-selenium-1      | Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
laravel-app-selenium-1      | [1670358939.757][SEVERE]: bind() failed: Cannot assign requested address (99)
laravel-app-selenium-1      | ChromeDriver was started successfully.
laravel-app-meilisearch-1   | [2022-12-06T20:35:39Z INFO  actix_web::middleware::logger] 127.0.0.1 "GET /health HTTP/1.1" 200 22 "-" "Wget" 0.000345
laravel-app-selenium-1      | 20:35:39.977 INFO [LocalNode.newSession] - Session created by the Node. Id: ed89bb279299042ba004a2c388e9b57d, 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:44791}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: LINUX, proxy: Proxy(), se:cdp: http://localhost:44791, se:cdpVersion: 107.0.5304.87, se:vncEnabled: true, se:vncLocalAddress: ws://192.168.192.2: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}
laravel-app-selenium-1      | 20:35:39.979 INFO [LocalDistributor.newSession] - Session created by the Distributor. Id: ed89bb279299042ba004a2c388e9b57d
laravel-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:44791}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: LINUX, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://192.168.192.2:4444/ses..., se:cdpVersion: 107.0.5304.87, se:vnc: ws://192.168.192.2:4444/ses..., se:vncEnabled: true, se:vncLocalAddress: ws://192.168.192.2: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}
laravel-app-mailhog-1       | [APIv1] KEEPALIVE /api/v1/events
laravel-app-meilisearch-1   | [2022-12-06T20:36:09Z INFO  actix_web::middleware::logger] 127.0.0.1 "GET /health HTTP/1.1" 200 22 "-" "Wget" 0.000097
laravel-app-meilisearch-1   | [2022-12-06T20:36:39Z INFO  actix_web::middleware::logger] 127.0.0.1 "GET /health HTTP/1.1" 200 22 "-" "Wget" 0.000081
laravel-app-mailhog-1       | [APIv1] KEEPALIVE /api/v1/events
laravel-app-laravel.test-1  |   2022-12-06 20:37:06 ................................................... ~ 1s
laravel-app-laravel.test-1  |   2022-12-06 20:37:07 /build/assets/app.4424761b.css .................... ~ 0s
laravel-app-laravel.test-1  |   2022-12-06 20:37:07 ................................................... ~ 1s
laravel-app-laravel.test-1  |   2022-12-06 20:37:07 ................................................... ~ 1s
laravel-app-laravel.test-1  |   2022-12-06 20:37:07 /build/assets/app.7cafe3db.js ..................... ~ 1s
laravel-app-meilisearch-1   | [2022-12-06T20:37:09Z INFO  actix_web::middleware::logger] 127.0.0.1 "GET /health HTTP/1.1" 200 22 "-" "Wget" 0.000091
laravel-app-meilisearch-1   | [2022-12-06T20:37:39Z INFO  actix_web::middleware::logger] 127.0.0.1 "GET /health HTTP/1.1" 200 22 "-" "Wget" 0.000082
laravel-app-selenium-1      | 20:37:45.813 INFO [LocalSessionMap.lambda$newLARACASTS_SNIPPET_PLACEHOLDER] - Deleted session from local Session Map, Id: ed89bb279299042ba004a2c388e9b57d
laravel-app-selenium-1      | 20:37:45.814 INFO [GridModel.release] - Releasing slot for session id ed89bb279299042ba004a2c388e9b57d
laravel-app-selenium-1      | 20:37:45.814 INFO [SessionSlot.stop] - Stopping session ed89bb279299042ba004a2c388e9b57d
0 likes
3 replies
kayaker323's avatar

Eventually for the version of the test including the user log in attempt, I end up getting the following error:

sail dusk --filter UserSubscriptionTest
PHPUnit 9.5.26 by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)

Time: 06:12.046, Memory: 38.50 MB

There was 1 error:

1) Tests\Browser\UserSubscriptionTest::testPurchase
TypeError: Facebook\WebDriver\Remote\JsonWireCompat::getElement(): Argument #1 ($rawElement) must be of type array, string given, called in /var/www/html/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php on line 218

/var/www/html/vendor/php-webdriver/webdriver/lib/Remote/JsonWireCompat.php:21
/var/www/html/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:218
/var/www/html/vendor/laravel/dusk/src/Browser.php:329
/var/www/html/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:144
/var/www/html/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php:236
/var/www/html/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:150
/var/www/html/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:76
/var/www/html/tests/Browser/UserSubscriptionTest.php:31

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
kayaker323's avatar

Ok, I'm finding some other oddities. The user factory created the user in my local dev db, not my testing database, despite my .env.testing defining DB_DATABASE=testing and phpunit.dusk.xml doing the same...

Does anyone know why this might be?

Please or to participate in this conversation.