require 'capybara/poltergeist' require 'capybara/dsl' module CapybaraWithPhantomJs include Capybara::DSL # Create a new PhantomJS session in Capybara def new_session # Register PhantomJS (aka poltergeist) as the driver to use Capybara.register_driver :poltergeist do |app| Capybara::Poltergeist::Driver.new(app) end # Use XPath as the default selector for the find method #Capybara.default_selector = :xpath # Start up a new thread @session = Capybara::Session.new(:poltergeist) # Report using a particular user agent @session.driver.headers = { 'User-Agent' => "Janis Parser ;)" } # Return the driver's session @session end end