0

I'm running the example test of Laravel Dusk for browser, but when I execute php artisan dusk I got an error

Using: * Ubuntu 18 * Laravel 5.8 * Dusk 5.1 * ChromeDriver 74 * apache2

This is my DuskTestCase.php:

    <?php

    namespace Tests;

    use Laravel\Dusk\TestCase as BaseTestCase;
    use Facebook\WebDriver\Chrome\ChromeOptions;
    use Facebook\WebDriver\Remote\RemoteWebDriver;
    use Facebook\WebDriver\Remote\DesiredCapabilities;

    abstract class DuskTestCase extends BaseTestCase
    {
    use CreatesApplication;

/**
 * Prepare for Dusk test execution.
 *
 * @beforeClass
 * @return void
 */
public static function prepare()
{
    static::startChromeDriver();
}

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

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

}

This is the error:

    1) Tests\Browser\ExampleTest::testBasicExample
    Facebook\WebDriver\Exception\UnknownServerException: unknown error: Chrome failed to start: exited abnormally
      (unknown error: DevToolsActivePort file doesn't exist)
      (The process started from chrome location /snap/bin/chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
      (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 4.18.0-20-generic x86_64)
  • 1
    Possible duplicate of [WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser](https://stackoverflow.com/questions/50642308/webdriverexception-unknown-error-devtoolsactiveport-file-doesnt-exist-while-t) – Chris White May 23 '19 at 15:19
  • Yes, no, but following some answers I got the solution with this https://stackoverflow.com/questions/39541739/chromedriver-error-chrome-version-must-be-52-using-nightwatch/45227939#45227939 – Oscar Acevedo Osses May 24 '19 at 16:50
  • I had to change my chrome installation – Oscar Acevedo Osses May 24 '19 at 16:50
  • Dusk defaults `DISPLAY` environment variable to `:0`. If the actual display isn't on `:0` you will get the `DevToolsActivePort file doesn't exist` error. Even if you have `DISPLAY` env variable set globally, php might not load it due to php configuration. Set DISPLAY in .env or make the graphical interface run on `:0`. This should be irrelevant if you are running headless. – Martins Balodis Nov 29 '19 at 10:04
  • @OscarAcevedoOsses my answer might help you too. You might have installed chromium-browser instead of google-chrome-stable. – Lupinity Labs Oct 24 '20 at 03:05

2 Answers2

0

This is not directly related to the question, but since I did not easily find any fix for the same error occuring on Laravel 7+ and Homestead 10.0.0, I'll present the solution I came up with after hours of research and trying hoping it will help out other people running into this issue.

Homestead configuration

Homestead does not seem to support Dusk out of the box anymore. To install the prerequisites for using Chromium, you have to add the webdriver feature to your homestead.yaml:

 features:
     - webdriver: true

and then re-provision by running homestead halt && homestead up --provision.

DuskTestCase class

After that, make sure Chromium is started in headless mode by adding additional arguments in the driverChrome() method in tests/DuskTestCase.php:

    protected function driverChrome()
    {
        $options = (new ChromeOptions)->addArguments([
            '--disable-gpu',
            '--headless',
        ]);

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

Most people will suggest using the --no-sandbox and --disable-dev-shm-usage flags too, but after provisioning homestead correctly with the webdriver feature that installs google-chrome-stable instead of chromium-browser, these were not needed for me to run correctly.

Lupinity Labs
  • 1,319
  • 8
  • 17
0

You may try manually download ChromeDriver from official ChromeDriver downloads page.

wget https://chromedriver.storage.googleapis.com/87.0.4280.88/chromedriver_linux64.zip
unzip chromedriver_linux64.zip    
./chromedriver