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
Changes from 1 commit
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
Next Next commit
feat: add PANTHER_REDUCED_MOTION to limit animations
Jean-Beru committed Dec 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 3315ce1db4de6563a15180bd8e43d9a916202453
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
-----

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

5 changes: 5 additions & 0 deletions src/ProcessManager/ChromeManager.php
Original file line number Diff line number Diff line change
@@ -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']);
17 changes: 11 additions & 6 deletions src/ProcessManager/FirefoxManager.php
Original file line number Diff line number Diff line change
@@ -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);

Unchanged files with check annotations Beta

/**
* @return FormField|FormField[]|FormField[][]
*/
public function get($name): FormField|array

Check failure on line 215 in src/DomCrawler/Form.php

GitHub Actions / Static Analysis

Method Symfony\Component\Panther\DomCrawler\Form::get() never returns array<array<Symfony\Component\DomCrawler\Field\FormField>|Symfony\Component\DomCrawler\Field\FormField> so it can be removed from the return type.
{
return $this->getFormField($this->getFormElement($name));
}
public function testAncestors(callable $clientFactory): void
{
$crawler = $this->request($clientFactory, '/basic.html');
if (!method_exists($crawler, 'ancestors')) {

Check failure on line 290 in tests/DomCrawler/CrawlerTest.php

GitHub Actions / Static Analysis

Call to function method_exists() with Symfony\Component\DomCrawler\Crawler and 'ancestors' will always evaluate to true.
$this->markTestSkipped('Crawler::ancestors() doesn\'t exist.');
}