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
-
#default_timeout ⇒ Object
The default Selenium Core client side timeout.
Instance Method Summary collapse
- #default_wait_for_time ⇒ Object
- #flunk(message) ⇒ Object
- #time_class ⇒ Object
-
#wait_for(params = {}) ⇒ Object
Poll continuously for the return value of the block to be true.
Instance Attribute Details
#default_timeout ⇒ Object
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_time ⇒ Object
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() raise Polonium::PoloniumError, end |
#time_class ⇒ Object
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 = params[:message] || "Timeout exceeded" configuration = Context.new() 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. + " (after #{timeout} sec)") true end |