laravel-console-dusk
laravel-console-dusk copied to clipboard
Dusk in a built app?
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 Same issue, did you figured out any work around?
No
@nunomaduro Any idea?
Not more than avoid using a compiled zero.
@ijpatricio?
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
@nunomaduro any update on this? I have the same issue on a fresh LZ installation.
@clarkeash No. Fell free to debug this and update the docs or the code accordingly.
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?
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();
});
}
}