lib/appium_lib/driver.rb in appium_lib-9.2.0 vs lib/appium_lib/driver.rb in appium_lib-9.3.0

- old
+ new

@@ -302,28 +302,57 @@ # @return [Driver] the driver attr_reader :driver # Return http client called in start_driver() # @return [Selenium::WebDriver::Remote::Http::Default] the http client attr_reader :http_client + # Return a time wait timeout + # Wait time for ::Appium::Common.wait or ::Appium::Common.wait_true. + # Provide Appium::Drive like { appium_lib: { wait_timeout: 20 } } + # @return [Integer] + attr_reader :appium_wait_timeout + # Return a time wait timeout + # Wait interval time for ::Appium::Common.wait or ::Appium::Common.wait_true. + # Provide Appium::Drive like { appium_lib: { wait_interval: 20 } } + # @return [Integer] + attr_reader :appium_wait_interval # Creates a new driver # - # ```ruby - # require 'rubygems' - # require 'appium_lib' + # @example # - # # platformName takes a string or a symbol. + # ```ruby + # require 'rubygems' + # require 'appium_lib' # - # # Start iOS driver - # opts = { caps: { platformName: :ios, app: '/path/to/MyiOS.app' } } - # Appium::Driver.new(opts).start_driver + # # platformName takes a string or a symbol. # - # # Start Android driver - # opts = { caps: { platformName: :android, app: '/path/to/my.apk' } } - # Appium::Driver.new(opts).start_driver - # ``` + # # Start iOS driver + # opts = { + # caps: { + # platformName: :ios, + # app: '/path/to/MyiOS.app' + # }, + # appium_lib: { + # wait_timeout: 30 + # } + # } + # Appium::Driver.new(opts).start_driver # + # # Start Android driver + # opts = { + # caps: { + # platformName: :android, + # app: '/path/to/my.apk' + # }, + # appium_lib: { + # wait_timeout: 30, + # wait_interval: 1 + # } + # } + # Appium::Driver.new(opts).start_driver + # ``` + # # @param opts [Object] A hash containing various options. # @return [Driver] def initialize(opts = {}) # quit last driver $driver.driver_quit if $driver @@ -342,10 +371,13 @@ @sauce_username = appium_lib_opts.fetch :sauce_username, ENV['SAUCE_USERNAME'] @sauce_username = nil if !@sauce_username || (@sauce_username.is_a?(String) && @sauce_username.empty?) @sauce_access_key = appium_lib_opts.fetch :sauce_access_key, ENV['SAUCE_ACCESS_KEY'] @sauce_access_key = nil if !@sauce_access_key || (@sauce_access_key.is_a?(String) && @sauce_access_key.empty?) @appium_port = appium_lib_opts.fetch :port, 4723 + # timeout and interval used in ::Appium::Comm.wait/wait_true + @appium_wait_timeout = appium_lib_opts.fetch :wait_timeout, 30 + @appium_wait_interval = appium_lib_opts.fetch :wait_interval, 0.5 # to pass it in Selenium.new. # `listener = opts.delete(:listener)` is called in Selenium::Driver.new @listener = appium_lib_opts.fetch :listener, nil @@ -406,11 +438,13 @@ sauce_username: @sauce_username, sauce_access_key: @sauce_access_key, port: @appium_port, device: @appium_device, debug: @appium_debug, - listener: @listener + listener: @listener, + wait_timeout: @appium_wait_timeout, + wait_interval: @appium_wait_interval } # Return duplicates so attributes are immutable attributes.each do |key, value| attributes[key] = value.duplicable? ? value.dup : value @@ -430,12 +464,12 @@ # Return true if the target Appium server is over REQUIRED_VERSION_XCUITEST. # If the Appium server is under REQUIRED_VERSION_XCUITEST, then error is raised. # @return [Boolean] def check_server_version_xcuitest - if automation_name_is_xcuitest? && (@appium_server_version['build']['version'] <= REQUIRED_VERSION_XCUITEST) - raise Appium::Error::NotSupportedAppiumServer, "XCUITest requires over Appium #{REQUIRED_VERSION_XCUITEST}" + if automation_name_is_xcuitest? && (@appium_server_version['build']['version'] < REQUIRED_VERSION_XCUITEST) + raise Appium::Error::NotSupportedAppiumServer, "XCUITest requires Appium version >= #{REQUIRED_VERSION_XCUITEST}" end true end # Returns the server's version info @@ -608,15 +642,15 @@ # # Example: # # exists { button('sign in') } ? puts('true') : puts('false') # - # @param pre_check [Integer] the amount in seconds to set the - # wait to before checking existance - # @param post_check [Integer] the amount in seconds to set the - # wait to after checking existance - # @param search_block [Block] the block to call + # @param [Integer] pre_check The amount in seconds to set the + # wait to before checking existence + # @param [Integer] post_check The amount in seconds to set the + # wait to after checking existence + # @yield The block to call # @return [Boolean] def exists(pre_check = 0, post_check = @default_wait) # do not uset set_wait here. # it will cause problems with other methods reading the default_wait of 0 # which then gets converted to a 1 second wait. @@ -635,37 +669,37 @@ exists end # The same as @driver.execute_script - # @param script [String] the script to execute - # @param args [*args] the args to pass to the script + # @param [String] script The script to execute + # @param [*args] args The args to pass to the script # @return [Object] def execute_script(script, *args) @driver.execute_script script, *args end # Calls @driver.find_elements # - # @param args [*args] the args to use + # @param [*args] args The args to use # @return [Array<Element>] Array is empty when no elements are found. def find_elements(*args) @driver.find_elements_with_appium(*args) end # Calls @driver.find_elements # - # @param args [*args] the args to use + # @param [*args] args The args to use # @return [Element] def find_element(*args) @driver.find_element_with_appium(*args) end # Calls @driver.set_location # # @note This method does not work on real devices. # - # @param [Hash] opts consisting of: + # @param [Hash] opts consisting of: # @option opts [Float] :latitude the latitude in degrees (required) # @option opts [Float] :longitude the longitude in degees (required) # @option opts [Float] :altitude the altitude, defaulting to 75 # @return [Selenium::WebDriver::Location] the location constructed by the selenium webdriver def set_location(opts = {})