Skip to content

Commit f76ea9b

Browse files
Add require support to appium.txt
# example appium.txt require = "common.rb" Add docs to status
1 parent 12b8e59 commit f76ea9b

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

lib/appium_lib/driver.rb

+40-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# Load appium.txt (toml format) into system ENV
99
# the basedir of this file + appium.txt is what's used
1010
# @param opts [Hash] file: '/path/to/appium.txt', verbose: true
11-
# @return [nil]
11+
# @return [Array<String>] the require files. nil if require doesn't exist
1212
def load_appium_txt opts
1313
raise 'opts must be a hash' unless opts.kind_of? Hash
1414
opts.each_pair { |k,v| opts[k.to_s.downcase.strip.intern] = v }
@@ -17,7 +17,8 @@ def load_appium_txt opts
1717
raise 'Must pass file' unless file
1818
verbose = opts.fetch :verbose, false
1919
# Check for env vars in .txt
20-
toml = File.expand_path File.join File.dirname(file), 'appium.txt'
20+
parent_dir = File.dirname file
21+
toml = File.expand_path File.join parent_dir, 'appium.txt'
2122
puts "appium.txt path: #{toml}" if verbose
2223
# @private
2324
def update data, *args
@@ -29,6 +30,7 @@ def update data, *args
2930

3031
toml_exists = File.exists? toml
3132
puts "Exists? #{toml_exists}" if verbose
33+
data = nil
3234

3335
if toml_exists
3436
require 'toml'
@@ -39,9 +41,14 @@ def update data, *args
3941
# toml requires A = "OK"
4042
#
4143
# A="OK" => A = "OK"
42-
data = File.read(toml).gsub /([^\s])\=(")/, "\\1 = \\2"
44+
data = File.read toml
45+
46+
data = data.split("\n").map do |line|
47+
line.sub /([^\s])\=/, "\\1 = "
48+
end.join "\n"
49+
4350
data = TOML::Parser.new(data).parsed
44-
ap data unless data.empty?
51+
ap data unless data.empty? if verbose
4552

4653
update data, 'APP_PATH', 'APP_APK', 'APP_PACKAGE',
4754
'APP_ACTIVITY', 'APP_WAIT_ACTIVITY',
@@ -50,7 +57,19 @@ def update data, *args
5057
# Ensure app path is absolute
5158
ENV['APP_PATH'] = File.expand_path ENV['APP_PATH'] if ENV['APP_PATH']
5259
end
53-
nil
60+
61+
# return list of require files as an array
62+
# nil if require doesn't exist
63+
if data && data['require']
64+
r = data['require']
65+
r = r.kind_of?(Array) ? r : [ r ]
66+
# ensure files are absolute
67+
r.map! do |file|
68+
file = file.include?(File::Separator) ? file :
69+
File.join(parent_dir, file)
70+
File.expand_path file
71+
end
72+
end
5473
end
5574

5675
module Appium
@@ -209,6 +228,22 @@ def initialize opts={}
209228
end # def initialize
210229

211230
# Returns the status payload
231+
#
232+
# ```ruby
233+
# {"status"=>0,
234+
# "value"=>
235+
# {"build"=>
236+
# {"version"=>"0.8.2",
237+
# "revision"=>"f2a2bc3782e4b0370d97a097d7e04913cf008995"}},
238+
# "sessionId"=>"8f4b34a7-a9a9-4ac5-b125-36258143446a"}
239+
# ```
240+
#
241+
# Discover the Appium rev running on the server.
242+
#
243+
# `status["value"]["build"]["revision"]`
244+
# `f2a2bc3782e4b0370d97a097d7e04913cf008995`
245+
#
246+
# @return [JSON]
212247
def status
213248
driver.status.payload
214249
end

0 commit comments

Comments
 (0)