Module: Watir::Wait

Extended by:
Wait
Included in:
Wait
Defined in:
lib/watir-classic/wait.rb

Defined Under Namespace

Classes: TimeoutError

Instance Method Summary collapse

Instance Method Details

#until(timeout = 60) {|instance| ... } ⇒ Object

Wait until the block evaluates to true or times out.

Examples:

Watir::Wait.until(5) { browser.text_field.exists? }

Parameters:

  • timeout (Fixnum) (defaults to: 60)

    timeout to wait until block returns true.

Yield Parameters:

  • instance (self)

    instance of self.

Raises:

See Also:



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

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

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

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

#while(timeout = 60) {|instance| ... } ⇒ Object

Wait while the block evaluates to true or times out.

Examples:

Watir::Wait.while(5) { browser.text_field.exists? }

Parameters:

  • timeout (Fixnum) (defaults to: 60)

    timeout to wait while block returns true.

Yield Parameters:

  • instance (self)

    instance of self.

Raises:

See Also:



42
43
44
45
46
47
48
49
50
51
# File 'lib/watir-classic/wait.rb', line 42

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

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

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