2

I am using laradock https://github.com/laradock/laradock for development environment setup. Everything looks good untill I have tried to run dusk test in the environment.

This is the output of command php artisan dusk

root@e686e0cbda43:/var/www/stability_v54# php artisan dusk --filter test_WhenEmptyFormIsSubmitted_ShowErrorMessages 
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)

Time: 28.59 seconds, Memory: 34.00MB

There was 1 error:

1) Tests\Browser\NurseRegisterTest::test_WhenEmptyFormIsSubmitted_ShowErrorMessages
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"w3c":false,"binary":"","args":["--disable-gpu","--no-sandbox","--ignore-ssl-errors","--whitelisted-ips=\"\"","--headless"]}}}

Failed to connect to 127.0.0.1 port 4444: Connection refused

/var/www/stability_v54/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:297
/var/www/stability_v54/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:144
/var/www/stability_v54/tests/DuskTestCase.php:64
/var/www/stability_v54/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:185
/var/www/stability_v54/vendor/laravel/framework/src/Illuminate/Support/helpers.php:765
/var/www/stability_v54/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:186
/var/www/stability_v54/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:92
/var/www/stability_v54/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:64
/var/www/stability_v54/tests/Browser/NurseRegisterTest.php:98

here is DuskTestCase,

<?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;

    protected function setUp()
    {
        //Set wait env variables
        $this->quickWait  = env('QUICK_WAIT', false);
        $this->shortWait  = env('SHORT_WAIT', false);
        $this->mediumWait = env('MEDIUM_WAIT', false);
        $this->longWait   = env('LONG_WAIT', false);

        parent::setUp();

        foreach (static::$browsers as $browser) {
            $browser->driver->manage()->deleteAllCookies();
        }
    }

    /**
     * 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()
    {
        $arguments = [
            '--disable-gpu',
            '--no-sandbox',
            '--ignore-ssl-errors',
            '--whitelisted-ips=""',
        ];

        $headlessMode = env('DUSK_HEADLESS_MODE', false);

        if($headlessMode) {
            array_push($arguments, '--headless');
        }

        $options = (new ChromeOptions)->addArguments($arguments);

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

I have following version of chrome driver and selenium.

Chrome version 88.0.4324.96 Selenium Standalone v.3.141.59

Somewhere I found I have to update these two into latest version, but these are already latest ones in my setup.

This question may sound duplicate but I have already tried the available ones in this community.

If somebody know the reason behind this please share, it will be extremly helpful.

Sagar Gautam
  • 9,049
  • 6
  • 53
  • 84

1 Answers1

1

The Curl error thrown for POST... means your dusk test case was unable to connect with the selenium endpoint entirely.

I see that you used 127.0.0.1 in your driver setup

protected function driver() {
    return RemoteWebDriver::create('http://127.0.0.1:4444', ...

but, assuming you're running php artisan dusk inside your laradock workspace container, that container can't see the seleninum host at http://127.0.0.1. However, because of the frontend network set up between containers by docker compose, that container can see it at http://selenium

Also, I think you also need to specify path /wd/hub under selenium

So try this:

  1. return RemoteWebDriver::create('http://selenium:4444/wd/hub', ...
  2. Run dusk inside your laradock workspace container, e.g.
    docker-compose exec -u laradock workspace php artisan dusk
Daryn
  • 4,791
  • 4
  • 39
  • 52