laravel/dusk

Fresh laravel project with dusk and chrome installation fails with php artisan dusk

MrMoonbag opened this issue · 6 comments

Dusk Version

8.2

Laravel Version

11.9

PHP Version

8.3.6

PHPUnit Version

11.0.1

Database Driver & Version

No response

Description

Running php artisan dusk on fresh setup gives the following error:

session not created: Chrome failed to start: exited normally.
(session not created: DevToolsActivePort file doesn't exist)
(The process started from chrome location /opt/google/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

image

Steps To Reproduce

Fresh Ubuntu 24.04 Server
composer require laravel/laravel dusk
composer require laravel/dusk --dev

sudo apt install chromium-browser
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb

php artisan dusk:install
php artisan dusk:chrome-driver

INFO ChromeDriver binary successfully installed for version 129.0.6668.91.

php artisan dusk = Fails

Can you share the output of php artisan dusk:chrome-driver --detect?

Can you share the content of tests/DuskTestCase.php

I have not made any changes to the project itself, so the test/DuskTestCase.php is the one generated by php artisan dusk command.

<?php

namespace Tests;

use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Illuminate\Support\Collection;
use Laravel\Dusk\TestCase as BaseTestCase;
use PHPUnit\Framework\Attributes\BeforeClass;

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

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

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

This might be a permission issue on Linux: https://stackoverflow.com/a/50642913

Adding '--no-sandbox' to DuskTestCase solved the issue. Thank you