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

Windows本地运行RSpec系统测试时TCP连接超时问题求助

解决Windows下Rails RSpec系统测试Net::OpenTimeout问题

修复方案

  • 指定Capybara的主机与端口
    在spec/rails_helper.rb或spec/spec_helper.rb中添加配置,避开默认端口可能的冲突:

    Capybara.server_host = '127.0.0.1'
    Capybara.server_port = 3001
    
  • 禁用Chrome沙箱模式
    Windows环境下Chrome沙箱易引发连接异常,添加驱动配置:

    Capybara.register_driver :selenium_chrome do |app|
      options = Selenium::WebDriver::Chrome::Options.new
      options.add_argument('--no-sandbox')
      options.add_argument('--disable-dev-shm-usage')
      Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
    end
    Capybara.javascript_driver = :selenium_chrome
    
  • 排查防火墙/杀毒软件拦截
    临时关闭Windows Defender防火墙或第三方杀毒软件,测试是否恢复正常。若有效,给Ruby进程和Chrome添加防火墙允许规则。

  • 让Webdrivers自动匹配版本
    删除手动安装的ChromeDriver,用gem自动下载适配版本:

    bundle exec webdrivers update chrome
    
  • 延长Capybara超时时间
    调整默认等待时长,适配Windows环境下的启动延迟:

    Capybara.default_max_wait_time = 10
    

测试验证

修改配置后运行测试命令(根据实际测试文件路径调整):

bundle exec rspec spec/system/root_page_spec.rb

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 10:25:35