Module: Watir::Wait

Defined in:
lib/watir/wait.rb,
lib/watir/wait/timer.rb

Defined Under Namespace

Classes: TimeoutError, Timer

Constant Summary

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:



20
# File 'lib/watir/wait.rb', line 20

attr_writer :timer

Class Method Details

.until(deprecated_timeout = nil, deprecated_message = nil, timeout: nil, message: nil, interval: nil, object: nil) ⇒ Object

Waits until the block evaluates to true or times out.

Examples:

Watir::Wait.until { browser.text_field(name: "new_user_first_name").visible? }

Parameters:

  • timeout (Integer)

    How long to wait in seconds

  • message (String)

    Message to raise if timeout is exceeded

  • object (Object, NilClass)

    Object to evaluate block against

Raises:



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

def until(deprecated_timeout = nil, deprecated_message = nil, timeout: nil, message: nil, interval: nil, object: nil)
  if deprecated_message || deprecated_timeout
    Watir.logger.deprecate "Using arguments for Wait#until", "keywords"
    timeout = deprecated_timeout
    message = deprecated_message
  end
  timeout ||= Watir.default_timeout
  run_with_timer(timeout, interval) do
    result = yield(object)
    return result if result
  end
  raise TimeoutError, message_for(timeout, message)
end

.while(deprecated_timeout = nil, deprecated_message = nil, timeout: nil, message: nil, interval: nil, object: nil) ⇒ Object

Wait while the block evaluates to true or times out.

Examples:

Watir::Wait.while { browser.text_field(name: "abrakadbra").present? }

Parameters:

  • timeout (Integer)

    How long to wait in seconds

  • message (String)

    Message to raise if timeout is exceeded

  • object (Object, NilClass)

    Object to evaluate block against

Raises:



64
65
66
67
68
69
70
71
72
73
# File 'lib/watir/wait.rb', line 64

def while(deprecated_timeout = nil, deprecated_message = nil, timeout: nil, message: nil, interval: nil, object: nil)
  if deprecated_message || deprecated_timeout
    Watir.logger.deprecate "Using arguments for Wait#while", "keywords"
    timeout = deprecated_timeout
    message = deprecated_message
  end
  timeout ||= Watir.default_timeout
  run_with_timer(timeout, interval) { return unless yield(object) }
  raise TimeoutError, message_for(timeout, message)
end