Class: Capybara::Lockstep::Client::Selenium

Inherits:
Capybara::Lockstep::Client show all
Defined in:
lib/capybara-lockstep/client/selenium.rb

Constant Summary

Constants inherited from Capybara::Lockstep::Client

ERROR_ALERT_OPEN, ERROR_NAVIGATED_AWAY, ERROR_PAGE_MISSING, ERROR_SNIPPET_MISSING, ERROR_WINDOW_CLOSED, SYNCHRONIZED_IVAR

Instance Method Summary collapse

Methods inherited from Capybara::Lockstep::Client

#synchronize, #synchronized=, #synchronized?

Methods included from PageAccess

#alert_present?, #page, #supported_driver?

Methods included from Logging

#log

Instance Method Details

#with_synchronization_error_handlingObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/capybara-lockstep/client/selenium.rb', line 5

def with_synchronization_error_handling
  yield
rescue ::Selenium::WebDriver::Error::ScriptTimeoutError
  timeout_message = "Could not synchronize client within #{timeout} seconds"
  log timeout_message
  if timeout_with == :error
    raise Timeout, timeout_message
  else
    # Don't raise an error, this may happen if the server is slow to respond.
    # We will retry on the next Capybara synchronize call.
  end
rescue ::Selenium::WebDriver::Error::UnexpectedAlertOpenError
  log ERROR_ALERT_OPEN
  # Don't raise an error, this will happen in an innocent test where a click opens an alert.
  # We will retry on the next Capybara synchronize call.
rescue ::Selenium::WebDriver::Error::NoSuchWindowError
  log ERROR_WINDOW_CLOSED
  # Don't raise an error, this will happen in an innocent test where a click closes a window.
  # We will retry on the next Capybara synchronize call.
rescue ::Selenium::WebDriver::Error::JavascriptError => e
  # When the URL changes while a script is running, my current selenium-webdriver
  # raises a Selenium::WebDriver::Error::JavascriptError with the message:
  # "javascript error: document unloaded while waiting for result".
  # We will retry on the next Capybara synchronize call, by then we should see
  # the new page.
  if e.message.include?('unload')
    log ERROR_NAVIGATED_AWAY
  else
    unhandled_synchronize_error(e)
  end
rescue StandardError => e
  unhandled_synchronize_error(e)
end