From 3315ce1db4de6563a15180bd8e43d9a916202453 Mon Sep 17 00:00:00 2001 From: "hubert.lenoir" Date: Tue, 10 Dec 2024 16:23:42 +0100 Subject: [PATCH] feat: add PANTHER_REDUCED_MOTION to limit animations --- CHANGELOG.md | 5 +++++ README.md | 1 + src/ProcessManager/ChromeManager.php | 5 +++++ src/ProcessManager/FirefoxManager.php | 17 +++++++++++------ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dde7475..e8ccb7ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +2.2.0 +----- + +* Add a `PANTHER_REDUCED_MOTION` environment variable to instruct the website to minimize the amount of non-essential movement + 2.1.2 ----- diff --git a/README.md b/README.md index 8a809bb1..e08f23a2 100644 --- a/README.md +++ b/README.md @@ -366,6 +366,7 @@ The following environment variables can be set to change some Panther's behaviou * `PANTHER_ERROR_SCREENSHOT_DIR`: to set a base directory for your failure/error screenshots (e.g. `./var/error-screenshots`) * `PANTHER_DEVTOOLS`: to toggle the browser's dev tools (default `enabled`, useful to debug) * `PANTHER_ERROR_SCREENSHOT_ATTACH`: to add screenshots mentioned above to test output in junit attachment format +* `PANTHER_REDUCED_MOTION`: to instruct the website to minimize the amount of non-essential movement ### Changing the Hostname and Port of the Built-in Web Server diff --git a/src/ProcessManager/ChromeManager.php b/src/ProcessManager/ChromeManager.php index 50f90565..cced1f88 100644 --- a/src/ProcessManager/ChromeManager.php +++ b/src/ProcessManager/ChromeManager.php @@ -114,6 +114,11 @@ private function getDefaultArguments(): array $args[] = '--no-sandbox'; } + // Prefer reduced motion, see https://developer.mozilla.org/fr/docs/Web/CSS/@media/prefers-reduced-motion + if ($_SERVER['PANTHER_REDUCED_MOTION'] ?? false) { + $args[] = '--force-prefers-reduced-motion'; + } + // Add custom arguments with PANTHER_CHROME_ARGUMENTS if ($_SERVER['PANTHER_CHROME_ARGUMENTS'] ?? false) { $arguments = explode(' ', $_SERVER['PANTHER_CHROME_ARGUMENTS']); diff --git a/src/ProcessManager/FirefoxManager.php b/src/ProcessManager/FirefoxManager.php index 10c3cd3e..7114a70a 100644 --- a/src/ProcessManager/FirefoxManager.php +++ b/src/ProcessManager/FirefoxManager.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Panther\ProcessManager; +use Facebook\WebDriver\Firefox\FirefoxOptions; use Facebook\WebDriver\Remote\DesiredCapabilities; use Facebook\WebDriver\Remote\RemoteWebDriver; use Facebook\WebDriver\WebDriver; @@ -52,16 +53,20 @@ public function start(): WebDriver $this->waitUntilReady($this->process, $url.$this->options['path'], 'firefox'); } - $firefoxOptions = []; + $capabilities = DesiredCapabilities::firefox(); + + /** @var FirefoxOptions $firefoxOptions */ + $firefoxOptions = $capabilities->getCapability(FirefoxOptions::CAPABILITY); if (isset($_SERVER['PANTHER_FIREFOX_BINARY'])) { - $firefoxOptions['binary'] = $_SERVER['PANTHER_FIREFOX_BINARY']; + $firefoxOptions->setOption('binary', $_SERVER['PANTHER_FIREFOX_BINARY']); } if ($this->arguments) { - $firefoxOptions['args'] = $this->arguments; + $firefoxOptions->addArguments($this->arguments); + } + // Prefer reduced motion, see https://developer.mozilla.org/fr/docs/Web/CSS/@media/prefers-reduced-motion + if ($_SERVER['PANTHER_REDUCED_MOTION'] ?? false) { + $firefoxOptions->setPreference('ui.prefersReducedMotion', 'reduced'); } - - $capabilities = DesiredCapabilities::firefox(); - $capabilities->setCapability('moz:firefoxOptions', $firefoxOptions); foreach ($this->options['capabilities'] as $capability => $value) { $capabilities->setCapability($capability, $value);