From 8cea2faf671fa60f594a3175ade53c8d57a2c04a Mon Sep 17 00:00:00 2001 From: Derek Date: Wed, 28 Dec 2022 02:49:28 -0500 Subject: [PATCH] Support .env DUSK_START_MAXIMIZED= CI environments such as GitHub Actions can set DUSK_START_MAXIMIZED=true to open the web browser without needing to set an exact widthxheight. --- src/Concerns/TogglesHeadlessMode.php | 11 +++++++++++ stubs/DuskTestCase.stub | 2 +- stubs/FirefoxDuskTestCase.stub | 6 ++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Concerns/TogglesHeadlessMode.php b/src/Concerns/TogglesHeadlessMode.php index efd5210..57e4a17 100644 --- a/src/Concerns/TogglesHeadlessMode.php +++ b/src/Concerns/TogglesHeadlessMode.php @@ -30,4 +30,15 @@ protected function hasHeadlessDisabled() return isset($_SERVER['DUSK_HEADLESS_DISABLED']) || isset($_ENV['DUSK_HEADLESS_DISABLED']); } + + /** + * Determine if the browser window should start maximized. + * + * @return bool + */ + protected function shouldStartMaximized() + { + return isset($_SERVER['DUSK_START_MAXIMIZED']) || + isset($_ENV['DUSK_START_MAXIMIZED']); + } } diff --git a/stubs/DuskTestCase.stub b/stubs/DuskTestCase.stub index cfe5431..9b2368c 100644 --- a/stubs/DuskTestCase.stub +++ b/stubs/DuskTestCase.stub @@ -57,7 +57,7 @@ abstract class DuskTestCase extends BaseTestCase $options = (new ChromeOptions)->addArguments($this->filterHeadlessArguments([ '--disable-gpu', '--headless', - '--window-size=1920,1080', + $this->shouldStartMaximized() ? '--start-maximized' : '--window-size=1920,1080', ])); return RemoteWebDriver::create( diff --git a/stubs/FirefoxDuskTestCase.stub b/stubs/FirefoxDuskTestCase.stub index c8b30c5..52949c3 100644 --- a/stubs/FirefoxDuskTestCase.stub +++ b/stubs/FirefoxDuskTestCase.stub @@ -21,11 +21,9 @@ abstract class DuskTestCase extends BaseTestCase */ public static function prepare() { - if (static::runningFirefoxInSail()) { - return; + if (! static::runningFirefoxInSail()) { + static::startFirefoxDriver(); } - - static::startFirefoxDriver(); } /**