Closed dlandberg closed 8 years ago
I eventually had to abandon Poltergeist because of this error. I was using it to load external urls in a rake task to test if page was loading properly. The task would run once a minute opening up a cloudfront cdn cached page. Sometimes I would get the timeout error, most of the time I wouldn't. So there were no testing frameworks in the way or asset compilation issues to tinker with.
@glennfu: Sounds like your script would be a nice small example of this issue. Are you able to post a gist?
Here's the trimmed down version:
require 'capybara'
require 'capybara/dsl'
require 'capybara/poltergeist'
Capybara.run_server = false
Capybara.app_host = "http://america.aljazeera.com"
session = Capybara::Session.new(:poltergeist, nil)
session.visit "/"
success = !!(session.body =~ /Al Jazeera America/)
The kicker is that this was run once a minute on a clock thread and might not fail for hours. When it would fail, none of the other monitoring setups would detect any issues, and manually checking the site showed it was still loading just fine.
I removed the poltergeist code in August 2014, so it's been a while and it doesn't look like I wrote down the specific errors I was seeing. I just remember that it wasn't a capturable exception, the app would simply die. That was the biggest problem since I couldn't just rescue and retry.
I hope this is helpful!
For me this started when we added rack-timeout to my project.
After trying everything in this thread I stumbled into: https://github.com/heroku/rack-timeout/issues/55
Leading me to this sample commit: https://github.com/craftsmen/roll/commit/04c3d869764708ec8ff495c924117f8c5a3f48d0
Leaving this here incase it helps anyone else getting this issue for the same reason (it could happen for other reasons as well).
@rschooley using rack-timeout in production/staging only solved my issue as well. Thanks!
I can also confirm that moving rack-timeout
gem outside of the test environment fixed the poltergeist/phantomjs timeout issue.
Or setting the timeout to 0 also worked:
Rack::Timeout.timeout = (Rails.env.test? ? 0 : 20)
:+1: Moving rack-timeout
out of the test group worked for me as well.
BTW, in config/initializers/timeout.rb
I simply check if Rack::Timeout
is defined before setting:
if defined?(Rack::Timeout)
Rack::Timeout.timeout = (ENV['RACK_TIMEOUT'] || 20).to_i
end
The error can be simulated with
Capybara.default_driver = :poltergeist Capybara.current_session.driver.headers = {'User-Agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0'}
@showaltb Ajax fix worked for us - thanks a lot - we have had months of problems with this one. Here is my slightly modified script if it's useful based on this fix and the similar one at https://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara
we call wait_for_ajax after in both AfterStep and the After hook.
def wait_for_ajax Timeout.timeout(Capybara.default_wait_time) do loop until finished_all_ajax_requests? end end
def finished_all_ajax_requests? begin page.evaluate_script("(typeof jQuery !== \"undefined\") ? jQuery.active : 0").zero? rescue Exception => e puts e end end
I was able to track this down an external js call taking a very long time and intermittently timing out. In my case the call was to an external service that does some rewriting of the page including some images. If I switch my driver to use webkit and include the option block_unknown_urls
my tests run normally.
Capybara.register_driver :webkit do |app|
Capybara::Webkit::Driver.new(app).tap do |driver|
driver.block_unknown_urls
end
end
Since I haven't been able to find a similar option for poltergeist I was able to resolve the issue by including --load-images=no
in the phantomjs options. Obviously this will break any tests that depend on loading images but in my case it's not a problem.
Capybara.register_driver :poltergeist do |app|
options = {
:window_size => [1280, 1440],
:port => 44678+ENV['TEST_ENV_NUMBER'].to_i,
:phantomjs_options => ['--proxy-type=none', '--load-images=no', '--ignore-ssl-errors=yes', '--ssl-protocol=any'],
:timeout => 120
}
Capybara::Poltergeist::Driver.new(app, options)
end
I was encountering Capybara::Poltergeist::TimeoutError
errors in my feature specs under the following circumstances
js: true
changing the cdn references to use Protocol-relative fixed the issue, i.e.:
<%= javascript_include_tag "//code.jquery.com/jquery-2.1.4.min.js" %>
this was running my specs on a vagrant box with ubuntu 14.04; phantomjs 1.9.0 and with poltergeist 1.5.1
I'm closing this since it doesn't actually appear to be a specific issue but a collection of 5 or 6 different things. From a quick perusal it appears using the blacklist support added in 1.6.0 and telling phantomjs to ignore ssl errors may have fixed some of them for people, but other than that it's a lot of crosstalk. If anyone is still having issues with current poltergeist please open a new issue with all relevant details and if possible a minimal test case.
@twalpole what is current phantomjs? 2.0.0 still not released.
@Vanuan Phantomjs 2.0.0 was released Jan 24, 2015 - so almost a year ago
@twalpole still, there are no official binaries for Linux
@Vanuan That really seems likes an issue to post over on the phantomjs project and not actually a poltergeist issue. You could also just compile it yourself for whatever platform you want to run it on.
@twalpole I would be pro locking this issue down, as I suspect it will still generate new comments, and a lot of pings if that's something you'd be okay with.
@Senjai Done
I've got an Capybara::Poltergeist::TimeoutError with a simple line of code:
The debug output:
I'm not sure that it's a poltergeist bug. Seems like the following code in the
web_socker_server.rb
raises the timeout exception:My environment: Mac OS Lion 10.7.5 phantomjs-1.9.1 poltergeist-1.3.0