Module: Watir::Wait

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

Defined Under Namespace

Classes: TimeoutError

Constant Summary collapse

INTERVAL =
0.1

Class Method Summary collapse

Class Method Details

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

Wait until the block evaluates to true or times out.

Raises:



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/watir-webdriver/wait.rb', line 15

def until(timeout = 30, message = nil, &block)
  end_time = ::Time.now + timeout

  until ::Time.now > end_time
    result = yield(self)
    return result if result
    sleep INTERVAL
  end

  raise TimeoutError, message_for(timeout, message)
end

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

Wait while the block evaluates to true or times out.

Raises:



31
32
33
34
35
36
37
38
39
40
# File 'lib/watir-webdriver/wait.rb', line 31

def while(timeout = 30, message = nil, &block)
  end_time = ::Time.now + timeout

  until ::Time.now > end_time
    return unless yield(self)
    sleep INTERVAL
  end

  raise TimeoutError, message_for(timeout, message)
end