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

Firefox 59.0与Protractor 5.3.1测试失败求助:会话未创建

解决Firefox 59.0 + Protractor 5.3.1自动化测试的Session创建失败问题

看起来你遇到的核心问题是Firefox与Protractor/GeckoDriver的版本兼容性不对齐,再加上配置细节没踩准。我来一步步帮你排查解决:

一、先明确:是否需要运行webdriver-manager start?

这个完全取决于你directConnect的设置:

  • 如果directConnect: true:不需要启动webdriver-manager,因为Protractor会直接调用浏览器对应的GeckoDriver,绕过Selenium Server。
  • 如果directConnect: false:必须在终端单独启动webdriver-manager start,或者通过selenium-standalone start启动Selenium Server,否则根本无法创建会话。

二、核心症结:版本兼容性不匹配

Firefox 59.0是比较老旧的版本,必须搭配对应版本的GeckoDriver才能正常工作,而Protractor 5.3.1对GeckoDriver的版本有严格要求:

  • Firefox 59.x 对应的GeckoDriver版本是 0.20.1 或 0.21.0(更高版本的GeckoDriver会完全不兼容旧版Firefox)

你之前执行的selenium-standalone install可能默认安装了较新的GeckoDriver,导致版本冲突。可以手动指定版本重新安装:

# 安装适配Firefox 59的指定版本GeckoDriver和Selenium Server
selenium-standalone install --drivers.gecko.version=0.20.1

三、调整Protractor配置文件

在你的protractor.conf.js里,针对Firefox补充以下配置,确保驱动和浏览器正确对接:

exports.config = {
  // 保留你原有的其他配置...
  directConnect: true, // 优先尝试这个模式,流程更简单
  capabilities: {
    browserName: 'firefox',
    // 显式启用Marionette(Firefox 47+默认启用,但手动设置更稳妥)
    marionette: true,
    'moz:firefoxOptions': {
      args: ['--no-sandbox'] // 解决部分环境下的权限限制问题
      // 可选:如果Firefox不在系统默认路径,手动指定二进制文件位置
      // binary: '/Applications/Firefox.app/Contents/MacOS/firefox-bin'
    }
  },
  // 如果后续切换到directConnect: false,需要开启下面这行
  // seleniumAddress: 'http://localhost:4444/wd/hub',
};

四、额外排查步骤

  1. 验证GeckoDriver版本:在终端运行geckodriver --version,确认显示的是0.20.1或0.21.0
  2. 清理旧驱动缓存:如果之前安装过其他版本的GeckoDriver,先删除旧文件再重新安装指定版本
  3. 测试极简用例:写一个无干扰的测试脚本,排除业务代码的影响:
describe('Firefox Basic Test', function() {
  it('should open Google successfully', function() {
    browser.get('https://www.google.com');
    expect(browser.getTitle()).toEqual('Google');
  });
});

五、如果还是失败?

仔细查看终端的完整报错信息,session not created通常会附带更具体的原因(比如驱动路径错误、Firefox二进制文件找不到等)。如果是驱动路径问题,可以在配置里手动指定GeckoDriver的位置:

exports.config = {
  // 其他配置...
  geckoDriver: '/usr/local/bin/geckodriver', // 替换成你的GeckoDriver实际路径
};

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 06:22:29