Module: OnlyofficeWebdriverWrapper::WaitUntilMethods

Included in:
WebDriver
Defined in:
lib/onlyoffice_webdriver_wrapper/webdriver/wait_until_methods.rb

Overview

Method to different wait_until methods

Constant Summary collapse

TIMEOUT_WAIT_ELEMENT =

Returns default timeout for wait element.

Returns:

  • (Integer)

    default timeout for wait element

15

Instance Method Summary collapse

Instance Method Details

#wait_until(timeout = ::PageObject.default_page_wait, message = nil, wait_js: true, &block) ⇒ void

This method returns an undefined value.

Wait until something happens

Parameters:

  • timeout (Integer) (defaults to: ::PageObject.default_page_wait)

    How much to wait

  • message (String) (defaults to: nil)

    which message show if something happens

  • wait_js (Boolean) (defaults to: true)

    should we wait for JavaScript actions



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/wait_until_methods.rb', line 14

def wait_until(timeout = ::PageObject.default_page_wait, message = nil, wait_js: true, &block)
  tries ||= 3
  wait = Object::Selenium::WebDriver::Wait.new(timeout: timeout, message: message)
  wait.until(&block)
  if wait_js
    wait.until { document_ready? }
    wait.until { jquery_finished? }
  end
rescue Selenium::WebDriver::Error::TimeoutError => e
  webdriver_error("Wait until timeout: #{timeout} seconds for `#{e}` failed")
rescue Selenium::WebDriver::Error::UnexpectedAlertOpenError => e
  webdriver_error(e.class, "JS Alert Happened: #{e}")
rescue Selenium::WebDriver::Error::StaleElementReferenceError
  OnlyofficeLoggerHelper.log("Wait until: rescuing from Stale Element error, #{tries} attempts remaining")
  retry unless (tries -= 1).zero?
  webdriver_error('Wait until: rescuing from Stale Element error failed after 3 tries')
end

#wait_until_element_disappear(xpath_name, timeout: TIMEOUT_WAIT_ELEMENT) ⇒ Void

Wait until some element disappear If timeout exceeded - raise an error

Parameters:

  • xpath_name (String)

    xpath of element

  • timeout (Integer) (defaults to: TIMEOUT_WAIT_ELEMENT)

    timeout to wait

Returns:

  • (Void)


71
72
73
74
75
76
77
78
79
80
81
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/wait_until_methods.rb', line 71

def wait_until_element_disappear(xpath_name, timeout: TIMEOUT_WAIT_ELEMENT)
  wait = Selenium::WebDriver::Wait.new(timeout: timeout) # seconds
  begin
    wait.until { get_element(xpath_name) ? false : true }
  rescue Selenium::WebDriver::Error::TimeoutError => e
    timeout_message = "wait_until_element_present(#{xpath_name}) " \
                      'Selenium::WebDriver::Error::TimeoutError: ' \
                      "timed out after #{timeout} seconds"
    webdriver_error(e.class, timeout_message)
  end
end

#wait_until_element_present(xpath_name, timeout: TIMEOUT_WAIT_ELEMENT) ⇒ Void

Wait until some element present If timeout exceeded - raise an error

Parameters:

  • xpath_name (String)

    xpath of element

  • timeout (Integer) (defaults to: TIMEOUT_WAIT_ELEMENT)

    timeout to wait

Returns:

  • (Void)


54
55
56
57
58
59
60
61
62
63
64
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/wait_until_methods.rb', line 54

def wait_until_element_present(xpath_name, timeout: TIMEOUT_WAIT_ELEMENT)
  wait = Selenium::WebDriver::Wait.new(timeout: timeout) # seconds
  begin
    wait.until { get_element(xpath_name) }
  rescue Selenium::WebDriver::Error::TimeoutError => e
    timeout_message = "wait_until_element_present(#{xpath_name}) " \
                      'Selenium::WebDriver::Error::TimeoutError: ' \
                      "timed out after #{timeout} seconds"
    webdriver_error(e.class, timeout_message)
  end
end

#wait_until_element_visible(xpath_name, timeout = 15) ⇒ Boolean

Wait until element is visible

Parameters:

  • xpath_name (String)

    to find object

  • timeout (Integer) (defaults to: 15)

    How much to wait

Returns:

  • (Boolean)

    true if element is visible after some timeout

Raises:

  • (StandardError)

    error if element not found for timeout



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/wait_until_methods.rb', line 37

def wait_until_element_visible(xpath_name, timeout = 15)
  wait_until_element_present(xpath_name)
  time = 0
  while !element_visible?(xpath_name) && time < timeout
    sleep(1)
    time += 1
  end
  return true unless time >= timeout

  webdriver_error("Element `#{xpath_name}` not visible for #{timeout} seconds")
end