You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Electron与Chrome需不同版本chromedriver的处理方案

测试环境配置
  • @wdio/selenium-standalone-service: ^6.11.0
  • Node 12(暂无法使用wdio-electron-service)
  • Google Chrome 版本:102.0.5005.61
  • Electron 18 应用内置 Chromium 版本:100.0.4896.60
  • Firefox 版本:101.0
问题描述

尝试通过selenium-standalone service同时创建1个Electron会话和1个浏览器会话,使用两组capabilities配置如下:

配置1:Electron会话

capabilities: {
  browserName: 'chrome',
  'goog:chromeOptions': {
    binary: 'Path to Electron binary',
    args: [
      /* cli arguments */
    ], // 可选,通常配置为 'app=' + 应用入口路径
  },
},

配置2:Chrome浏览器会话

capabilities: {
  browserName: 'chrome',
  'goog:chromeOptions': {
    args: [],
  },
}

Chromedriver版本冲突现象

在selenium-standalone的installArgs和args中配置驱动版本时:

  • 若指定chrome驱动版本为100.0.4896.60(匹配Electron内置Chromium),Chrome浏览器会话创建失败
  • 若指定chrome驱动版本为latest(匹配本机Chrome 102),Electron应用会话创建失败

尝试将浏览器会话切换为Firefox,对应capabilities配置:

capabilities: {
  browserName: 'firefox'
}

selenium-standalone驱动配置调整为:

drivers: {
  chrome: { version: '100.0.4896.60' },  // 匹配Electron内置Chromium版本
  firefox: { version: 'latest' }, // 匹配本机Firefox版本
}

此时Electron会话可正常创建,但Firefox会话创建失败,报错如下:

[0-0] 2022-06-03T07:48:28.519Z ERROR @wdio/runner: Error: Failed to create session.
Unable to create session from {
  "desiredCapabilities": {
    "moz:firefoxOptions": {
      "args": [
        "-remote-debugging-port",
        "50030"
      ]
    },
    "browserName": "firefox"
  },
  "capabilities": {
    "firstMatch": [
      {
        "browserName": "firefox",
        "moz:firefoxOptions": {
          "args": [
            "-remote-debugging-port",
            "50030"
          ]
        }
      }
    ]
  }
}
  Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
        System info: host: '-----', ip: '----', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '1.8.0_231'
        Driver info: driver.version: unknown
            at Object.startWebDriverSession (~/node_modules/webdriver/build/utils.js:34:15)
            at processTicksAndRejections (internal/process/task_queues.js:97:5)
解决方案

解决Chrome与Electron的驱动版本冲突

selenium-standalone默认只能启动单个版本的chromedriver,无法同时适配两个不同内核版本的Chromium系应用,有两种可行方案:

  1. 拆分执行流程:写两份独立的WDIO配置,一份配置100版本chromedriver跑Electron用例,一份配置对应Chrome 102版本的chromedriver跑浏览器用例,执行时分开启动,不需要在同一个selenium-standalone实例里同时跑两类会话,改造成本最低。
  2. 多驱动端口分流:手动下载两个版本的chromedriver,分别启动在不同端口(比如100版本绑定9515,102版本绑定9516),WDIO配置中关闭selenium-standalone对chromedriver的自动管理,在两个capabilities中分别通过port参数指定对应驱动的端口,直接连接手动启动的驱动实例。

解决Firefox会话创建失败问题

报错中Driver info: driver.version: unknown是驱动加载失败的典型标识,三个点调整即可修复:

  1. 升级本机Java环境到11及以上版本,当前Java 1.8.0_231版本过低,无法兼容高版本geckodriver和Firefox 101。
  2. 不要用latest指定geckodriver版本,手动固定版本为0.31.0,该版本同时兼容Firefox 101和当前使用的Selenium 3.141.59。
  3. 覆盖默认的Firefox启动参数,在capabilities中显式配置'moz:firefoxOptions': { args: [] },去掉WDIO自动注入的-remote-debugging-port参数——这个参数是Chromium系专属参数,Firefox不识别,会直接导致启动异常。

内容的提问来源于stack exchange,提问作者Claire

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.03 07:51:27