我正在使用Rspec(3.0.0),Capybara(2.4.4)和Capybara-Webkit(1.5.1)设置前端测试。我的应用程序使用Sinatra,因此它不是Rails应用程序 我得到了一个奇怪的错误,似乎是随机的。它可能每三到四次尝试一次,但它会使其余的测试失败。当它通过时一切都很好,Rspec不会抱怨。
我尝试重新安装每个gem,在任何地方放置sleep
语句,将等待时间增加到不合理的值,但没有任何效果。
我搞砸了宝石的版本,但错误不断回来。我试图将测试放在救援区,对我感到羞耻,但即便如此也没有用
我能找到的答案似乎已经过时,更新软件并没有解决问题。另一个答案表明Chrome插件存在问题,但这也没有用。
以下是我能够收集的信息:
expect
语句为真。退出测试后似乎提出错误。Errno::EPIPE:Broken pipe
Gemfile的相关部分:
gem 'byebug' # debugger
gem 'capybara'
gem 'capybara-webkit'
gem 'rspec', '~> 3.0.0' # tdd'
gem 'faker' # create fake, but realistic data
gem 'launchy'
失败测试的内容:
it 'should submit signup form and open auth popup' do
page.fill_in('email', with: EMAIL)
page.fill_in('password', with: PASSWORD)
page.within_window window_opened_by {click_button 'Sign Up'} do
page.fill_in('EmailAddress', with: EMAIL)
page.fill_in('Password', with: PASSWORD)
page.click_button('sign-in')
end
while auth_connect = page.has_selector?('.loading-container.active.visible')
sleep 0.5
end
expect(checkElementsKyc(page)).to be true
end
失败案例中的结果(我已经包含了下一个测试,之后每次测试返回相同的内容):
Failures:
1) signup_flow signup should submit signup form and open dwolla auth popup
Failure/Error: Unable to find matching line from backtrace
EOFError:
end of file reached
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/capybara-webkit-1.5.1/lib/capybara/webkit/connection.rb:49:in `read_nonblock'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/capybara-webkit-1.5.1/lib/capybara/webkit/connection.rb:49:in `read'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/capybara-webkit-1.5.1/lib/capybara/webkit/connection.rb:40:in `gets'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/capybara-webkit-1.5.1/lib/capybara/webkit/browser.rb:283:in `check'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/capybara-webkit-1.5.1/lib/capybara/webkit/browser.rb:210:in `command'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/capybara-webkit-1.5.1/lib/capybara/webkit/browser.rb:38:in `reset!'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/capybara-webkit-1.5.1/lib/capybara/webkit/driver.rb:251:in `reset!'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/capybara-2.4.4/lib/capybara/session.rb:103:in `reset!'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/capybara-2.4.4/lib/capybara.rb:257:in `block in reset_sessions!'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/capybara-2.4.4/lib/capybara.rb:257:in `each'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/capybara-2.4.4/lib/capybara.rb:257:in `reset_sessions!'
# /home/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/capybara-2.4.4/lib/capybara/rspec.rb:20:in `block (2 levels) in <top (required)>'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:287:in `instance_exec'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:287:in `instance_exec_with_rescue'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:356:in `run'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:410:in `block in run'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:410:in `each'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:410:in `run'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:485:in `run'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:344:in `run_after_example'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:163:in `block in run'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:301:in `with_around_example_hooks'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:145:in `run'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:494:in `block in run_examples'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:490:in `map'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:490:in `run_examples'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:457:in `run'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:458:in `block in run'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:458:in `map'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:458:in `run'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:112:in `block (2 levels) in run_specs'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:112:in `map'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:112:in `block in run_specs'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/reporter.rb:54:in `report'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:108:in `run_specs'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:86:in `run'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:70:in `run'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:38:in `invoke'
# /home/xalio08/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.4/exe/rspec:4:in `<top (required)>'
# /home/xalio08/.rbenv/versions/2.1.4/bin/rspec:23:in `load'
# /home/xalio08/.rbenv/versions/2.1.4/bin/rspec:23:in `<main>'
#
# Showing full backtrace because every line was filtered out.
# See docs for RSpec::Configuration#backtrace_exclusion_patterns and
# RSpec::Configuration#backtrace_inclusion_patterns for more information.
2) signup_flow edit_details should not pass test with invalid dob
Failure/Error: Unable to find matching line from backtrace
Errno::EPIPE:
Broken pipe
# ./test/scripts/test_helper.rb:18:in `block (2 levels) in <top (required)>'
任何帮助将不胜感激!即使是调试/日志记录工具也非常有用。
谢谢!
更新:
使用webkit_debug后,我无法确定当capybara重置浏览器时是否触发了错误。以下是webkit_debug的输出:
Finished "Node.attribute" with response "Success(true)"
Wrote response true "true"
Received "Reset()"
Started "Reset()"
Aborting request to ""
should submit signup form and open auth popup (FAILED - 1)
Failures:
答案 0 :(得分:0)
Capybara默认行为是在每次测试后重置会话,在:挂钩后。 如堆栈跟踪所示,此函数(reset_sessions!)导致我的测试崩溃。
作为一个临时的解决方案,我在修补Capybara Gem以便在测试后我可以选择是否重置会话。
这是我的猴子补丁:
module Capybara
class << self
attr_accessor :keep_sessions
def reset_sessions!
unless Capybara.keep_sessions
session_pool.each { |mode, session| session.reset! }
end
end
alias_method :reset!, :reset_sessions!
end
end
之后我只是在问题测试结束时做Capybara.keep_sessions=true
。它正在工作,错误消失,但我知道这并不理想。
希望这有帮助!