当窗口位于 Chrome 87 的后台时,Webdriver.io/Selenium 测试失败

Rya*_*ton 8 webdriver node.js selenium-webdriver webdriver-io

我刚刚升级到最新版本的 Chrome 87。无论 Chrome 窗口是在前台还是后台,我的 Webdriver.io/Selenium 测试都可以正常运行。现在,升级后,如果窗口在前台,则测试通过,但如果它在后台则不通过。

我没有最小化运行我的测试的 Chrome 窗口。我只是按 Alt+Tab,这样我的 IDE 就在 Chrome 前面,它在后面。

我知道 Chrome 87 有一个新的“功能”,如果它不在前台,它会使用更少的 CPU。有没有办法使用 Chrome 或 Chromedriver 设置关闭它?

似乎我的测试是找到要点击的按钮,但 Chrome 没有注册点击。

Rya*_*ton 7

这是 Chrome 87 中的一个错误:

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

解决方法

节点JS

解决方法是desiredCapabilities在 Node.JS/Chimpy 中设置 Webdriver.io 中的“localState”,如下所示:

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

爪哇

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);
Run Code Online (Sandbox Code Playgroud)

上一个答案

另一种解决方法是在您的活动浏览器/IDE/等下方留下背景 Chrome 窗口的一小部分。

在下图中,您可以看到运行测试的少量 Chrome 窗口。

在此处输入图片说明


mo-*_*-to 4

最新的 chrome - chromedriver 已经解决了这个问题 在此输入图像描述