Skip to content

Commit afb0b09

Browse files
Add promote_singleton_appium_methods(main_module)
module App module Splash class << self def login 'login' end end end end module Kernel def splash App::Splash end end Appium.promote_singleton_appium_methods(App) This enables accessing $driver methods within the App::Splash page object. Fix #73 Raise on nil driver
1 parent 631c584 commit afb0b09

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/appium_lib/driver.rb

+19
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,25 @@ module Appium
151151
require 'android/element/generic'
152152
require 'android/element/textfield'
153153

154+
def self.promote_singleton_appium_methods main_module
155+
raise 'Driver is nil' if $driver.nil?
156+
main_module.constants.each do |sub_module|
157+
#noinspection RubyResolve
158+
$driver.public_methods(false).each do |m|
159+
const = Woven.const_get(sub_module)
160+
const.send(:define_singleton_method, m) do |*args, &block|
161+
begin
162+
super(*args, &block) # promote.rb
163+
rescue NoMethodError, ArgumentError
164+
$driver.send m, *args, &block if $driver.respond_to?(m)
165+
end
166+
# override unless there's an existing method with matching arity
167+
end unless const.respond_to?(m) &&
168+
const.method(m).arity == $driver.method(m).arity
169+
end
170+
end
171+
end
172+
154173
##
155174
# Promote appium methods to class instance methods
156175
#

0 commit comments

Comments
 (0)