Capybara-webkit stops / hangs unexpectedly and inconsistently
Firstly, I appreciate how hard it is to debug this issue, or even figure out if Capybara-webkit is indeed at fault, but I believe Capybara-Webkit, QT Webkit, and or Capybara are causing the problem, with the former two being the more likely. So I appreciate any help if you can help.
I am on OS X 10.8.1 with the latest version of all gems, QT webkit 4.8.3 and Ruby 1.9.3 available. I'll post the info further down for your reference.
I have found that recently after upgrading my OS and installing the latest QT & Capybara-webkit Gem, when running a few small Cucumber tests using rake cucumber:wip everything tends to work fine. However, when I run the full suite I find the tests just hang for some reason, and never fix themselves. I have seen this in my CI environment (Mac as well, but OS OX 10.7, and latest versions of everything else) as well. However, if I set Capybara.javascript_driver = :selenium instead of Capybara.javascript_driver = :webkit then I don't experience this behaviour
I can reproduce this error easily by running rake cucumber, the first 34 scenarios across 5 feature files run OK, and then oddly when I hit the 6th feature file (one of many more), it hangs on the first scenario before what seems like Capybara-Webkit has even been invoked. However, clearly it is because when Selenium is used this issue does not exist.
Here is the output from the test on that scenario showing, and importantly it does not seem like the @javascript interpretor has yet been invoked (I use capybara-webkit) as it got stuck on the Background portion:
Feature: Backlog Other Functionality
In order to manage a backlog
A visitor
Should be able to rely on some necessary functionality
Background: # features/backlog_other.feature:6
Given the database has the necessary lookup tables # features/step_definitions/shared_steps.rb:1
And a user named "John" is registered # features/step_definitions/authentication_steps.rb:1
The @javascript declaration in fact comes later in the scenario declaration, not in the background section, so to be honest I'm not sure if Capybara detects that in advance and switches to the :javascript driver, or if it only switches when the Scenario starts that is tagged with @javascript.
Anyway, clearly it is hanging on the next step in the Background which is And I am signed in as "John"
The code for this step is as follows:
step %{I am on the home page}
step %{I follow "Log in"}
step %{I fill in "Email" with "#{user_name.gsub(/ /,'')}@acme.com"}
step %{I fill in "Password" with "password"}
step %{I press "Log in"}
step %{I should see the notice "Signed in successfully."}
Now I could include all the code for this step if you want, but it's all pretty bog standard Capybara code. For example, here are two of the steps:
Given /^(?:|I )am on (.+)$/ do |page_name|
visit path_to(page_name)
end
When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
with_scope(selector_to(selector)) do
click_link(link)
end
end
So why it should hang on this step confuses me. There is certainly nothing in those steps that warrants any odd behaviour, and if I run that test individually it works just fine.
I have included a debug log using Capybara.javascript_driver = :webkit_debug for:
- A full
rake cucumberwhich fails every time and hangs - please see capybara-webkit.log rake cucumber:wipwhich runs the same scenario tagged with @wip that fails when run as part ofrake cucumber- please see capybara-webkit-wip.log
So why it works on its own, and not with others is beyond me.
Looking at the log it seems that it gets stuck at the last line http://127.0.0.1:64775/
Oddly however, whilst it is hung, I run the following command and it responds just fine: $ curl http://127.0.0.1:64775/ -I HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 X-Ua-Compatible: IE=Edge,chrome=1 Etag: "5ea29e44392cd954eb3c57e2464ad3b0" Cache-Control: max-age=0, private, must-revalidate X-Request-Id: 408a00e6fcecefc59c7837b6f9215d79 X-Runtime: 0.035834 Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20) Date: Wed, 17 Oct 2012 17:04:18 GMT Content-Length: 0 Connection: Keep-Alive Set-Cookie: _easybacklog_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJTdlMzBhZTFkODEyZDRjYmQ0ZDMyNDAyNTBmZjk1OWJkBjsAVEkiDWxhc3RfdXJsBjsARkkiBi8GOwBG--ac40a5343fc67f1e0d8563994c10a068839ef97e; path=/; HttpOnly
Here is some info on my environment:
OS X Version: 10.8.1 Ruby: ruby-1.9.3-p194 using RVM XCode version: 4.5.1
$ gcc --version i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
$ bundle list Gems included by the bundle:
- Ascii85 (1.0.2)
- ZenTest (4.8.2)
- actionmailer (3.2.8)
- actionpack (3.2.8)
- activemodel (3.2.8)
- activerecord (3.2.8)
- activeresource (3.2.8)
- activesupport (3.2.8)
- acts_as_list (0.1.8)
- addressable (2.3.2)
- arel (3.0.2)
- autotest (4.4.6)
- autotest-growl (0.2.16)
- autotest-rails (4.1.2)
- awesome_print (1.1.0)
- bcrypt-ruby (3.0.1)
- builder (3.0.3)
- bundler (1.2.0)
- capybara (1.1.2)
- capybara-screenshot (0.2.2)
- capybara-webkit (0.12.1)
- childprocess (0.3.5)
- chunky_png (1.2.6)
- coderay (1.0.8)
- columnize (0.3.6)
- compass (0.12.2)
- compass-960-plugin (0.10.4)
- compass-rails (1.0.3)
- cucumber (1.2.1)
- cucumber-rails (1.3.0)
- database_cleaner (0.9.1)
- debugger (1.2.0)
- debugger-linecache (1.1.2)
- debugger-ruby_core_source (1.1.3)
- deep_merge (1.0.0)
- devise (2.1.2)
- devise-encryptable (0.1.1)
- diff-lcs (1.1.3)
- ejs (1.1.1)
- email_spec (1.2.1)
- erubis (2.7.0)
- exceptional (2.0.32)
- excon (0.16.4)
- execjs (1.4.0)
- factory_girl (4.1.0)
- factory_girl_rails (4.1.0)
- ffi (1.1.5)
- foreman (0.60.0)
- fssm (0.2.9)
- gherkin (2.11.4)
- growl (1.0.3)
- haml (3.1.7)
- hashery (2.0.1)
- heroku (2.32.11)
- heroku-api (0.3.5)
- heroku_san (3.0.4)
- hike (1.2.1)
- hpricot (0.8.6)
- httparty (0.9.0)
- i18n (0.6.1)
- journey (1.0.4)
- jquery-rails (2.1.3)
- jslint_on_rails (1.1.1)
- json (1.7.5)
- kgio (2.7.4)
- launchy (2.1.2)
- libwebsocket (0.1.5)
- mail (2.4.4)
- method_source (0.8)
- mime-types (1.19)
- multi_json (1.3.6)
- multi_xml (0.5.1)
- netrc (0.7.7)
- newrelic_rpm (3.4.2)
- nokogiri (1.5.5)
- orm_adapter (0.4.0)
- pdf-reader (1.2.0)
- pg (0.14.1)
- polyglot (0.3.3)
- prawn (0.12.0)
- pry (0.9.10)
- pry-rails (0.0.4 6dd39e3)
- quiet_assets (1.0.1)
- rack (1.4.1)
- rack-cache (1.2)
- rack-force_domain (0.2.0 ff16ac9)
- rack-ssl (1.3.2)
- rack-test (0.6.2)
- rails (3.2.8)
- railties (3.2.8)
- raindrops (0.10.0)
- rake (0.9.2.2)
- rdoc (3.12)
- recursive-open-struct (0.2.2 8178fa5)
- redis (2.2.2)
- redis-namespace (1.0.3)
- rest-client (1.6.7)
- rspec (2.11.0)
- rspec-core (2.11.1)
- rspec-expectations (2.11.3)
- rspec-mocks (2.11.3)
- rspec-rails (2.11.0)
- ruby-rc4 (0.1.5)
- ruby_parser (2.3.1)
- rubyzip (0.9.9)
- sass (3.2.1)
- sass-rails (3.2.5)
- selenium-webdriver (2.25.0)
- sequel (3.20.0)
- sexp_processor (3.2.0)
- shortly (0.3.3)
- shoulda-matchers (1.4.0)
- sinatra (1.0)
- slop (3.3.3)
- sprockets (2.1.3)
- taps (0.3.24)
- thor (0.16.0)
- tilt (1.3.3)
- timecop (0.5.2)
- treetop (1.4.11)
- ttfunk (1.0.3)
- turbo-sprockets-rails3 (0.1.15)
- tzinfo (0.3.33)
- uglifier (1.3.0)
- unicorn (4.3.1)
- vanity (1.8.0 dda319f)
- warden (1.2.1)
- watchr (0.7)
- webrat (0.7.3)
- will_paginate (3.0.3)
- xml-object (0.9.93)
- xpath (0.1.4)
$ brew info qt
qt: stable 4.8.3 (bottled), HEAD
http://qt.nokia.com/
/usr/local/Cellar/qt/4.8.2 (2753 files, 195M)
/usr/local/Cellar/qt/4.8.3 (2779 files, 194M) *
https://github.com/mxcl/homebrew/commits/master/Library/Formula/qt.rb
==> Options
--developer
Compile and link Qt with developer options
--with-qt3support
Enable deprecated Qt3Support module
--with-debug-and-release
Compile Qt in debug and release mode
--with-qtdbus
Enable QtDBus module
--universal
Build a universal binary
--with-mysql
Enable MySQL plugin
--with-demos-examples
Enable Qt demos and examples
==> Caveats
We agreed to the Qt opensource license for you.
If this is unacceptable you should uninstall.
BTW. I just tried uninstalling and installing Qt and installling with version 4.8.2 and I had the same issue.
Please check out the latest master and see if it resolves your issues. We just pushed a number of fixes for Qt 4.8.
Sorry, unfortunately it doesn't work :(
It gets stuck on this line in my Cucumber steps now, which is different admittedly:
@javascript Scenario: Duplicate a backlog # features/backlog.feature:33 When I follow "Create a new backlog" # features/step_definitions/web_steps.rb:27 And I fill in "Name the backlog" with "Project X" # features/step_definitions/web_steps.rb:33 And I press "Create new backlog" # features/step_definitions/web_steps_extra.rb:1
Looks like a co worker and myself are getting the same issue.
@mattheworiordan can you paste a log from the webkit_debug driver using master? The debugging output is much better for this kind of thing now.
Ok, will do.
On 9 Nov 2012, at 18:10, Joe Ferris [email protected] wrote:
@mattheworiordan can you paste a log from the webkit_debug driver using master? The debugging output is much better for this kind of thing now.
— Reply to this email directly or view it on GitHub.
Where is this log? just the rails test.log?
@jferris, here is the log when running cucumber
http://speedy.sh/M3zSK/cucumber.log
@mattheworiordan do you know what's going on in your code when that happens? It seems like maybe it's starting some requests and then canceling them somehow, and capybara-webkit doesn't realized that the request has been canceled.
Here are the 4 steps of my scenario, it seems the final one never fires, or perhaps it hangs on this step:
When I follow "Create a new backlog"
And I fill in "Name the backlog" with "Project X"
And I press "Create new backlog"
Then I should see the notice "Backlog was successfully created."
And I press "Create new backlog" simply executes the following code:
When /^(?:|I )press "([^"]*)"(?: within (?:|the )"([^"]*)")?$/ do |button, selector|
selector_css = selector_to(selector)
sleep 0.2 if selector_css.present? && !page.has_css?(selector_css) # https://github.com/thoughtbot/capybara-webkit/issues/36
with_scope(selector_css) do
click_button(selector_to(button, :dont_translate_to_css=>true))
end
end
Then I should see the notice "Backlog was successfully created." executes the following code:
Then /^(?:|I )should (|not )see the (notice) "([^"]+)"$/ do |negation, notice_alert, message|
selector = "#alert-space .#{notice_alert}"
unless negation.strip == "not" && page.has_no_selector?(selector) # if notice not shown at all allow this to pass if in the negative
within(selector) do |content|
if negation.strip == "not"
page.should_not have_content(message)
else
page.should have_content(message)
end
end
end
end
To be honest, I can't see anything particularly unusual in any of this?
Not sure what else I can provide. I appreciate you looking into this, it's a really odd problem.
Can you use $stdout.puts statements to track down exactly which line it's halting on? I don't see anything odd in there, either, but it would be good to know exactly where it's stopping. If you can paste some of the production code that the problematic step is exercising, that would also be useful. Are iframes or windows involved?
Ok, I added the debug messages and was able to isolate it down to a single line that hangs.
Here is the complete log http://www.speedyshare.com/5UKwq/cucumber.log
In my logs, after using $stdout.puts I get the following debug information:
notice check notice Backlog was successfully created.
notice check notice_alert notice
notice check selector #alert-space .notice
notice check passed selector check
After that it goes into webkit_debug output and does not seem to ever return back to my Cucumber steps.
The code matching the above notices is as follows:
Then /^(?:|I )should (|not )see the (notice|alert|error|warning) "([^"]+)"$/ do |negation, notice_alert, message|
$stdout.puts "notice check #{negation} #{notice_alert} #{message}"
notice_alert = 'error' if notice_alert == 'alert' # errors and alerts are stored in the same .error class
$stdout.puts "notice check notice_alert #{notice_alert}"
selector = "#alert-space .#{notice_alert}"
$stdout.puts "notice check selector #{selector}"
unless negation.strip == "not" && page.has_no_selector?(selector) # if notice not shown at all allow this to pass if in the negative
$stdout.puts "notice check passed selector check"
within(selector) do |content|
$stdout.puts "notice check within #{selector}"
if negation.strip == "not"
page.should_not have_content(message)
else
page.should have_content(message)
end
$stdout.puts "notice check finished"
end
end
end
So it looks like it's hanging on the line with the value:
within('#alert-space .notice') do |content|
I then thought it might be useful to take a screen shot beforehand as it may help with debugging, and that is when things became odd. I added a new line to the Cucumber steps Then screenshot the page which simply executes screenshot_and_save_page. However, when I ran cucumber the second time round hoping to get a screenshot, I did not see the debug messages notice check*, meaning it hung before it even got to that so probably on the screen shot line. Does this some how mean that Capybara-Webkit is sort of getting stuck on whatever requests comes after the previous Create a new backlog action.
I just don't know where to go from here. Happy to do whatever debugging you want though.
BTW. I wondered if capybara-screenshot was interfering, so I reran the tests without that Gem installed and the same thing happened. I also added a debug line above page.save_page and that gets run, but as soon as page.save_page executes it seems capybara-webkit starts downloading the page..
Received "Body"
"TimeoutCommand" waiting for load to finish
Started request to "http://127.0.0.1:62222/accounts/1/backlogs/2"
Received 302 from "http://127.0.0.1:62222/accounts/1/backlogs"
1 requests remaining
....
4 requests remaining
Page finished with true
And just hangs there.
@jferris, oddly I have never actually waited more than around a few minutes once Capybara-Webkit hangs, and always killed the process. This time however I left it running by mistake and when I came back it was running more tests.
Here is the log http://speedy.sh/QGH55/cucumber.log
Look at line 17441 and you will see we get an error: No response received from the server. (Capybara::Webkit::NoResponseError)
Also, if you look at line 17482 you will see that every test afterwards now fails with:
Broken pipe (Errno::EPIPE)
Maybe that will help diagnose the issue?
That pair of errors means that the server crashed after a while. Can you try sending it this command in a before block?
page.driver.browser.timeout = 10
Ok, so far so good, I have been able to run the tests and it's not hung. I will however need to wait for the tests to finish running before I can figure out exactly what's happening, and unfortunately the suite is pretty large (at least 30 minutes). I'll review once done and post the results.
On 9 Nov 2012, at 20:31, Joe Ferris [email protected] wrote:
That pair of errors means that the server crashed after a while. Can you try sending it this command in a before block?
page.driver.browser.timeout = 10 — Reply to this email directly or view it on GitHub.
Ok, so the tests complete, but I have loads of failing tests because 10s is not quite enough for some of the more in-depth steps. I am not really sure if this is fixing the issue, or just working around the hanging server issue though. I will re-run with a more generous 20s allowance and see if the original test fails or not
Ok, unfortunately even with 20s delay, it runs into problems.
I keep getting errors such as:
Received "Reset"
Started "Reset"
Finished "Reset" with response "Success()"
Wrote response true ""
Connection refused - connect(2) (Errno::ECONNREFUSED)
/Users/matt/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/http.rb:762:in `initialize'
/Users/matt/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/http.rb:762:in `open'
/Users/matt/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/http.rb:762:in `block in connect'
/Users/matt/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
/Users/matt/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
/Users/matt/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/http.rb:762:in `connect'
/Users/matt/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
/Users/matt/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/http.rb:744:in `start'
/Users/matt/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/net/http.rb:1284:in `request'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/http/default.rb:83:in `response_for'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/http/default.rb:39:in `request'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/bridge.rb:598:in `raw_execute'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/bridge.rb:576:in `execute'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/bridge.rb:350:in `deleteAllCookies'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/common/options.rb:67:in `delete_all_cookies'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/capybara-1.1.3/lib/capybara/selenium/driver.rb:81:in `reset!'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/capybara-1.1.3/lib/capybara/session.rb:70:in `reset!'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/capybara-1.1.3/lib/capybara/dsl.rb:87:in `block in reset_sessions!'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/capybara-1.1.3/lib/capybara/dsl.rb:87:in `each'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/capybara-1.1.3/lib/capybara/dsl.rb:87:in `reset_sessions!'
/Users/matt/.rvm/gems/ruby-1.9.3-p286/gems/capybara-1.1.3/lib/capybara/cucumber.rb:10:in `After'
That backtrace has selenium-webdriver in it and not capybara-webkit. Are you using selenium for some scenarios?
Yes, it's a mix, but I get the same problem when I run only stories tagged with capybara webkit. I can send you a log of that if that helps?
Sent from my iPhone
On 9 Nov 2012, at 23:41, Joe Ferris [email protected] wrote:
That backtrace has selenium-webdriver in it and not capybara-webkit. Are you using selenium for some scenarios?
— Reply to this email directly or view it on GitHubhttps://github.com/thoughtbot/capybara-webkit/issues/399#issuecomment-10247264.