Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions config/laravel-console-dusk.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@
'source' => storage_path('laravel-console-dusk/source'),
],

/*
|--------------------------------------------------------------------------
| Laravel Dusk Chrome Driver Path
|--------------------------------------------------------------------------
|
| You may override chrome driver path, for instance if you are using
| laravel dusk while building a standalone application. If you don't set
| (or set to null) this config, the default path will be used.
|
| In your .env file, you can set this value to "auto" to install the chrome
| driver alongside your phar file (if any), or else to the default path.
*/
'chrome_driver_path' => env('CONSOLE_DUSK_DRIVER_PATH'),

/*
| --------------------------------------------------------------------------
| Headless Mode
Expand Down
44 changes: 44 additions & 0 deletions src/Chrome/ChromeProcess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace NunoMaduro\LaravelConsoleDusk\Chrome;

use Laravel\Dusk\Chrome\ChromeProcess as BaseChromeProcess;
use Phar;

/**
* Extends Dusk's ChromeProcess to handle Chrome Driver Path override.
*/
class ChromeProcess extends BaseChromeProcess
{
/** @inheritdoc */
public function toProcess(array $arguments = [])
{
$chromeDriverPath = config('laravel-console-dusk.chrome_driver_path');

if (!$this->driver && isset($chromeDriverPath)) {
if ($chromeDriverPath === 'auto') {
// Set the driver directory to the phar's directory
// Or else, don't do anything
if (($pharPath = Phar::running(false)) !== '') {
$chromeDriverPath = dirname($pharPath);
} else {
$chromeDriverPath = null;
}
}

if ($chromeDriverPath !== null) {
$filenames = [
'linux' => 'chromedriver-linux',
'mac' => 'chromedriver-mac',
'mac-intel' => 'chromedriver-mac-intel',
'mac-arm' => 'chromedriver-mac-arm',
'win' => 'chromedriver-win.exe',
];

$this->driver = $chromeDriverPath.DIRECTORY_SEPARATOR.$filenames[$this->operatingSystemId()];
}
}

return parent::toProcess($arguments);
}
}
30 changes: 30 additions & 0 deletions src/Chrome/SupportsChrome.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace NunoMaduro\LaravelConsoleDusk\Chrome;

use \Laravel\Dusk\Chrome\SupportsChrome as BaseSupportsChrome;

/**
* Overrides Laravel\Dusk\Chrome\SupportsChrome::buildChromeProcess
*/
trait SupportsChrome
{
use BaseSupportsChrome;

/**
* Build the process to run the Chromedriver.
*
* @param array $arguments
* @return \Symfony\Component\Process\Process
*
* @throws \RuntimeException
*
* @overrides Laravel\Dusk\Chrome\SupportsChrome::buildChromeProcess
* Makes it use NunoMaduro\LaravelConsoleDusk\Chrome\ChromeProcess
* instead of Laravel\Dusk\Chrome\ChromeProcess
*/
protected static function buildChromeProcess(array $arguments = [])
{
return (new ChromeProcess(static::$chromeDriver))->toProcess($arguments);
}
}
36 changes: 36 additions & 0 deletions src/Console/ChromeDriverCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace NunoMaduro\LaravelConsoleDusk\Console;

use Laravel\Dusk\Console\ChromeDriverCommand as BaseDriverCommand;
use Phar;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'dusk:chrome-driver')]
class ChromeDriverCommand extends BaseDriverCommand
{
/** @inheritdoc */
public function __construct()
{
$chromeDriverPath = config('laravel-console-dusk.chrome_driver_path');

// Check if driver path is overriden
if (isset($chromeDriverPath)) {
if ($chromeDriverPath === 'auto') {
// Set the driver directory to the phar's directory
// Or else, don't do anything
if (($pharPath = Phar::running(false)) !== '') {
$chromeDriverPath = dirname($pharPath);
} else {
$chromeDriverPath = null;
}
}

if ($chromeDriverPath !== null) {
$this->directory = $chromeDriverPath.DIRECTORY_SEPARATOR;
}
}

parent::__construct();
}
}
2 changes: 1 addition & 1 deletion src/Drivers/Chrome.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Laravel\Dusk\Chrome\SupportsChrome;
use NunoMaduro\LaravelConsoleDusk\Chrome\SupportsChrome;
use NunoMaduro\LaravelConsoleDusk\Contracts\Drivers\DriverContract;

class Chrome implements DriverContract
Expand Down
3 changes: 2 additions & 1 deletion src/LaravelConsoleDuskServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
use Illuminate\Support\Facades\File;
use Illuminate\Support\ServiceProvider;
use Laravel\Dusk\Browser;
use Laravel\Dusk\Console\ChromeDriverCommand;
use NunoMaduro\LaravelConsoleDusk\Console\ChromeDriverCommand;
use NunoMaduro\LaravelConsoleDusk\Contracts\ManagerContract;

class LaravelConsoleDuskServiceProvider extends ServiceProvider implements DeferrableProvider
{
public function boot(): void
{
if ($this->app->runningInConsole()) {

$this->publishes([
__DIR__.'/../config/laravel-console-dusk.php' => config_path('laravel-console-dusk.php'),
], 'config');
Expand Down