Reputation: 103
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)
Upvotes: 5
Views: 4264
Reputation: 1
I encountered the same problem, and solved it according to @Martins Balodis comment above. I'm guessing the reason is related to my dual monitor setup. I did not manage to alter this by adding an entry in the Dusk's environment file. Instead, I added this line in the top section of my test file.
$_ENV['DISPLAY'] = getenv('DISPLAY');
I tested several suggestions concerning adding arguments to the chrome driver, but this was the only modification that worked given that I wanted to run the tests with --browse
.
Upvotes: 0
Reputation: 111
In my case, I found out that I needed to add --no-sandbox
to tests/DuskTestCase.php
since I was running on root on an lxd container.
I found out about the error by running: vendor/laravel/dusk/bin/chromedriver-linux --log-level=ALL
and in another terminal running php artisan dusk
. It will display the logs and I was able to deduce the problem from there.
Upvotes: 6
Reputation: 71
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
Upvotes: 0
Reputation: 2454
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 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
.
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.
Upvotes: 3