Module: Watir::Wait

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

Overview

Module provided by optional require:

require "watir-webdriver/extensions/wait"

Defined Under Namespace

Classes: TimeoutError

Class Method Summary collapse

Class Method Details

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

Wait until the block evaluates to true or times out.

Raises:



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/watir-webdriver/extensions/wait.rb', line 20

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

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

  raise TimeoutError, "timed out after #{timeout} seconds"
end

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

Wait while the block evaluates to true or times out.

Raises:



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

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

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

  raise TimeoutError, "timed out after #{timeout} seconds"
end