Module: Watir::Wait

Defined in:
lib/watir-webdriver/wait.rb,
lib/watir-webdriver/wait/timer.rb

Defined Under Namespace

Classes: TimeoutError, Timer

Constant Summary collapse

INTERVAL =
0.1

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.timer#wait

Access Watir timer implementation in use.

Returns:

  • (#wait)

See Also:



21
# File 'lib/watir-webdriver/wait.rb', line 21

attr_writer :timer

Class Method Details

.until(timeout = nil, message = nil) ⇒ Object

Waits until the block evaluates to true or times out.

Examples:

Watir::Wait.until { browser.text_field(name: "new_user_first_name").visible? }

Parameters:

  • timeout (Fixnum) (defaults to: nil)

    How long to wait in seconds

  • message (String) (defaults to: nil)

    Message to raise if timeout is exceeded

Raises:



38
39
40
41
42
43
44
45
# File 'lib/watir-webdriver/wait.rb', line 38

def until(timeout = nil, message = nil)
  timeout ||= Watir.default_timeout
  run_with_timer(timeout) do
    result = yield(self)
    return result if result
  end
  raise TimeoutError, message_for(timeout, message)
end

.while(timeout = nil, message = nil) ⇒ Object

Wait while the block evaluates to true or times out.

Examples:

Watir::Wait.while { browser.text_field(name: "abrakadbra").present? }

Parameters:

  • timeout (Fixnum) (defaults to: nil)

    How long to wait in seconds

  • message (String) (defaults to: nil)

    Message to raise if timeout is exceeded

Raises:



58
59
60
61
62
# File 'lib/watir-webdriver/wait.rb', line 58

def while(timeout = nil, message = nil)
  timeout ||= Watir.default_timeout
  run_with_timer(timeout) { return unless yield(self) }
  raise TimeoutError, message_for(timeout, message)
end