使用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
相关产品推荐
相关产品推荐

