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.
15
Instance Method Summary collapse
-
#wait_until(timeout = ::PageObject.default_page_wait, message = nil, wait_js: true, &block) ⇒ void
Wait until something happens.
-
#wait_until_element_disappear(xpath_name, timeout: TIMEOUT_WAIT_ELEMENT) ⇒ Void
Wait until some element disappear If timeout exceeded - raise an error.
-
#wait_until_element_present(xpath_name, timeout: TIMEOUT_WAIT_ELEMENT) ⇒ Void
Wait until some element present If timeout exceeded - raise an error.
-
#wait_until_element_visible(xpath_name, timeout = 15) ⇒ Boolean
Wait until element is visible.
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
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, = nil, wait_js: true, &block) tries ||= 3 wait = Object::Selenium::WebDriver::Wait.new(timeout: timeout, 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
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 = "wait_until_element_present(#{xpath_name}) " \ 'Selenium::WebDriver::Error::TimeoutError: ' \ "timed out after #{timeout} seconds" webdriver_error(e.class, ) end end |
#wait_until_element_present(xpath_name, timeout: TIMEOUT_WAIT_ELEMENT) ⇒ Void
Wait until some element present If timeout exceeded - raise an error
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 = "wait_until_element_present(#{xpath_name}) " \ 'Selenium::WebDriver::Error::TimeoutError: ' \ "timed out after #{timeout} seconds" webdriver_error(e.class, ) end end |
#wait_until_element_visible(xpath_name, timeout = 15) ⇒ Boolean
Wait until element is visible
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 |