lib/appium_lib/driver.rb in appium_lib-15.2.0 vs lib/appium_lib/driver.rb in appium_lib-15.2.1
- old
+ new
@@ -38,10 +38,30 @@
require 'appium_lib_core'
require 'uri'
module Appium
class Driver
+ # @private
+ class << self
+ def convert_to_symbol(value)
+ if value.nil?
+ value
+ else
+ value.to_sym
+ end
+ end
+
+ # @private
+ def get_cap(caps, name)
+ name_with_prefix = "#{::Appium::Core::Base::Bridge::APPIUM_PREFIX}#{name}"
+ caps[convert_to_symbol name] ||
+ caps[name] ||
+ caps[convert_to_symbol name_with_prefix] ||
+ caps[name_with_prefix]
+ end
+ end
+
# attr readers are promoted to global scope. To avoid clobbering, they're
# made available via the driver_attributes method
#
# attr_accessor is repeated for each one so YARD documents them properly.
@@ -246,19 +266,15 @@
# Deprecated. TODO: remove
def set_app_path(opts)
return unless @core.caps
# return the path exists on the local
- return if @core.caps['app'] && !@core.caps['app'].nil? && File.exist?(@core.caps['app'])
- return if @core.caps[:app] && !@core.caps[:app].nil? && File.exist?(@core.caps[:app])
+ app_path = Driver.get_cap(@core.caps, 'app')
+ return if !app_path.nil? && File.exist?(app_path)
# The app file is not exact path
- if !@core.caps['app'].nil?
- @core.caps['app'] = self.class.absolute_app_path opts
- elsif !@core.caps[:app].nil?
- @core.caps[:app] = self.class.absolute_app_path opts
- end
+ @core.caps['app'] = self.class.absolute_app_path opts
end
# @private
def set_sauce_related_values(appium_lib_opts)
@sauce = Appium::SauceLabs.new(appium_lib_opts)
@@ -384,13 +400,12 @@
#
# @return [String] APP_PATH as an absolute path
def self.absolute_app_path(opts)
raise ArgumentError, 'opts must be a hash' unless opts.is_a? Hash
- # FIXME: 'caps' and 'app' will be correct
- caps = opts[:caps] || opts['caps'] || {}
- app_path = caps[:app] || caps['app']
+ caps = opts[:caps] || opts['caps'] || {}
+ app_path = get_cap(caps, 'app')
raise ArgumentError, 'absolute_app_path invoked and app is not set!' if app_path.nil? || app_path.empty?
# Sauce storage API. http://saucelabs.com/docs/rest#storage
return app_path if app_path.start_with? 'sauce-storage:'
return app_path if app_path =~ URI::DEFAULT_PARSER.make_regexp # public URL for Sauce
@@ -519,12 +534,15 @@
#
# @option http_client_ops [Hash] :http_client Custom HTTP Client
# @option http_client_ops [Hash] :open_timeout Custom open timeout for http client.
# @option http_client_ops [Hash] :read_timeout Custom read timeout for http client.
# @return [Selenium::WebDriver] the new global driver
- def start_driver(http_client_ops =
- { http_client: ::Appium::Http::Default.new, open_timeout: 999_999, read_timeout: 999_999 })
+ def start_driver(http_client_ops = { http_client: nil, open_timeout: 999_999, read_timeout: 999_999 })
+ if http_client_ops[:http_client].nil?
+ http_client = ::Appium::Http::Default.new(open_timeout: http_client_ops[:open_timeout],
+ read_timeout: http_client_ops[:read_timeout])
+ end
# TODO: do not kill the previous session in the future version.
if $driver.nil?
driver_quit
else
@@ -533,10 +551,15 @@
# If automationName is set only in server side, then the following automation_name should be nil before
# starting driver.
automation_name = @core.automation_name
- @driver = @core.start_driver(server_url: server_url, http_client_ops: http_client_ops)
+ @driver = @core.start_driver(server_url: server_url,
+ http_client_ops: {
+ http_client: http_client,
+ open_timeout: 999_999,
+ read_timeout: 999_999
+ })
@http_client = @core.http_client
# if automation_name was nil before start_driver, then re-extend driver specific methods
# to be able to extend correctly.
extend_for(device: @core.device, automation_name: @core.automation_name) if automation_name.nil?