Created
August 30, 2016 19:42
-
-
Save fernyb/f29ef3eca52c35dd73deb233ce60f40a to your computer and use it in GitHub Desktop.
Capybara PhantomJS Poltergeist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'capybara' | |
require 'capybara/dsl' | |
require 'capybara/poltergeist' | |
Capybara.register_driver :poltergeist do |app| | |
options = { | |
:js_errors => false | |
} | |
Capybara::Poltergeist::Driver.new(app, options) | |
end | |
Capybara.default_driver = :poltergeist | |
Capybara.run_server = false | |
class Request | |
include Capybara::DSL | |
def visit_home | |
visit "http://google.com/" | |
end | |
def print_html | |
$stdout.puts "\n\n", evaluate_script(%Q{ document.body.innerHTML }), "\n\n" | |
end | |
def done! | |
$stdout.puts "Done!" | |
begin | |
page.driver.quit | |
rescue Exception => e | |
end | |
end | |
end | |
req = Request.new | |
req.visit_home | |
req.print_html | |
req.done! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment