Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly debug with Capybara/Poltergeist?

I am playing around with capybara/poltergeist perfect duo, but I am having trouble to properly debugging. I was testing a simple script:

logger = Logger.new "./log/who-scored-com.log"
Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, js_errors: false,
                                         debug: true,
                                         logger: logger)
end
browser = Capybara.current_session
browser.visit 'https://www.whoscored.com/LiveScores'
browser.save_page 'page.html'

I am expecting that the script grap the page normally and saves it, but the page is empty and this is returned:

`Capybara::Poltergeist::StatusFailError: Capybara::Poltergeist::StatusFailError
    from /home/vagrant/local/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/poltergeist-1.9.0/lib/capybara/poltergeist/browser.rb:351:in `command'
    from /home/vagrant/local/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/poltergeist-1.9.0/lib/capybara/poltergeist/browser.rb:34:in `visit'`

Now, this don't give me nothing about this error. I catch the exception and print it and it gives me:

"Request to 'https://www.whoscored.com/LiveScores' failed to reach server, check DNS and/or server status"

Even if I have no idea why the address do not respond for capybara (and any hint would be appreciate :) ) I don't understand why the :debug options used in configuration doesn't seem to give me no info

like image 367
ciaoben Avatar asked Dec 07 '22 23:12

ciaoben


1 Answers

You have a couple of issues

  1. the poltergeist logger option is defined as '(Object responding to puts) - The ruby 2.3.0 standard library Logger object doesnt respond to puts so it's not valid.

  2. You're example doesn't have Capybara.current_driver = :poltergeist so I'm not sure if it is actually using the driver you're configuring there or a previously defined one (I would have expected an error on the Logger object if it was)

  3. debug: true will add debugging for poltergeist to the log, but there is also debugging info from phantomjs. That is generated by passing phantomjs_options: ['--debug=true'], phantomjs_logger: <an IO object - again not a Logger object> to the driver

  4. The error you're actually hitting is the connection being refused due to not being able to negotiate an ssl protocol - to fix it add the required ssl protocol as a phantomjs option - `phantomjs_options: ['--ssl-protocol=TLSv1.2']

like image 135
Thomas Walpole Avatar answered Dec 23 '22 08:12

Thomas Walpole