Module: Watir::Wait

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

Defined Under Namespace

Classes: TimeoutError

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:



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

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 0.5
  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:



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

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

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

  raise TimeoutError, message_for(timeout, message)
end