Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dusk in a built app? #11

Open
ekandreas opened this issue Mar 19, 2019 · 10 comments
Open

Dusk in a built app? #11

ekandreas opened this issue Mar 19, 2019 · 10 comments

Comments

@ekandreas
Copy link

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
@arunbabucode
Copy link

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

@ekandreas
Copy link
Author

No

@arunbabucode
Copy link

@nunomaduro Any idea?

@ekandreas
Copy link
Author

Not more than avoid using a compiled zero.

@nunomaduro
Copy link
Owner

@ijpatricio?

@ijpatricio
Copy link

It's the same issue that I got into when laravel-zero/laravel-zero#193 (comment)

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

@clarkeash
Copy link

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

@nunomaduro
Copy link
Owner

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

@dungnh
Copy link

dungnh commented Feb 25, 2020

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?

@jonathandey
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants