Dusk: Chromedrive problem with Dusk

Created on 15 Mar 2018  Â·  14Comments  Â·  Source: laravel/dusk

Hey all.

I do not know if this is affecting other people, but I think so. Testing with dusk is leading to this error:

→ php artisan dusk
PHPUnit 7.1-dev by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)

Time: 3.98 seconds, Memory: 18.00MB

There was 1 error:

1) Tests\Browser\AccountTest::a_user_can_login_into_system
Facebook\WebDriver\Exception\UnknownServerException: unknown error: call function result missing 'value'
  (Session info: headless chrome=65.0.3325.162)
  (Driver info: chromedriver=2.33.506106 (8a06c39c4582fbfbab6966dbb1c38a9173bfb1a2),platform=Mac OS X 10.12.6 x86_64)

/path-to/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:114
/path-to/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:326
/path-to/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:547
/path-to/vendor/facebook/webdriver/lib/Remote/RemoteExecuteMethod.php:40
/path-to/vendor/facebook/webdriver/lib/Remote/RemoteWebElement.php:66
/path-to/vendor/laravel/dusk/src/Concerns/InteractsWithElements.php:170
/path-to/tests/Browser/AccountTest.php:33
/path-to/vendor/laravel/dusk/src/TestCase.php:92
/path-to/tests/Browser/AccountTest.php:37

It looks like a problem with chromedrive. So, I've downloaded an fresh version of chromedriver, put it in my $PATH and in .env.dusk.local file the following key:

CHROME_DRIVER_BIN_PATH="/Users/blablabla/path/to/CHROME/chromedriver"

In my DuskTestCase.php file:

protected function driver()
    {
        $options = (new ChromeOptions)->addArguments([
            '--disable-gpu',
            '--headless',
            '--verbose',
            '--log-path=' . storage_path("logs/chromedriver-errors.log"),
        ]);

        if (env("CHROME_DRIVER_BIN_PATH")) {
            $options->setBinary(env('CHROME_DRIVER_BIN_PATH'));
        }

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

Now, if I run with the new chromedriver bin, the errors changed to:

here was 1 error:

1) Tests\Browser\AccountTest::a_user_can_login_into_system
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"binary":"\/Users\/path-to\/chromedriver","args":["--disable-gpu","--headless"]}}}

Operation timed out after 30000 milliseconds with 0 bytes received

Is there any one here having these strange problems with chromedrive and Dusk?

Any help is very appreciate.

Most helpful comment

The only fix I have found was using no-sandbox .

$options = (new ChromeOptions)->addArguments([
            '--disable-gpu',
            '--headless',
            '--no-sandbox'
        ]);

All 14 comments

See #489.

I too was getting the awful call function result missing 'value' error from a particular Dusk test when running on my macOS, but when I updated all the composer packages, I no longer got the error.

I have ran in to the Operation timed out... error many times indeed. I found that certain environments needed certain ChromeOptions to work right. For my Demos site example, I get that error in Docker if I don't run Xvfb, but if I do run that program then it just hangs for a very very long time.

Using "no-sandbox" has been the only way I have been able to reliably use chromedriver. Without it, I would either get timeout issues or "Chrome might have crashed" messages from chromedriver.

About the actual issue being talked about here (call function result missing 'value'), using the latest version of chromedriver has also fixed this problem for me.

The only fix I have found was using no-sandbox .

$options = (new ChromeOptions)->addArguments([
            '--disable-gpu',
            '--headless',
            '--no-sandbox'
        ]);

I'm trying to run dusk tests in a Docker container called Workspace. I have a new Laravel 5.7.9 project with Laradock. I have the same options in use as above (@rolandalla) but I'm getting this error:

There was 1 failure:

1) Tests\Browser\ExampleTest::testBasicExample
Did not see expected text [Laravel] within element [body].
Failed asserting that false is true.

It seems like the Dusk isn't finding any elements. That test above is the basic test that comes with Laravel project. Any ideas?

This is another error:

1) Tests\Browser\LoginTest::testLogin
Facebook\WebDriver\Exception\NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"body textarea[name='email']"}
  (Session info: headless chrome=70.0.3538.67)
  (Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.9.93-linuxkit-aufs x86_64)

@rapitkan Does the screenshot show anything?

@staudenmeir Screenshot's backgound color is white. No text or other content.

This is my setup in DuskTestCase.php:

        $options = (new ChromeOptions)->addArguments([
            '--disable-gpu',
            '--headless',
            '--no-sandbox',
            '--verbose'
        ]);

And WORKSPACE_INSTALL_DUSK_DEPS=true in .env of laradock.

I got it working. I had missed a couple of steps in Laradock instructions.

There's an issue open to update the ChromeDriver: https://github.com/laravel/dusk/issues/570

We'll look into updating these soon. In the meantime feel free to send in a PR.

SOLVED!!!

In DuskTestCase.php File

Old Code of driver():

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
            )
        );
    }

Just Add '--no-sandbox' flag

New Code:

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

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

I had the same problem.
https://github.com/staudenmeir/dusk-updater
Script saved my day.
Thanks to the writer.

There is a few way you can try:

1.make sure copy ".env" rename ".env.dusk.local" and change APP_URL={http://localhost:8000} //you serve

  1. run php artisan serve
  2. run php artisan dusk
    Time: 2.17 seconds, Memory: 18.00 MB

OK (1 test, 1 assertion)

debug:
1.change DuskTestCase.php to see what website page you browse

namespace Tests;

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

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',
    ]);

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

}

2.add one line in you test file ExampleTest.php

namespace Tests\Browser;

use Laravel\Dusk\Browser;
use Tests\DuskTestCase;

class ExampleTest extends DuskTestCase
{
/**
* A Dusk test example.
*
* @return void
*/
public function testExample()
{
$this->browse(function (Browser $browser) {
$browser->visit('/')
->pause(1000) // => this line
->assertSee('Laravel');
});
}
}

I had the same problem. I installed the chrome in Laravel homestead and It's working now.

sudo apt-get install chromium-browser

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alex-LE picture alex-LE  Â·  7Comments

muswanto picture muswanto  Â·  3Comments

fwang-laralabs picture fwang-laralabs  Â·  6Comments

dellow picture dellow  Â·  4Comments

rauldeheer picture rauldeheer  Â·  4Comments