3

Can anyone help, I am unable to get Laravel dusk to run the default sample test in my current Laravel 5.6 project on mac high sierra.

Error message

Time: 2.5 minutes, Memory: 14.00MB

There was 1 error:

1) Tests\Browser\ExampleTest::testBasicExample Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"binary":"/Users/keith/Desktop/dusk/vendor/laravel/dusk/bin/chromedriver-mac","args":["--disable-gpu"]}}}

Operation timed out after 30002 milliseconds with 0 bytes received

/Users/keith/Desktop/dusk/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:286 /Users/keith/Desktop/dusk/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:126 /Users/keith/Desktop/dusk/tests/DuskTestCase.php:40 /Users/keith/Desktop/dusk/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:189 /Users/keith/Desktop/dusk/vendor/laravel/framework/src/Illuminate/Support/helpers.php:770 /Users/keith/Desktop/dusk/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:190 /Users/keith/Desktop/dusk/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:92 /Users/keith/Desktop/dusk/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:64 /Users/keith/Desktop/dusk/tests/Browser/ExampleTest.php:21

I have already done the following :

  • added the following to app\Providers\AppServiceProvider.php

use Laravel\Dusk\DuskServiceProvider;

...

public function register()

{

    if ($this->app->environment('local', 'testing')) {

        $this->app->register(DuskServiceProvider::class);
    }

}
  • ran 'php artisan dusk:install' in terminal
  • set App_URL in .env to http://localhost:8000
  • specified the location of chromedriver in DuskTestCase
  • start 'php artisan serve' before running 'php artisan dusk'

Repository : https://github.com/KKOA/dusk

Jonas Staudenmeir
  • 21,093
  • 4
  • 33
  • 77
KKOA
  • 31
  • 1
  • 2

3 Answers3

3

If your function extends from DuskTestCase.php, then you need to increase connection_timeout_in_ms.

Do this by changing driver method to the following:

DuskTestCase.php

protected function driver()
    {
        $options = (new ChromeOptions)->addArguments([
            '--disable-gpu',
            '--headless',
            '--window-size=1920,1080',
        ]);

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

If that dosen't work for some reason then try to set_time_limit before $this->browse

set_time_limit(0);
Unicco
  • 1,797
  • 1
  • 14
  • 27
1

try this while you instantiate your browser.. the most important is $driver = retry(5, function () use ($capabilities) { return RemoteWebDriver::create('http://localhost:9515', $capabilities, 60000, 60000);

Below is how i instantiate my browser

$options      = (new ChromeOptions)->addArguments(['--disable-gpu', '--headless', '--no-sandbox']);
$capabilities = DesiredCapabilities::chrome()
  ->setCapability(ChromeOptions::CAPABILITY, $options)
  ->setPlatform('Linux');
$driver       = retry(5, function () use ($capabilities) {
  return RemoteWebDriver::create('http://localhost:9515', $capabilities, 60000, 60000);
}, 50);

$browser = new Browser($this->driver, new ElementResolver($driver, ''));
vidihermes
  • 565
  • 3
  • 6
  • 20
  • I needed to update the Chrome installation within my Laravel Homestead Vagrant: https://stackoverflow.com/a/45227939/470749 – Ryan Nov 24 '18 at 15:09
1

You really need to have latest google-chrome and latest chrome driver installed. I used to have only chromium browser and it doesn't work with it. To install latest chrome driver run php artisan dusk:chrome-driver.

pejuko
  • 1,614
  • 1
  • 10
  • 5
  • This worked for me. I only had chromium browser and it worked when I ran ```php artisan dusk:chrome-driver``` – raffi Apr 25 '21 at 18:22