class Sauce::Capybara::Driver
Constants
- MAX_RETRIES
- RETRY_ON
Public Instance Methods
browser()
click to toggle source
Oh gods why didn’t I comment these when I wrote them? These are what I think I’m doing.
Returns the browser currently being used or fetches a new browser, either from the RSpec
integration or by creating one.
# File lib/sauce/capybara.rb, line 82 def browser # Return the existing browser if we have it unless existing_browser? # Try to get a driver from the driver pool @browser = rspec_browser unless @browser @browser = Sauce::Selenium2.new at_exit do finish! end end end @browser end
existing_browser?()
click to toggle source
If a browser has been created OR RSpec
has put one in the diriver pool and we’re using that browser, returns true.
# File lib/sauce/capybara.rb, line 109 def existing_browser? if @using_rspec_browser @browser == Sauce.driver_pool[Thread.current.object_id] else @browser end end
finish!()
click to toggle source
# File lib/sauce/capybara.rb, line 117 def finish! @browser.quit if existing_browser? @browser = nil # Rethink how to do this. RSpec still references the driver pool. Sauce.driver_pool[Thread.current.object_id] = nil @using_rspec_browser = nil end
handle_retry(method, *args, &block)
click to toggle source
# File lib/sauce/capybara.rb, line 16 def handle_retry(method, *args, &block) retries = 0 # Disable retries only when we really really want to, this will remain # an undocomented hack for the time being if ENV['SAUCE_DISABLE_RETRY'] retries = MAX_RETRIES end begin send("base_#{method}".to_sym, *args, &block) rescue *RETRY_ON => e if retries < MAX_RETRIES puts "Received an exception (#{e}), retrying" retries = retries + 1 retry else raise end end end
render(path)
click to toggle source
# File lib/sauce/capybara.rb, line 126 def render(path) browser.save_screenshot path end
rspec_browser()
click to toggle source
Returns the rspec created browser if it exists
# File lib/sauce/capybara.rb, line 98 def rspec_browser if browser = Sauce.driver_pool[Thread.current.object_id] @using_rspec_browser = true else @using_rspec_browser = false end browser end