【发布时间】:2019-08-18 16:33:12
【问题描述】:
rspec执行时,长时间无响应,则出现Net::ReadTimeout:,测试失败。
目前,我们正在 Ubuntu docker 上构建 rails 5.1.7 的开发环境。 并且为了做包含js的视图测试,测试环境是用系统测试的selenium_chrome_headless搭建的。
我删除了 application.html.erb 的源代码以确定错误发生的位置。
结果,我们发现<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> 会超时。
下面是一些代码。
application.html.erb
<!DOCTYPE html>
<html>
<head>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
</head>
<body>
</body>
</html>
spec/views/hoges/index_spec.rb
require 'rails_helper'
RSpec.feature 'MetaFramesIndex', type: :system, js: true do
scenario 'sample' do
visit hoges_index_path
end
end
rails_helper.rb 的一部分
Capybara.register_driver :selenium_chrome_headless do |app|
browser_options = ::Selenium::WebDriver::Chrome::Options.new
browser_options.args << '--headless'
browser_options.args << '--no-sandbox'
browser_options.args << '--disable-gpu'
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end
config.before(:each) do |example|
if example.metadata[:type] == :system
driven_by :selenium_chrome_headless, screen_size: [1400, 1400]
end
end
错误日志
Failure/Error: visit hoges_index_path
Net::ReadTimeout:
Net::ReadTimeout
[Screenshot]: tmp/screenshots/failures_r_spec_example_groups_hoges_index_sample_529.png
~~~~
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/http/default.rb:129:in `response_for'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/http/default.rb:82:in `request'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/http/common.rb:64:in `call'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/bridge.rb:167:in `execute'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/w3c/bridge.rb:567:in `execute'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/w3c/bridge.rb:59:in `get'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/navigation.rb:32:in `to'
# /usr/local/bundle/gems/capybara-2.18.0/lib/capybara/selenium/driver.rb:49:in `visit'
# /usr/local/bundle/gems/capybara-2.18.0/lib/capybara/session.rb:274:in `visit'
# /usr/local/bundle/gems/capybara-2.18.0/lib/capybara/dsl.rb:50:in `block (2 levels) in <module:DSL>'
# ./spec/views/hoges/index_spec.rb:7:in `block (2 levels) in <top (required)>'
我希望早点回复,而不是超时。
我们将等待答案。
【问题讨论】:
标签: rspec ruby-on-rails-5 capybara