Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webdriver.io/Selenium tests fail when the window is in the background on Chrome 87

I've just upgraded to the latest version of Chrome 87. My Webdriver.io/Selenium tests used to run fine regardless of if the Chrome window was in the foreground or the background. Now, after upgrading, the tests pass if the window is in the foreground, but not if it's in the background.

I'm not minimizing the Chrome window running my tests. I'm just pressing Alt+Tab so that my IDE is in front of Chrome and it's behind.

I know Chrome 87 has a new "feature" where it uses less CPU if it's not in the foreground. Is there a way to turn this off with either Chrome or Chromedriver settings?

It seems that my test is finding the button to click on, but Chrome isn't registering the click.

like image 815
Ryan Shillington Avatar asked Nov 19 '20 18:11

Ryan Shillington


2 Answers

This is a bug in Chrome 87:

https://bugs.chromium.org/p/chromedriver/issues/detail?id=3641&sort=-id

Workaround

Node JS

The workaround is to set the "localState" in Webdriver.io's desiredCapabilities like the below in Node.JS/Chimpy:

chimpOptions.webdriverio.desiredCapabilities = {
  chromeOptions: {
    args: ["--no-sandbox", ...],
    prefs: {...}
    },
    localState: {
      "browser.enabled_labs_experiments": ["calculate-native-win-occlusion@2"],
    },
  },
  ...
};

Java

ChromeOptions options = new ChromeOptions();
   
HashMap<String, Object> chromeLocalStatePrefs = new HashMap<String, Object>();
List<String> experimentalFlags = new ArrayList<String>();
experimentalFlags.add("calculate-native-win-occlusion@2");
chromeLocalStatePrefs.put("browser.enabled_labs_experiments", experimentalFlags);
options.setExperimentalOption("localState", chromeLocalStatePrefs);

Previous Answer

The other workaround is to leave a small lip of the background Chrome window underneath your active browser/IDE/etc.

In the image below, you can see a small amount of the Chrome window running the test.

enter image description here

like image 170
Ryan Shillington Avatar answered Sep 21 '22 18:09

Ryan Shillington


the latest chrome - chromedriver has resolved this issue enter image description here

like image 33
mo-ta-to Avatar answered Sep 21 '22 18:09

mo-ta-to