Module: Polonium::WaitFor

Included in:
Driver, Element, Page, SeleniumDsl
Defined in:
lib/polonium/wait_for.rb

Defined Under Namespace

Classes: Context

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_timeoutObject

The default Selenium Core client side timeout.



35
36
37
# File 'lib/polonium/wait_for.rb', line 35

def default_timeout
  @default_timeout ||= 20000
end

Instance Method Details

#default_wait_for_timeObject



26
27
28
# File 'lib/polonium/wait_for.rb', line 26

def default_wait_for_time
  5
end

#flunk(message) ⇒ Object



40
41
42
# File 'lib/polonium/wait_for.rb', line 40

def flunk(message)
  raise Polonium::PoloniumError, message
end

#time_classObject



30
31
32
# File 'lib/polonium/wait_for.rb', line 30

def time_class
  Time
end

#wait_for(params = {}) ⇒ Object

Poll continuously for the return value of the block to be true. You can use this to assert that a client side or server side condition was met.

wait_for do
  User.count == 5
end


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/polonium/wait_for.rb', line 9

def wait_for(params={})
  return super unless block_given?
  timeout = params[:timeout] || default_wait_for_time
  message = params[:message] || "Timeout exceeded"
  configuration = Context.new(message)
  begin_time = time_class.now
  while (time_class.now - begin_time) < timeout
    if value = yield(configuration)
      return value
    end
    return value if value
    sleep 0.25
  end
  flunk(configuration.message + " (after #{timeout} sec)")
  true
end