lib/appium_lib/driver.rb in appium_lib-0.3.0 vs lib/appium_lib/driver.rb in appium_lib-0.3.1
- old
+ new
@@ -30,10 +30,12 @@
require 'android/element/alert'
require 'android/element/generic'
require 'android/element/textfield'
class Driver
+ @@loaded = false
+
def initialize opts={}
opts = {} if opts.nil?
# Path to the .apk, .app or .app.zip.
# The path can be local or remote for Sauce.
@app_path = opts.fetch 'APP_PATH', ENV['APP_PATH']
@@ -69,15 +71,30 @@
raise 'APP_ACTIVITY must be set.' if @app_activity.nil?
# load Android specific methods
extend Appium::Android
else
+ @ios_js = [] # used to keep track of loaded JavaScript on iOS
# load iOS specific methods
extend Appium::Ios
end
# Save global reference to last created Appium driver for top level methods.
$last_driver = self
+
+ # Promote exactly once the first time the driver is created.
+ # Subsequent drivers do not trigger promotion.
+ unless @@loaded
+ @@loaded = true
+ # Promote Appium driver methods to Object instance methods.
+ $last_driver.public_methods(false).each do | m |
+ Object.class_eval do
+ define_method m do | *args, &block |
+ $last_driver.send m, *args, &block
+ end
+ end
+ end
+ end
end # def initialize
# WebDriver capabilities. Must be valid for Sauce to work.
# https://github.com/jlipps/appium/blob/master/app/android.js
def android_capabilities
\ No newline at end of file