Rspec Capybara Webkit: Random Unable to find matching string from backtrace
I am setting up tests with Rspec (3.0.0), Capybara (2.4.4) and Capybara-Webkit (1.5.1). My application uses Sinatra, so this is not a Rails application.
I have a strange error that seems random. This happens maybe once every three or four tries, but it makes the rest of the tests fail. When it passes, everything is fine and Rspec is not complaining.
I tried reinstalling every stone, putting statements sleep
everywhere, increasing the timeout to an unreasonable value, but nothing worked. I messed up with the gems version, but the error keeps returning. I tried to put the test in the rescue block, shame on me, but even that didn't work.
The answers I could find looked out of date and the software update didn't fix the issues. Another answer suggested a problem with Chrome plugins, but that didn't work either.
Here's the information I was able to gather:
- It is associated with a test that opens a new window (see below). Maybe some kind of interaction / timing error?
- When I put logs everywhere it seems to get to the end of the test and the statement
expect
is true. It looks like the error occurs after exiting the test. - When this happens, the rest of the test will fail as well, with the following code:
Errno::EPIPE:Broken pipe
Relevant part of the Gemfile:
gem 'byebug' # debugger
gem 'capybara'
gem 'capybara-webkit'
gem 'rspec', '~> 3.0.0' # tdd'
gem 'faker' # create fake, but realistic data
gem 'launchy'
Failed test content:
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
Results in case of failure (I've included the following test, it returns the same for every test after that):
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)>'
Any help would be greatly appreciated! Even a debug / logging tool would be very helpful.
Thank!
Update:
After using webkit_debug, it would be difficult for me to determine that the error is being triggered when using the browser's capybara reset. Here is the output of 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:
source to share
Capybara's default behavior is to reset sessions after each test, in: after the hook. As stated in the stack trace, this function (reset_sessions!) Was breaking my tests.
As a workaround, I monkey paid a Capybara Gem so that I could select a reset session after the test.
Here is my monkey patch:
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
After that, I just do Capybara.keep_sessions=true
at the end of the problematic test. It works, error dissapearead but I know it is not perfect.
Hope this helps!
source to share