Class: Sauce::Capybara::Driver

Inherits:
Capybara::Selenium::Driver
  • Object
show all
Defined in:
lib/sauce/capybara.rb

Constant Summary collapse

RETRY_ON =
[::Selenium::WebDriver::Error::UnhandledError,
::Selenium::WebDriver::Error::UnknownError]
MAX_RETRIES =
3

Instance Method Summary collapse

Instance Method Details

#browserObject



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/sauce/capybara.rb', line 76

def browser
  unless existing_browser?
    @browser = rspec_browser
    unless @browser
      @browser = Sauce::Selenium2.new
      at_exit do
        finish!
      end
    end
  end
  @browser
end

#existing_browser?Boolean



98
99
100
101
102
103
104
# File 'lib/sauce/capybara.rb', line 98

def existing_browser?
  if @using_rspec_browser
    @browser == Sauce.driver_pool[Thread.current.object_id]
  else
    @browser
  end
end

#finish!Object



106
107
108
109
# File 'lib/sauce/capybara.rb', line 106

def finish!
  @browser.quit if existing_browser?
  @browser = nil
end

#handle_retry(method, *args, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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) ⇒ Object



111
112
113
# File 'lib/sauce/capybara.rb', line 111

def render(path)
  browser.save_screenshot path
end

#rspec_browserObject



89
90
91
92
93
94
95
96
# File 'lib/sauce/capybara.rb', line 89

def rspec_browser
  if browser = Sauce.driver_pool[Thread.current.object_id]
    @using_rspec_browser = true
  else
    @using_rspec_browser = false
  end
  browser
end