Module: QAT::Web::Elements::Waiters
- Included in:
- QAT::Web::Elements, Page
- Defined in:
- lib/qat/web/elements/waiters.rb
Overview
Helper methods for handling timeouts and wait periods
Instance Method Summary collapse
-
#timeouts ⇒ HashWithIndifferentAccess
Returns the timeouts configuration.
-
#timeouts_config(timeouts) ⇒ HashWithIndifferentAccess
Defines timeouts through a configuration hash.
-
#timeouts_file(path) ⇒ HashWithIndifferentAccess
Defines timeouts through a configuration file path.
-
#wait_until(timeout, klass = nil) { ... } ⇒ Object
Generic wait method.
-
#wait_until_not_present(selector, timeout) ⇒ Object
Waits a maximum timeout time until an element is no longer present on page.
-
#wait_until_not_visible(selector, timeout) ⇒ Object
Waits a maximum timeout time until an element is no longer visible on page.
-
#wait_until_present(selector, timeout) ⇒ Object
Waits a maximum timeout time until an element is present on page.
-
#wait_until_visible(selector, timeout) ⇒ Object
Waits a maximum timeout time until an element is visible on page.
Methods included from Config
Methods included from Selector
Methods included from Configuration
last_access, #last_access, last_access=, #parse_configuration
Instance Method Details
#timeouts ⇒ HashWithIndifferentAccess
Returns the timeouts configuration
40 41 42 |
# File 'lib/qat/web/elements/waiters.rb', line 40 def timeouts @timeouts end |
#timeouts_config(timeouts) ⇒ HashWithIndifferentAccess
Defines timeouts through a configuration hash
33 34 35 36 |
# File 'lib/qat/web/elements/waiters.rb', line 33 def timeouts_config(timeouts) valid_config?(timeouts, 'timeouts') @timeouts = HashWithIndifferentAccess.new(timeouts) end |
#timeouts_file(path) ⇒ HashWithIndifferentAccess
Defines timeouts through a configuration file path
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/qat/web/elements/waiters.rb', line 18 def timeouts_file(path) raise(ArgumentError, "File '#{path}' does not exist!") unless File.exist?(path) @timeouts_file = path begin config = YAML.load(File.read(@timeouts_file)) || {} rescue Psych::SyntaxError log.error "Failed to load file '#{@timeouts_file}'." raise end timeouts_config(config) end |
#wait_until(timeout, klass = nil) { ... } ⇒ Object
Generic wait method
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/qat/web/elements/waiters.rb', line 80 def wait_until(timeout, klass = nil, &block) default_time = Capybara.default_max_wait_time timeout ||= default_time tries = timeout / default_time exceptions = [Capybara::ElementNotFound, Capybara::ExpectationNotMet] exceptions << klass if klass Retriable.retriable(on: exceptions, tries: tries.ceil, base_interval: default_time) do yield end end |
#wait_until_not_present(selector, timeout) ⇒ Object
Waits a maximum timeout time until an element is no longer present on page
63 64 65 66 |
# File 'lib/qat/web/elements/waiters.rb', line 63 def wait_until_not_present(selector, timeout) type, value, = build_selector(selector, { wait: timeout }) has_no_selector?(type, value, **) end |
#wait_until_not_visible(selector, timeout) ⇒ Object
Waits a maximum timeout time until an element is no longer visible on page
71 72 73 74 |
# File 'lib/qat/web/elements/waiters.rb', line 71 def wait_until_not_visible(selector, timeout) type, value, = build_selector(selector, { visible: false, wait: timeout }) has_no_selector?(type, value, **) end |
#wait_until_present(selector, timeout) ⇒ Object
Waits a maximum timeout time until an element is present on page
47 48 49 50 |
# File 'lib/qat/web/elements/waiters.rb', line 47 def wait_until_present(selector, timeout) type, value, = build_selector(selector, { visible: false, wait: timeout }) has_selector?(type, value, **) end |
#wait_until_visible(selector, timeout) ⇒ Object
Waits a maximum timeout time until an element is visible on page
55 56 57 58 |
# File 'lib/qat/web/elements/waiters.rb', line 55 def wait_until_visible(selector, timeout) type, value, = build_selector(selector, { visible: true, wait: timeout }) has_selector?(type, value, **) end |