webdriverio / webdriverio

Next-gen browser and mobile automation test framework for Node.js
http://webdriver.io
MIT License
9.01k stars 2.5k forks source link

[🐛 Bug]: isStable method fails if test executes in the browser which is in the background or in the tray #11995

Open HannaTarasevich opened 8 months ago

HannaTarasevich commented 8 months ago

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

latest

Node.js Version

latest

Mode

Standalone Mode

Which capabilities are you using?

{
  "name": "my-new-project",
  "type": "module",
  "devDependencies": {
    "@wdio/cli": "^8.27.2",
    "@wdio/cucumber-framework": "^8.27.2",
    "@wdio/dot-reporter": "^8.23.0",
    "@wdio/local-runner": "^8.27.2",
    "@wdio/spec-reporter": "^8.27.2",
    "chai": "^4.3.10",
    "wdio-wait-for": "^3.0.9"
  },
  "scripts": {
    "wdio": "wdio run ./wdio.conf.js"
  }
}

What happened?

Suppose the tests are running in the browser in the background (fully covered by any other window), or the browser with running tests is minimized to tray. In that case, isStable method fails with an error AssertionError: javascript error: You are are checking for animations on an inactive tab, animations do not run for inactive tabs.

It would be pretty much useful not to fail the method, since actually animations are working in the application even in such cases (e.g., some animation after clicking on other elements like animated dropdown menu appearing).

    if (document.visibilityState === 'hidden') {
        throw Error('You are are checking for animations on an inactive tab, animations do not run for inactive tabs')
    }

What is your expected behavior?

isStable is working even if browser tests execution is in the background or in the tray.

How to reproduce the bug.

https://github.com/HannaTarasevich/wdio-timeout-issue

Steps: 1) npm run wdio 2) minimize appeared Chrome for testing browser to the tray right after it appears

Relevant log output

[chrome 120.0.6099.217 windows #0-0] 1) As a user, I can log into the secure area When I login with tomsmith and SuperSecretPassword!
[chrome 120.0.6099.217 windows #0-0] Error: javascript error: You are are checking for animations on an inactive tab, animations do not run for inactive tabs
[chrome 120.0.6099.217 windows #0-0] Error: javascript error: You are are checking for animations on an inactive tab, animations do not run for inactive tabs
[chrome 120.0.6099.217 windows #0-0] JavaScript stack:
[chrome 120.0.6099.217 windows #0-0] Error: You are are checking for animations on an inactive tab, animations do not run for inactive tabs
[chrome 120.0.6099.217 windows #0-0]     at isElementStable (eval at executeAsyncScript (:447:26), <anonymous>:5:15)
[chrome 120.0.6099.217 windows #0-0]     at eval (eval at executeAsyncScript (:447:26), <anonymous>:25:4)
[chrome 120.0.6099.217 windows #0-0]     at eval (eval at executeAsyncScript (:447:26), <anonymous>:26:4)
[chrome 120.0.6099.217 windows #0-0]     at executeAsyncScript (<anonymous>:447:47)
[chrome 120.0.6099.217 windows #0-0]     at apply.ELEMENT (<anonymous>:462:29)
[chrome 120.0.6099.217 windows #0-0]     at callFunction (<anonymous>:341:22)
[chrome 120.0.6099.217 windows #0-0]     at <anonymous>:355:23
[chrome 120.0.6099.217 windows #0-0]     at <anonymous>:356:3
[chrome 120.0.6099.217 windows #0-0]   (Session info: chrome=120.0.6099.217)

Code of Conduct

Is there an existing issue for this?

christian-bromann commented 8 months ago

@erwinheitzman what do you think?

wdio-bot commented 8 months ago

Thanks for reporting!

We greatly appreciate any contributions that help resolve the bug. While we understand that active contributors have their own priorities, we kindly request your assistance if you rely on this bug being fixed. We encourage you to take a look at our contribution guidelines or join our friendly Discord development server, where you can ask any questions you may have. Thank you for your support, and cheers!

BorisOsipov commented 8 months ago

It would be pretty much useful not to fail the method, since actually animations are working in the application even in such cases (e.g., some animation after clicking on other elements like animated dropdown menu appearing).

No. If the browser tab is inactive, the real browser may slow down or even stop the animation.

We cannot detect if there is an active animation due to Policies in place to aid background page performance

Most browsers stop sending `requestAnimationFrame()` callbacks to background tabs or hidden in order to improve performance and battery life.

So if we remove the check

    if (document.visibilityState === 'hidden') {
        throw Error('You are are checking for animations on an inactive tab, animations do not run for inactive tabs')
    }

You just get weird javacript timeout error instead of actual meaningful error.

HannaTarasevich commented 8 months ago

@BorisOsipov any ideas how the script can be improved?

BorisOsipov commented 8 months ago

@HannaTarasevich

Improved in what direction? We can detect animation only via requestAnimationFrame() callback. Such callback never calls in hidden browser.

If we ignore that the browser is hidden and return true in such a case - we lie to people because actually animation may still be in progress and vice-versa.

I think there may some chromium\ff browser startup args to prevent background trolling, but that is outside the scope of wdio and this script.

BorisOsipov commented 8 months ago

E.g. for chromium it seems --disable-renderer-backgrounding arg.

HannaTarasevich commented 8 months ago

Got it, thanks. Looks like there is no way to use the method for such cases Animations are working with visibilityState = hidden for my case, so the flag won't help