class Sauce::Capybara::Driver

Constants

MAX_RETRIES
RETRY_ON

Public Instance Methods

base_reset!()
Alias for: reset!
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 84
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
      Sauce.logger.debug "Capybara creating new Selenium driver."
      @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 113
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 121
def finish!
  Sauce.logger.debug "Capybara integration called #finish!"
  @browser.quit if existing_browser?
  @browser = nil

  # Rethink how to do this.  RSpec still references the driver pool.
  Sauce.logger.debug "Capybara - Removing driver for #{Thread.current.object_id} from 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 17
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 147
def render(path)
  browser.save_screenshot path
end
reset!() click to toggle source
# File lib/sauce/capybara.rb, line 132
def reset!
  begin
    base_reset!

  rescue Selenium::WebDriver::Error::WebDriverError => e 
    session_finished = e.message.match "ERROR Job is not in progress"

    if @browser.config[:suppress_session_quit_failures] && session_finished
      @browser=nil
    else
      raise e
    end
  end   
end
Also aliased as: base_reset!
rspec_browser() click to toggle source

Returns the rspec created browser if it exists

# File lib/sauce/capybara.rb, line 101
def rspec_browser
  if browser = Sauce.driver_pool[Thread.current.object_id]
    Sauce.logger.debug "Capybara using browser from driver_pool (browser.session_id)."
    @using_rspec_browser = true
  else
    @using_rspec_browser = false
  end
  browser
end