Module: Watir::Wait

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

Defined Under Namespace

Classes: TimeoutError, Timer

Constant Summary collapse

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:


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

attr_writer :timer

Class Method Details

.until(depr_timeout = nil, depr_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) (defaults to: nil)

    How long to wait in seconds

  • message (String) (defaults to: nil)

    Message to raise if timeout is exceeded

  • object (Object, NilClass) (defaults to: nil)

    Object to evaluate block against

Raises:


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/watir/wait.rb', line 35

def until(depr_timeout = nil, depr_message = nil, timeout: nil, message: nil, interval: nil, object: nil)
  if depr_message || depr_timeout
    Watir.logger.deprecate 'Using arguments for Wait#until', 'keywords', ids: %i[until timeout_arguments]
    timeout = depr_timeout
    message = depr_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, object, message)
end

.while(depr_timeout = nil, depr_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) (defaults to: nil)

    How long to wait in seconds

  • message (String) (defaults to: nil)

    Message to raise if timeout is exceeded

  • object (Object, NilClass) (defaults to: nil)

    Object to evaluate block against

Raises:


61
62
63
64
65
66
67
68
69
70
# File 'lib/watir/wait.rb', line 61

def while(depr_timeout = nil, depr_message = nil, timeout: nil, message: nil, interval: nil, object: nil)
  if depr_message || depr_timeout
    Watir.logger.deprecate 'Using arguments for Wait#while', 'keywords', ids: %i[while timeout_arguments]
    timeout = depr_timeout
    message = depr_message
  end
  timeout ||= Watir.default_timeout
  run_with_timer(timeout, interval) { return unless yield(object) }
  raise TimeoutError, message_for(timeout, object, message)
end