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

Windows系统下Chrome搭配Nightwatch无法使用?求解决方法

解决Chrome更新后Nightwatch测试在Windows 10上的问题

这些都是Chrome版本更新后,和Nightwatch、ChromeDriver兼容性常见的坑,我帮你逐个拆解解决:

1. 受控浏览器显示data:而非加载目标页面

这个大概率是ChromeDriver与Chrome版本不匹配,或者启动配置存在冲突:

  • 先确认Chrome和ChromeDriver版本严格对应:比如Chrome 116.x必须搭配ChromeDriver 116.x,哪怕是最新版也要保证版本号完全对齐(ChromeDriver下载页会明确标注支持的Chrome版本范围)。
  • 检查Nightwatch配置里的launch_url是否正确,同时确认测试用例中browser.url()的目标地址没有拼写错误。
  • 在chromeOptions里添加"useAutomationExtension": false,这个参数会禁用Chrome自带的自动化扩展,避免扩展加载异常导致页面无法正常启动。

2. 弹出“禁用开发者模式扩展”弹窗

这是Chrome默认拦截自动化工具扩展的提示,直接在启动配置里屏蔽即可:

  • 在chromeOptions的excludeSwitches中加入enable-automation,同时配合useAutomationExtension: false,配置示例如下:
chromeOptions: {
  excludeSwitches: ['enable-automation'],
  useAutomationExtension: false,
  // 其他参数...
}
  • 如果测试不需要任何浏览器扩展,也可以在args里添加--disable-extensions,但上面的配置更精准,不会影响自动化必要的功能。

3. --ignore-certificate-errors不再受支持的警告

Chrome已经废弃了这个参数的直接使用,推荐用更合规的替代方案:

  • 去掉--ignore-certificate-errors参数,改用Selenium原生的acceptInsecureCerts: true配置,放在desiredCapabilities或者chromeOptions中均可,这个参数会让WebDriver自动接受测试环境的自签名证书。
  • 如果需要针对特定证书放行,可以使用--ignore-certificate-errors-spki-list参数并跟上证书的SPKI指纹,但一般测试环境用acceptInsecureCerts就足够覆盖需求。

完整配置示例片段

给你一个参考的Nightwatch配置(nightwatch.conf.js):

module.exports = {
  src_folders: ['tests'],
  test_settings: {
    default: {
      launch_url: 'https://your-test-domain.com', // 替换成你的测试地址
      webdriver: {
        start_process: true,
        server_path: require('chromedriver').path,
        port: 9515,
        cli_args: ['--log-level=info']
      },
      desiredCapabilities: {
        browserName: 'chrome',
        acceptInsecureCerts: true,
        chromeOptions: {
          args: [
            '--no-sandbox',
            '--disable-dev-shm-usage',
            '--window-size=1920,1080'
          ],
          excludeSwitches: ['enable-automation'],
          useAutomationExtension: false
        }
      }
    }
  }
};

最后重启测试环境,也可以尝试清理Chrome缓存(比如在args里加--user-data-dir=./temp-chrome-profile创建临时用户目录),应该就能解决这些问题了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 08:55:22