It appears I'm retracing the steps taken in the SO post: Capybara, Poltergeist and Phantomjs and giving an empty response in body. (Mark this as a duplicate if you want, but I'm including a minimal standalone test case and version numbers.)
Am I doing anything obviously wrong? Is there another minimal test I can run that might help isolate the problem?
file: pgtest.rbrequire 'rubygems'
require 'capybara'
require 'capybara/dsl'
require 'capybara/poltergeist'
module PGTest
include Capybara::DSL
extend self
def test
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app)
end
Capybara.current_driver = :poltergeist
session = Capybara::Session.new(:poltergeist)
visit "http://www.google.com"
sleep 5
puts session.html
end
end
PGTest.test
When invoked as follows, it prints an empty page:
$ ruby pgtest.rb
<html><head></head><body></body></html>
It's worth noting that I can use phantomjs extract the html from www.google.com:
file: pjs_dump.jsvar page = require('webpage').create();
page.open("http://www.google.com", function () {
var html = page.evaluate(function () {
return document.documentElement.outerHTML;
});
console.log(html);
phantom.exit();
});
When I run 'phantomjs pjs_dump.js', it prints the html from www.google.com, so phantomjs appears to be working properly.
This does the trick for me:
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
require 'capybara/poltergeist'
Capybara.run_server = false
Capybara.current_driver = :poltergeist
class PGTest
include Capybara::DSL
def test
visit "http://www.google.com"
puts page.body
end
end
PGTest.new.test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With