laravel-console-dusk icon indicating copy to clipboard operation
laravel-console-dusk copied to clipboard

Dusk in a built app?

Open ekandreas opened this issue 5 years ago • 10 comments

When using laravel-console-dusk inside a compiled zero app this error is catched:

Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"binary":"","args
  ":["--disable-gpu","--headless"]}}}

  Failed to connect to localhost port 9515: Connection refused

ekandreas avatar Mar 19 '19 15:03 ekandreas

@ekandreas Same issue, did you figured out any work around?

arunbabucode avatar Apr 10 '19 19:04 arunbabucode

No

ekandreas avatar Apr 10 '19 21:04 ekandreas

@nunomaduro Any idea?

arunbabucode avatar Apr 10 '19 21:04 arunbabucode

Not more than avoid using a compiled zero.

ekandreas avatar Apr 10 '19 21:04 ekandreas

@ijpatricio?

nunomaduro avatar Apr 10 '19 22:04 nunomaduro

It's the same issue that I got into when https://github.com/laravel-zero/laravel-zero/issues/193#issuecomment-472607642

I have no idea right now.

Isn't Dusk executing another process, other than the main one? And therefore a different setting for the file and port should be configured? Regarding this https://www.php.net/manual/en/phar.using.intro.php

ijpatricio avatar Apr 11 '19 11:04 ijpatricio

@nunomaduro any update on this? I have the same issue on a fresh LZ installation.

clarkeash avatar Jan 17 '20 16:01 clarkeash

@clarkeash No. Fell free to debug this and update the docs or the code accordingly.

nunomaduro avatar Jan 17 '20 16:01 nunomaduro

I have same this issue when try to run console-dusk in a Laravel built app (not Laravel Zero) on production server. Can anyone help this?

dungnh avatar Feb 25 '20 04:02 dungnh

I have been knocking my head against the desk trying to solve this one!

Just managed to get it working... I resolved it by explicitly defining the chromedriver path. See my ChromeDriver class below on how I did that.

I have overridden the Chrome driver with my own class. This class contains...

<?php

namespace App\DuskDrivers;

use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use NunoMaduro\LaravelConsoleDusk\Drivers\Chrome;

class ChromeDriver extends Chrome {

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

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

    public function open(): void
    {
        static::useChromedriver('/usr/local/bin/chromedriver');
        parent::open();
    }
}

To override the Chrome driver I had to first override the manager class

<?php

namespace App\DuskDrivers;

use NunoMaduro\LaravelConsoleDusk\ConsoleBrowserFactory;
use NunoMaduro\LaravelConsoleDusk\Contracts\ConsoleBrowserFactoryContract;
use NunoMaduro\LaravelConsoleDusk\Contracts\Drivers\DriverContract;
use NunoMaduro\LaravelConsoleDusk\Contracts\ManagerContract;
use NunoMaduro\LaravelConsoleDusk\Manager as BaseManager;

class Manager extends BaseManager implements ManagerContract {

    public function __construct(DriverContract $driver = null, ConsoleBrowserFactoryContract $browserFactory = null)
    {
        parent::__construct($driver, $browserFactory);

        $this->driver = $driver ?: new ChromeDriver();
        $this->browserFactory = $browserFactory ?: new ConsoleBrowserFactory();
    }

}

Then apply this inside my AppServiceProvider class - make sure this provider is loaded after NunoMaduro\LaravelConsoleDusk\LaravelConsoleDuskServiceProvider::class in your config/app.php file.

<?php

namespace App\Providers;

use App\DuskDrivers\Manager;
use Illuminate\Support\ServiceProvider;
use NunoMaduro\LaravelConsoleDusk\Contracts\ManagerContract;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {

    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind(ManagerContract::class, function ($app) {
            return new Manager();
        });
    }
}

jonathandey avatar Apr 17 '20 16:04 jonathandey