Module: Watir::Waitable

Included in:
Alert, Browser, Element, ElementCollection, ShadowRoot, Window, WindowCollection
Defined in:
lib/watir/wait.rb

Overview

Wait

Instance Method Summary collapse

Instance Method Details

#wait_until(timeout: nil, message: nil, interval: nil, **opt, &blk) ⇒ Object

Waits until the condition is true.

Examples:

browser.wait_until(timeout: 2) do |browser|
  browser.windows.size == 1
end
browser.text_field(name: "new_user_first_name").wait_until(&:present?).click
browser.text_field(name: "new_user_first_name").wait_until(message: 'foo') { |field| field.present? }
browser.text_field(name: "new_user_first_name").wait_until(timeout: 60, &:present?)
browser.text_field(name: "new_user_first_name").wait_until(timeout: 60, name: 'new_user_first_name')

Parameters:

  • timeout (Integer) (defaults to: nil)

    seconds to wait before timing out

  • message (String) (defaults to: nil)

    error message for when times out



104
105
106
107
108
109
110
111
112
113
# File 'lib/watir/wait.rb', line 104

def wait_until(timeout: nil, message: nil, interval: nil, **opt, &blk)
  message ||= proc { |obj| "waiting for true condition on #{obj.inspect}" }

  # TODO: Consider throwing argument error for mixing block & options
  proc = create_proc(opt, &blk)

  Wait.until(timeout: timeout, message: message, interval: interval, object: self, &proc)

  self
end

#wait_while(timeout: nil, message: nil, interval: nil, **opt, &blk) ⇒ Object

TODO:

add element example

Waits while the condition is true.

Examples:

browser.wait_while(timeout: 2) do |browser|
  !browser.exists?
end
browser.wait_while(timeout: 2, title: 'No')

Parameters:

  • timeout (Integer) (defaults to: nil)

    seconds to wait before timing out

  • message (String) (defaults to: nil)

    error message for when times out



130
131
132
133
134
135
136
137
138
139
# File 'lib/watir/wait.rb', line 130

def wait_while(timeout: nil, message: nil, interval: nil, **opt, &blk)
  message ||= proc { |obj| "waiting for false condition on #{obj.inspect}" }

  # TODO: Consider throwing argument error for mixing block & options
  proc = create_proc(opt, &blk)

  Wait.while(timeout: timeout, message: message, interval: interval, object: self, &proc)

  self
end