webdriverio / webdriverio/webdriverio

[💡 Feature]: Configure `prefers-reduced-motion`

Open
#11,683 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted Idea 💡 Needs Investigation
Dominant language
TypeScript
Stars
9.8k
Forks
2.7k
Avg merge
2d 13h
Merged PRs (30d)
69

Description

Is your feature request related to a problem?

I'm testing a site where I regularly check for prefers-reduced-motion and enable/disable animations accordingly. However there is no way to exercise this state in WebDriverIO as far as I can tell. This applies to all media features, notably prefers-color-scheme which is relevant to testing dark theme states.

Describe the solution you'd like.

I'd love to see an option to configure media features in the browser. Something like:

browser.mediaFeatures.setPrefersReducedMotion('reduced');
browser.mediaFeatures.setPrefersColorScheme('dark');
// ...

The exact API isn't super important, as long as there is some option we can set.

Describe alternatives you've considered.

I don't believe it is possible to set prefers-reduced-motion through JS, meaning browser.execute(() => /* ... */) is not an option.

It would be possible to set some kind of attribute on the root element and code your CSS to also check for that in addition to prefers-reduced-motion, though this gets awkward fast.

browser.execute(() => document.body.setAttribute('disable-animations', ''));
@media (prefers-reduced-motion: no-preference) {
  body:not([disable-animations]) .some-element {
    transition: /* ... */;
  }
}

This also wouldn't work very well with shadow DOM, where body .some-element doesn't work correctly and you'd need to use :host-context or something like that.

Additional context

While this is a generically useful tool for testing, I think prefers-reduced-motion is particularly useful as a means of disabling animations for testing. If a project consistently uses prefers-reduced-motion to disable animations this means:

  • This flag can be used to turn off all animations for testing.
  • Tests can help enforce that prefers-reduced-motion actually is used consistently. Any time animations are a problem for testing, they are likely also a problem for users sensitive to motion. Fixing your tests is also improving the user experience!

This could be a slightly more generic solution to the general problem of disabling animations in testing, which is the real root problem of https://github.com/webdriverio/webdriverio/issues/3106 and could address that issue as well.

This is assuming that prefers-reduced-motion: reduced is roughly equivalent to "disable animations" which may not be strictly true. I'm not accessibility expert, so I'm not 100% on what the "correct" way to handle this particular setting is.

There is also movement which may be critical for functionality. For example, shooting a bullet in a game needs to move from the source to target, so skipping that animation for prefers-reduced-motion users would fundamentally break the experience. However in those cases, I suspect for testing you actually wouldn't want to skip them anyways, since the bullet's travel time is a key piece of functionality which needs to be handled and tested as well.

Code of Conduct
  • I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by investigating how WebdriverIO exposes browser configuration and whether its current browser automation entry points provide access to media features. Define a supported API for setting prefers-reduced-motion and prefers-color-scheme, then verify that browser media queries observe those values and that the behavior is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.