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

feat: add PANTHER_REDUCED_MOTION to limit animations #651

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
-----

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions src/ProcessManager/ChromeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
9 changes: 9 additions & 0 deletions src/ProcessManager/FirefoxManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,6 +64,14 @@ public function start(): WebDriver
$capabilities = DesiredCapabilities::firefox();
$capabilities->setCapability('moz:firefoxOptions', $firefoxOptions);

// Prefer reduced motion, see https://developer.mozilla.org/fr/docs/Web/CSS/@media/prefers-reduced-motion
if ($_SERVER['PANTHER_REDUCED_MOTION'] ?? false) {
/** @var FirefoxOptions|array $firefoxOptions */
$firefoxOptions = $capabilities->getCapability('moz:firefoxOptions') ?? [];
$firefoxOptions = $firefoxOptions instanceof FirefoxOptions ? $firefoxOptions->toArray() : $firefoxOptions;
$firefoxOptions['prefs']['ui.prefersReducedMotion'] = 'reduced';
}

foreach ($this->options['capabilities'] as $capability => $value) {
$capabilities->setCapability($capability, $value);
}
Expand Down
Loading