Module: SparklingWatir::Wait

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

Overview

This module is in charge of handling all the waits

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 TapWatir timer implementation in use.

Returns:

  • (#wait)

See Also:



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

attr_writer :timer

Class Method Details

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

Waits until the block evaluates to true or times out.

TODO: Add examples

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:



38
39
40
41
42
43
44
45
# File 'lib/sparkling_watir/wait.rb', line 38

def until(timeout: nil, message: nil, interval: nil, object: nil)
  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(timeout: nil, message: nil, interval: nil, object: nil) ⇒ Object

Wait while the block evaluates to true or times out.

TODO: Add examples

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:



59
60
61
62
63
# File 'lib/sparkling_watir/wait.rb', line 59

def while(timeout: nil, message: nil, interval: nil, object: nil)
  timeout ||= Watir.default_timeout
  run_with_timer(timeout, interval) { return unless yield(object) }
  raise TimeoutError, message_for(timeout, object, message)
end