Skip to content

Commit 299d0c8

Browse files
Move appium.txt loading to appium_lib
1 parent aaf54be commit 299d0c8

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

lib/appium_lib/driver.rb

+49
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,55 @@
44
https://github.com/appium/appium/blob/82995f47408530c80c3376f4e07a1f649d96ba22/sample-code/examples/ruby/simple_test.rb
55
https://github.com/appium/appium/blob/c58eeb66f2d6fa3b9a89d188a2e657cca7cb300f/LICENSE
66
=end
7+
8+
# Load appium.txt (toml format) into system ENV
9+
# the basedir of this file + appium.txt is what's used
10+
# @param opts [Hash] file: '/path/to/appium.txt', verbose: true
11+
# @return [nil]
12+
def load_appium_txt opts
13+
raise 'opts must be a hash' unless opts.kind_of? Hash
14+
opts.each_pair { |k,v| opts[k.to_s.downcase.strip.intern] = v }
15+
opts = {} if opts.nil?
16+
file = opts.fetch :file, nil
17+
raise 'Must pass file' unless file
18+
verbose = opts.fetch :verbose, false
19+
# Check for env vars in .txt
20+
toml = File.expand_path File.join File.dirname(file), 'appium.txt'
21+
puts "appium.txt path: #{toml}" if verbose
22+
# @private
23+
def update data, *args
24+
args.each do |name|
25+
var = data[name]
26+
ENV[name] = var if var
27+
end
28+
end
29+
30+
toml_exists = File.exists? toml
31+
puts "Exists? #{toml_exists}" if verbose
32+
33+
if toml_exists
34+
require 'toml'
35+
require 'ap'
36+
puts "Loading #{toml}" if verbose
37+
38+
# bash requires A="OK"
39+
# toml requires A = "OK"
40+
#
41+
# A="OK" => A = "OK"
42+
data = File.read(toml).gsub /([^\s])\=(")/, "\\1 = \\2"
43+
data = TOML::Parser.new(data).parsed
44+
ap data
45+
46+
update data, 'APP_PATH', 'APP_APK', 'APP_PACKAGE',
47+
'APP_ACTIVITY', 'APP_WAIT_ACTIVITY',
48+
'SELENDROID'
49+
50+
# Ensure app path is absolute
51+
ENV['APP_PATH'] = File.expand_path ENV['APP_PATH'] if ENV['APP_PATH']
52+
end
53+
nil
54+
end
55+
756
module Appium
857
add_to_path __FILE__
958

0 commit comments

Comments
 (0)