@@ -52,10 +52,15 @@ def update data, *args
52
52
53
53
update data , 'APP_PATH' , 'APP_APK' , 'APP_PACKAGE' ,
54
54
'APP_ACTIVITY' , 'APP_WAIT_ACTIVITY' ,
55
- 'SELENDROID '
55
+ 'DEVICE '
56
56
57
57
# Ensure app path is absolute
58
- ENV [ 'APP_PATH' ] = File . expand_path ENV [ 'APP_PATH' ] if ENV [ 'APP_PATH' ]
58
+ ENV [ 'APP_PATH' ] = File . expand_path ENV [ 'APP_PATH' ] if ENV [ 'APP_PATH' ] &&
59
+ !ENV [ 'APP_PATH' ] . empty?
60
+
61
+ if ! %w( ios android selendroid ) . include? ENV [ 'DEVICE' ]
62
+ raise 'DEVICE must be ios, android, or selendroid'
63
+ end
59
64
end
60
65
61
66
# return list of require files as an array
@@ -74,6 +79,10 @@ def update data, *args
74
79
end
75
80
end
76
81
82
+ module MiniTest
83
+ class Spec ; end
84
+ end
85
+
77
86
module Appium
78
87
add_to_path __FILE__
79
88
@@ -105,10 +114,11 @@ module Appium
105
114
class Driver
106
115
@@loaded = false
107
116
108
- attr_reader :default_wait , :app_path , :app_name , :selendroid ,
117
+ attr_reader :default_wait , :app_path , :app_name ,
109
118
:app_package , :app_activity , :app_wait_activity ,
110
119
:sauce_username , :sauce_access_key , :port , :os , :debug
111
120
# Creates a new driver.
121
+ # :device is :android, :ios, or :selendroid
112
122
#
113
123
# ```ruby
114
124
# # Options include:
@@ -120,11 +130,12 @@ class Driver
120
130
# require 'appium_lib'
121
131
#
122
132
# # Start iOS driver
123
- # app = { app_path: '/path/to/MyiOS.app'}
133
+ # app = { device: :ios, app_path: '/path/to/MyiOS.app'}
124
134
# Appium::Driver.new(app).start_driver
125
135
#
126
136
# # Start Android driver
127
- # apk = { app_path: '/path/to/the.apk',
137
+ # apk = { device: :android
138
+ # app_path: '/path/to/the.apk',
128
139
# app_package: 'com.example.pkg',
129
140
# app_activity: 'act.Start',
130
141
# app_wait_activity: 'act.Start'
@@ -152,10 +163,6 @@ def initialize opts={}
152
163
# The name to use for the test run on Sauce.
153
164
@app_name = opts . fetch :app_name , ENV [ 'APP_NAME' ]
154
165
155
- # If Android, this will toggle selendroid as a device
156
- @selendroid = opts . fetch :selendroid , ENV [ 'SELENDROID' ]
157
- @selendroid = 'selendroid' if @selendroid
158
-
159
166
# Android app package
160
167
@app_package = opts . fetch :app_package , ENV [ 'APP_PACKAGE' ]
161
168
@@ -173,12 +180,13 @@ def initialize opts={}
173
180
174
181
@port = opts . fetch :port , ENV [ 'PORT' ] || 4723
175
182
176
- @os = :ios
177
- @os = :android if @app_path . match /\. apk/i
183
+ # :ios, :android, :selendroid
184
+ @device = opts . fetch :device , ENV [ 'DEVICE' ] || :ios
185
+ @device = @device . intern # device must be a symbol
178
186
179
187
# load common methods
180
188
extend Appium ::Common
181
- if @os == :android
189
+ if @device == :android
182
190
raise 'APP_ACTIVITY must be set.' if @app_activity . nil?
183
191
184
192
# load Android specific methods
@@ -197,7 +205,7 @@ def initialize opts={}
197
205
puts "Debug is: #{ @debug } "
198
206
if @debug
199
207
ap opts unless opts . empty?
200
- puts "OS is: #{ @os } "
208
+ puts "Device is: #{ @device } "
201
209
patch_webdriver_bridge
202
210
end
203
211
@@ -210,7 +218,7 @@ def initialize opts={}
210
218
@@loaded = true
211
219
# Promote Appium driver methods to Object instance methods.
212
220
$driver. public_methods ( false ) . each do | m |
213
- MiniTest ::Spec . class_eval do
221
+ :: MiniTest ::Spec . class_eval do
214
222
define_method m do | *args , &block |
215
223
begin
216
224
# puts "[Object.class_eval] Calling super for '#{m}'"
@@ -264,9 +272,8 @@ def android_capabilities
264
272
browserName : 'Android' ,
265
273
platform : 'LINUX' ,
266
274
version : '4.2' ,
267
- device : @selendroid || 'Android' ,
275
+ device : @device == :android ? 'Android' : 'selendroid ',
268
276
name : @app_name || 'Ruby Console Android Appium' ,
269
- app : absolute_app_path ,
270
277
:'app-package' => @app_package ,
271
278
:'app-activity' => @app_activity ,
272
279
:'app-wait-activity' => @app_wait_activity || @app_activity
@@ -281,14 +288,15 @@ def ios_capabilities
281
288
platform : 'Mac 10.8' ,
282
289
version : '6.0' ,
283
290
device : 'iPhone Simulator' ,
284
- name : @app_name || 'Ruby Console iOS Appium' ,
285
- app : absolute_app_path
291
+ name : @app_name || 'Ruby Console iOS Appium'
286
292
}
287
293
end
288
294
289
295
# @private
290
296
def capabilities
291
- @os == :ios ? ios_capabilities : android_capabilities
297
+ caps = @device == :ios ? ios_capabilities : android_capabilities
298
+ caps [ :app ] = absolute_app_path unless @app_path . nil? || @app_path . empty?
299
+ caps
292
300
end
293
301
294
302
# Converts environment variable APP_PATH to an absolute path.
@@ -365,7 +373,7 @@ def start_driver
365
373
# Set timeout to a large number so that Appium doesn't quit
366
374
# when no commands are entered after 60 seconds.
367
375
# broken on selendroid: https://github.com/appium/appium/issues/513
368
- mobile :setCommandTimeout , timeout : 9999 unless @selendroid
376
+ mobile :setCommandTimeout , timeout : 9999 unless @device == : selendroid
369
377
370
378
# Set implicit wait by default unless we're using Pry.
371
379
@driver . manage . timeouts . implicit_wait = @default_wait unless defined? Pry
0 commit comments