Skip to content

Commit 0104a87

Browse files
authored
add capability to be able to set default timeout/interval for wait/wait_true (#468)
* add capability to be able to set default timeout/interval for wait/wait_true * update docs
1 parent 1372e64 commit 0104a87

File tree

5 files changed

+60
-20
lines changed

5 files changed

+60
-20
lines changed

android_tests/lib/android/specs/driver.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def sauce?
5454
port: 4723,
5555
device: :android,
5656
debug: true,
57-
listener: nil }
57+
listener: nil,
58+
wait_timeout: 30, # default
59+
wait_interval: 0.5 } # default
5860

5961
if actual != expected
6062
diff = HashDiff.diff expected, actual

ios_tests/appium.txt

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ app = "./UICatalog.app"
99
sauce_username = ""
1010
sauce_access_key = ""
1111
wait = 30
12+
wait_timeout = 20
13+
wait_interval = 1

ios_tests/lib/ios/specs/driver.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def sauce?
5050
port: 4723,
5151
device: :ios,
5252
debug: true,
53-
listener: nil }
53+
listener: nil,
54+
wait_timeout: 20, # defined in appium.txt
55+
wait_interval: 1 } # defined in appium.txt
5456

5557
if actual != expected
5658
diff = HashDiff.diff expected, actual

lib/appium_lib/common/wait.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def _generic_wait(opts = {})
1313
# [:one, :two] => :one, :two
1414
raise "Invalid keys #{invalid_keys.to_s[1..-2]}. Valid keys are #{valid_keys.to_s[1..-2]}" unless invalid_keys.empty?
1515

16-
timeout = opts.fetch(:timeout, 30)
17-
interval = opts.fetch(:interval, 0.5)
16+
timeout = opts.fetch(:timeout, @appium_wait_timeout)
17+
interval = opts.fetch(:interval, @appium_wait_interval)
1818
message = opts[:message]
1919
ignored = Array(opts[:ignore] || ::Exception)
2020
return_if_true = opts[:return_if_true]
@@ -62,8 +62,8 @@ def _process_wait_opts(opts)
6262
# If only a number is provided then it's treated as the timeout value.
6363
#
6464
# @param [Hash] opts Options
65-
# @option opts [Numeric] :timeout (30) Seconds to wait before timing out.
66-
# @option opts [Numeric] :interval (0.5) Seconds to sleep between polls.
65+
# @option opts [Numeric] :timeout Seconds to wait before timing out. Set default by `appium_wait_timeout` (30).
66+
# @option opts [Numeric] :interval Seconds to sleep between polls. Set default by `appium_wait_interval` (0.5).
6767
# @option opts [String] :message Exception message if timed out.
6868
# @option opts [Array, Exception] :ignore Exceptions to ignore while polling (default: Exception)
6969
def wait_true(opts = {}, &block)
@@ -80,8 +80,8 @@ def wait_true(opts = {}, &block)
8080
# If only a number is provided then it's treated as the timeout value.
8181
#
8282
# @param [Hash] opts Options
83-
# @option opts [Numeric] :timeout (30) Seconds to wait before timing out.
84-
# @option opts [Numeric] :interval (0.5) Seconds to sleep between polls.
83+
# @option opts [Numeric] :timeout Seconds to wait before timing out. Set default by `appium_wait_timeout` (30).
84+
# @option opts [Numeric] :interval Seconds to sleep between polls. Set default by `appium_wait_interval` (0.5).
8585
# @option opts [String] :message Exception message if timed out.
8686
# @option opts [Array, Exception] :ignore Exceptions to ignore while polling (default: Exception)
8787
def wait(opts = {}, &block)

lib/appium_lib/driver.rb

+46-12
Original file line numberDiff line numberDiff line change
@@ -304,23 +304,52 @@ class Driver
304304
# Return http client called in start_driver()
305305
# @return [Selenium::WebDriver::Remote::Http::Default] the http client
306306
attr_reader :http_client
307+
# Return a time wait timeout
308+
# Wait time for ::Appium::Common.wait or ::Appium::Common.wait_true.
309+
# Provide Appium::Drive like { appium_lib: { wait_timeout: 20 } }
310+
# @return [Integer]
311+
attr_reader :appium_wait_timeout
312+
# Return a time wait timeout
313+
# Wait interval time for ::Appium::Common.wait or ::Appium::Common.wait_true.
314+
# Provide Appium::Drive like { appium_lib: { wait_interval: 20 } }
315+
# @return [Integer]
316+
attr_reader :appium_wait_interval
307317

308318
# Creates a new driver
309319
#
310-
# ```ruby
311-
# require 'rubygems'
312-
# require 'appium_lib'
320+
# @example
313321
#
314-
# # platformName takes a string or a symbol.
322+
# ```ruby
323+
# require 'rubygems'
324+
# require 'appium_lib'
315325
#
316-
# # Start iOS driver
317-
# opts = { caps: { platformName: :ios, app: '/path/to/MyiOS.app' } }
318-
# Appium::Driver.new(opts).start_driver
326+
# # platformName takes a string or a symbol.
319327
#
320-
# # Start Android driver
321-
# opts = { caps: { platformName: :android, app: '/path/to/my.apk' } }
322-
# Appium::Driver.new(opts).start_driver
323-
# ```
328+
# # Start iOS driver
329+
# opts = {
330+
# caps: {
331+
# platformName: :ios,
332+
# app: '/path/to/MyiOS.app'
333+
# },
334+
# appium_lib: {
335+
# wait_timeout: 30
336+
# }
337+
# }
338+
# Appium::Driver.new(opts).start_driver
339+
#
340+
# # Start Android driver
341+
# opts = {
342+
# caps: {
343+
# platformName: :android,
344+
# app: '/path/to/my.apk'
345+
# },
346+
# appium_lib: {
347+
# wait_timeout: 30,
348+
# wait_interval: 1
349+
# }
350+
# }
351+
# Appium::Driver.new(opts).start_driver
352+
# ```
324353
#
325354
# @param opts [Object] A hash containing various options.
326355
# @return [Driver]
@@ -344,6 +373,9 @@ def initialize(opts = {})
344373
@sauce_access_key = appium_lib_opts.fetch :sauce_access_key, ENV['SAUCE_ACCESS_KEY']
345374
@sauce_access_key = nil if !@sauce_access_key || (@sauce_access_key.is_a?(String) && @sauce_access_key.empty?)
346375
@appium_port = appium_lib_opts.fetch :port, 4723
376+
# timeout and interval used in ::Appium::Comm.wait/wait_true
377+
@appium_wait_timeout = appium_lib_opts.fetch :wait_timeout, 30
378+
@appium_wait_interval = appium_lib_opts.fetch :wait_interval, 0.5
347379

348380
# to pass it in Selenium.new.
349381
# `listener = opts.delete(:listener)` is called in Selenium::Driver.new
@@ -408,7 +440,9 @@ def driver_attributes
408440
port: @appium_port,
409441
device: @appium_device,
410442
debug: @appium_debug,
411-
listener: @listener
443+
listener: @listener,
444+
wait_timeout: @appium_wait_timeout,
445+
wait_interval: @appium_wait_interval
412446
}
413447

414448
# Return duplicates so attributes are immutable

0 commit comments

Comments
 (0)