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

