lib/appium_lib/driver.rb in appium_lib-3.0.3 vs lib/appium_lib/driver.rb in appium_lib-4.0.0
- old
+ new
@@ -22,11 +22,10 @@
require_relative 'ios/element/textfield'
require_relative 'ios/element/text'
require_relative 'ios/mobile_methods'
# android
-require_relative 'android/dynamic'
require_relative 'android/helper'
require_relative 'android/patch'
require_relative 'android/element/alert'
require_relative 'android/element/button'
require_relative 'android/element/generic'
@@ -208,11 +207,21 @@
# attr readers are promoted to global scope. To avoid clobbering, they're
# made available via the driver_attributes method
# The amount to sleep in seconds before every webdriver http call.
- attr_accessor :global_webdriver_http_sleep
+ attr_accessor :global_webdriver_http_sleep,
+ :caps,
+ :custom_url,
+ :export_session,
+ :default_wait,
+ :last_waits,
+ :sauce_username,
+ :sauce_access_key,
+ :appium_port,
+ :appium_device,
+ :appium_debug
# Creates a new driver
#
# ```ruby
# require 'rubygems'
@@ -249,26 +258,27 @@
@last_waits = [@default_wait]
@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?)
- @port = appium_lib_opts.fetch :port, 4723
+ @appium_port = appium_lib_opts.fetch :port, 4723
# Path to the .apk, .app or .app.zip.
# The path can be local or remote for Sauce.
unless !@caps || @caps[:app].nil? || @caps[:app].empty?
@caps[:app] = self.class.absolute_app_path @caps[:app]
end
# https://code.google.com/p/selenium/source/browse/spec-draft.md?repo=mobile
- @device = @caps[:platformName]
- @device = @device.is_a?(Symbol) ? @device : @device.downcase.strip.intern if @device
- raise "platformName must be set. Not found in options: #{opts}" unless @device
- raise 'platformName must be Android or iOS' unless [:android, :ios].include?(@device)
+ @appium_device = @caps[:platformName]
+ @appium_device = @appium_device.is_a?(Symbol) ? @appium_device : @appium_device.downcase.strip.intern if @appium_device
+ raise "platformName must be set. Not found in options: #{opts}" unless @appium_device
+ raise 'platformName must be Android or iOS' unless [:android, :ios].include?(@appium_device)
# load common methods
extend Appium::Common
+ extend Appium::Device
if device_is_android?
# load Android specific methods
extend Appium::Android
else
# load iOS specific methods
@@ -278,16 +288,16 @@
# apply os specific patches
patch_webdriver_element
# enable debug patch
# !!'constant' == true
- @debug = appium_lib_opts.fetch :debug, !!defined?(Pry)
+ @appium_debug = appium_lib_opts.fetch :debug, !!defined?(Pry)
- if @debug
+ if @appium_debug
ap opts unless opts.empty?
- puts "Debug is: #{@debug}"
- puts "Device is: #{@device}"
+ puts "Debug is: #{@appium_debug}"
+ puts "Device is: #{@appium_device}"
patch_webdriver_bridge
end
# Save global reference to last created Appium driver for top level methods.
@@ -295,13 +305,10 @@
# Promote exactly once the first time the driver is created.
# Subsequent drivers do not trigger promotion.
unless @@loaded
@@loaded = true
- # load device methods exactly once
- extend Appium::Device
-
# Promote only on Minitest::Spec (minitest 5) by default
Appium.promote_appium_methods ::Minitest::Spec
end
self # return newly created driver
@@ -314,24 +321,24 @@
export_session: @export_session,
default_wait: @default_wait,
last_waits: @last_waits,
sauce_username: @sauce_username,
sauce_access_key: @sauce_access_key,
- port: @port,
- device: @device,
- debug: @debug,
+ port: @appium_port,
+ device: @appium_device,
+ debug: @appium_debug,
}
# Return duplicates so attributes are immutable
attributes.each do |key, value|
attributes[key] = value.duplicable? ? value.dup : value
end
attributes
end
def device_is_android?
- @device == :android
+ @appium_device == :android
end
# Returns the server's version info
#
# ```ruby
@@ -350,10 +357,13 @@
# Converts app_path to an absolute path.
# @return [String] APP_PATH as an absolute path
def self.absolute_app_path app_path
raise 'APP_PATH not set!' if app_path.nil? || app_path.empty?
+ # may be absolute path to file on remote server.
+ # if the file is on the remote server then we can't check if it exists
+ return app_path if @custom_url
# 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.match(/^http/) # public URL for Sauce
if app_path.match(/^(\/|[a-zA-Z]:)/) # absolute file path
app_path = File.expand_path app_path unless File.exist? app_path
@@ -377,10 +387,10 @@
def server_url
return @custom_url if @custom_url
if !@sauce_username.nil? && !@sauce_access_key.nil?
"http://#{@sauce_username}:#{@sauce_access_key}@ondemand.saucelabs.com:80/wd/hub"
else
- "http://127.0.0.1:#{@port}/wd/hub"
+ "http://127.0.0.1:#{@appium_port}/wd/hub"
end
end
# Restarts the driver
# @return [Driver] the driver