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

使用Firefox运行WebdriverIO测试时遇创建会话失败问题求助

WebdriverIO + Firefox 无法创建会话:连接localhost端口失败

错误信息

ERROR @wdio/runner: Error: Failed to create session.
Unable to connect to "http://localhost:60284/", make sure the browser driver is running on that address.

环境详情

  • WebdriverIO 版本:9.11.0
  • Node.js 版本:22.12.10
  • Firefox 版本:136.0
  • Geckodriver 版本:0.36.0
  • 操作系统:Windows 11

解决方案

1. 修复Geckodriver与Firefox版本兼容性问题

Geckodriver 0.36.0仅支持Firefox 102~115版本,你当前使用的Firefox 136.0版本超出兼容范围,这是核心问题。

  • 下载对应Firefox 136.0的Geckodriver稳定版(推荐0.44.0及以上版本)
  • 替换现有Geckodriver文件,确保新驱动可正常执行

2. 验证Geckodriver的PATH配置

  • 打开命令提示符,执行geckodriver --version,若能返回版本信息则配置正常;若提示“找不到命令”,将Geckodriver所在文件夹添加到系统环境变量PATH中
  • 也可在WebdriverIO配置文件(wdio.conf.js)中直接指定驱动路径:
exports.config = {
    // 其他配置项
    services: ['firefox'],
    capabilities: [{
        browserName: 'firefox',
        'wdio:geckodriverOptions': {
            path: 'C:\\your\\geckodriver\\path\\geckodriver.exe'
        }
    }]
};

3. 手动启动Geckodriver测试连接

  • 打开命令提示符,执行geckodriver --port 60284
  • 打开浏览器访问http://localhost:60284/status,若返回包含"ready":true的JSON内容,说明驱动正常运行;若启动失败,根据控制台报错排查(如权限不足、依赖缺失)

4. 检查端口占用情况

  • 打开命令提示符,执行netstat -ano | findstr :60284,若有结果说明端口被占用
  • 可通过任务管理器结束对应PID的进程,或在WebdriverIO配置中更换端口:
exports.config = {
    // 其他配置项
    capabilities: [{
        browserName: 'firefox',
        'wdio:geckodriverOptions': {
            port: 60285 // 选择未被占用的端口
        }
    }]
};

5. 确认WebdriverIO配置正确性

确保配置文件中启用Firefox服务且capabilities设置无误:

exports.config = {
    runner: 'local',
    services: ['firefox'], // 自动启动Geckodriver的关键配置
    capabilities: [{
        browserName: 'firefox',
        acceptInsecureCerts: true // 按需添加
    }],
    // 其他必要配置(specs、framework等)
};

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 00:17:08