@@ -18,7 +18,12 @@ module Appium::Common
1818 #
1919 # find_element :text doesn't work so use XPath to find by text.
2020
21- # Check every 0.5 seconds to see if block.call is true.
21+ # Check every 0.5 seconds to see if block.call doesn't raise an exception.
22+ # if .call raises an exception then it will be tried again.
23+ # if .call doesn't raise an exception then it will stop waiting.
24+ #
25+ # Example: wait { name('back').click }
26+ #
2227 # Give up after 30 seconds.
2328 # @param max_wait [Integer] the maximum time in seconds to wait for
2429 # @param interval [Float] the time in seconds to wait after calling the block
@@ -27,7 +32,29 @@ module Appium::Common
2732 def wait max_wait = 30 , interval = 0.5 , &block
2833 # Rescue Timeout::Error: execution expired
2934 result = nil
30- timeout ( max_wait ) { until ( result = begin ; block . call ; rescue ; end ) do ; sleep interval end }
35+ timeout max_wait do
36+ puts "Result is nil? #{ result . nil? } #{ result } "
37+ until ( result = begin ; block . call || true ; rescue ; end )
38+ sleep interval
39+ end
40+ end
41+ result
42+ end
43+
44+ # Check every 0.5 seconds to see if block.call returns true. nil is considered a failure.
45+ # Give up after 30 seconds.
46+ # @param max_wait [Integer] the maximum time in seconds to wait for
47+ # @param interval [Float] the time in seconds to wait after calling the block
48+ # @param block [Block] the block to call
49+ # @return [Object] the result of block.call
50+ def wait_true max_wait = 30 , interval = 0.5 , &block
51+ # Rescue Timeout::Error: execution expired
52+ result = nil
53+ timeout max_wait do
54+ until ( result = begin ; block . call ; rescue ; end )
55+ sleep interval
56+ end
57+ end
3158 result
3259 end
3360
0 commit comments