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

使用Firefox运行Nightwatch测试时遇Binary location error问题求助

解决Firefox在Nightwatch.js中无法找到浏览器二进制文件的问题

你需要在night.conf.js的Firefox测试配置中,通过moz:firefoxOptions显式指定Firefox可执行文件的路径。修改后的完整配置如下:

module.exports = {
  src_folders: ['tests'],
  webdriver: {
      start_process: true,
      port: 4444
  },
  test_settings: {
      default: {
          desiredCapabilities: {
              browserName: 'chrome'
          },
          webdriver: { server_path: require('chromedriver').path },
          
          'screenshots': {
            'enabled': true,
            'on_failure': true,
            'path': './screens'
          },

          'test_workers': {
            'enabled': false,
            'workers': 'auto'
          },
      },
      firefox: {
          desiredCapabilities: {
              browserName: 'firefox',
              'moz:firefoxOptions': {
                  binary: 'C:\\Program Files\\Mozilla Firefox\\firefox.exe'
              }
          },
          webdriver: { server_path: require('geckodriver').path }
      }
  }
};

说明

  • 核心修改是在firefox配置的desiredCapabilities下新增moz:firefoxOptions对象,通过binary字段指定你确认的Firefox路径(Windows路径需用双反斜杠转义)。
  • 即便Firefox在默认安装路径,Geckodriver有时会因系统环境变量差异、权限问题无法自动检测到二进制文件,显式指定路径可以彻底解决这个定位问题。

修改完成后,重新执行测试命令npm test -- -t tests/github.js --env firefox即可正常运行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 10:05:22