Module: Thoran::Selenium::WebDriver::Driver::Attempt

Included in:
Selenium::WebDriver::Driver
Defined in:
lib/Thoran/Selenium/WebDriver/Driver/Attempt/attempt.rb

Instance Method Summary collapse

Instance Method Details

#attempt(max_attempts = 3, &block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/Thoran/Selenium/WebDriver/Driver/Attempt/attempt.rb', line 24

def attempt(max_attempts = 3, &block)
  attempts = 0
  loop do
    begin
      yield
      break
    rescue Timeout::Error, ::Selenium::WebDriver::Error::UnknownError, ::Selenium::WebDriver::Error::NoSuchElementError => e
      attempts += 1
      if attempts >= max_attempts
        @driver.quit
        puts "Giving up after #{max_attempts} attempts to #{__method__} because #{e}."
        exit
      end
    end
  end
end