lib/appium_lib/appium.rb in appium_lib-11.0.0 vs lib/appium_lib/appium.rb in appium_lib-11.1.0
- old
+ new
@@ -75,14 +75,13 @@
require 'tomlrb'
Appium::Logger.info "Loading #{toml}" if verbose
data = Tomlrb.load_file(toml, symbolize_keys: true)
- if verbose
- Appium::Logger.info data unless data.empty?
- end
+ Appium::Logger.info data if verbose && !data.empty?
+
if data && data[:caps] && data[:caps][:app] && !data[:caps][:app].empty?
data[:caps][:app] = Appium::Driver.absolute_app_path data
end
if data && data[:appium_lib] && data[:appium_lib][:require]
@@ -198,16 +197,21 @@
#
def promote_appium_methods(class_array, driver = $driver)
raise 'Driver is nil' if driver.nil?
# Wrap single class into an array
- class_array = [class_array] unless class_array.class == Array
+ class_array = [class_array] unless class_array.instance_of? Array
# Promote Appium driver methods to class instance methods.
class_array.each do |klass|
- driver.public_methods(false).each do |m|
+ driver.public_methods(false).each do |method|
klass.class_eval do
- define_method m do |*args, &block|
+ if method_defined? method
+ ::Appium::Logger.warn "'#{method}' is already defined. Skipping to override it."
+ next
+ end
+
+ define_method method do |*args, &block|
begin
# Prefer existing method.
# super will invoke method missing on driver
super(*args, &block)
@@ -215,14 +219,14 @@
# so rescue argument error
# and call the name method on $driver
rescue NoMethodError, ArgumentError
if args.size == 1 && args.first.is_a?(Hash)
# To prevent warnings by keyword arguments (for Ruby 2.7 and 3)
- driver.send m, **args.first, &block if driver.respond_to?(m)
+ driver.send method, **args.first, &block if driver.respond_to?(method)
else
::Appium::Logger.warn "Should fix this '#{args}' for Ruby 2.7 (and 3)" if args.first.is_a?(Hash)
- driver.send m, *args, &block if driver.respond_to?(m)
+ driver.send method, *args, &block if driver.respond_to?(method)
end
end
end
end
end