Skip to content

Instantly share code, notes, and snippets.

@abotalov
Created August 19, 2013 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abotalov/6274999 to your computer and use it in GitHub Desktop.
Save abotalov/6274999 to your computer and use it in GitHub Desktop.
Method that allows to run a couple of Capybara methods in a block. See http://stackoverflow.com/q/18293303/841064
require 'capybara'
class Capybara::Selenium::Driver
def browser
unless @browser
@browser = Selenium::WebDriver.for(options[:browser], options.reject { |key,val| SPECIAL_OPTIONS.include?(key) })
end
@browser
end
end
def with_capybara(&block)
Capybara.app_host = 'http://www.stackoverflow.com'
session = Capybara::Session.new(:selenium)
block.call(session)
session.driver.browser.quit
end
with_capybara do |session|
session.visit("/")
session.find('#nav-askquestion')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment