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:



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

attr_writer :timer

Class Method Details

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

Waits until the block evaluates to true or times out.

Examples:

Watir::Wait.until { browser.a(:id => "ajaxed").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:



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

def until(timeout = nil, message = nil, &block)
  timeout ||= Watir.default_timeout

  timer.wait(timeout) do
    result = yield(self)
    return result if result
    sleep INTERVAL
  end

  raise TimeoutError, message_for(timeout, message)
end

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

Wait while the block evaluates to true or times out.

Examples:

Watir::Wait.while { browser.a(:id => "ajaxed").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:



62
63
64
65
66
67
68
69
70
71
# File 'lib/watir-webdriver/wait.rb', line 62

def while(timeout = nil, message = nil, &block)
  timeout ||= Watir.default_timeout

  timer.wait(timeout) do
    return unless yield(self)
    sleep INTERVAL
  end

  raise TimeoutError, message_for(timeout, message)
end