yi_appium_caps_util 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 61fff7c392146eeb830c6ffd3fcba1ff20c8a006
4
+ data.tar.gz: 27dac3650436aba685c4c1c434593d24e43f7f25
5
+ SHA512:
6
+ metadata.gz: 34f3666823814f56f94a73d5b2bd39f51b1b68f8581c64fb9dcedb65d1f82fb325ac5650ebbc306d16f3068813373acd05a37fe6ded2e28740c98d2d3f6e9049
7
+ data.tar.gz: 1b07d5ca33848277491c94b9b7d0648ddcba5a02a657c680928ed030966bd0d614d381ba52eefda8330137ea2ad0ca7ae1aa1fcbf7fa8ccfb7c37caeac6ca09a
data/app/getIOSIP.zip ADDED
Binary file
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require_relative '../lib/yi_appium_caps_util.rb'
5
+
6
+ action = 'help'
7
+
8
+ options = {}
9
+
10
+ OptionParser.new do |opts|
11
+ opts.banner = "You.i Utility for appium.txt capabilities"
12
+ puts opts.banner
13
+
14
+ opts.on("-u", "--update", "update device ID and IP address") do
15
+ options[:update] = true
16
+ end
17
+ opts.on("-cPLATFORM", "--create PLATFORM", "creates the appium.txt file for specefied platform") do |c|
18
+ options[:create_caps] = c
19
+ end
20
+ opts.on("-fFILE", "--file FILE", "capabilities path and file name (default: ./appium.txt)") do |f|
21
+ options[:file] = f
22
+ end
23
+ opts.on("-h", "--help", "Prints this help") do
24
+ puts opts
25
+ exit
26
+ end
27
+ end.parse!
28
+
29
+ raise "You should pass -u or -c PLATFORM as an input argument. Type -h for help" if options[:update] == nil and options[:create_caps] == nil
30
+
31
+ if options[:update]
32
+ if options[:file]
33
+ YiAppiumCapsUtil.update(options[:file])
34
+ else
35
+ YiAppiumCapsUtil.update
36
+ end
37
+ end
38
+
39
+ if options[:create_caps]
40
+ YiAppiumCapsUtil.create(options[:create_caps].downcase)
41
+ end
@@ -0,0 +1,196 @@
1
+ require "ipaddress"
2
+ require 'socket'
3
+ require 'toml'
4
+ require 'shellwords'
5
+
6
+ class YiAppiumCapsUtil
7
+ class << self
8
+ public
9
+ def update (caps_file_name = './appium.txt')
10
+ raise "appium.txt file is missing" if not File.file?(caps_file_name)
11
+
12
+ #Read capability file
13
+ parsed_data = TOML.load_file(caps_file_name)
14
+
15
+ #Update caps
16
+ output_data = run_update(parsed_data)
17
+
18
+ #Save the file if caps have changed
19
+ if (output_data != parsed_data)
20
+ puts 'Updating caps'
21
+ write_caps(caps_file_name, output_data)
22
+ else
23
+ puts 'caps have not changed'
24
+ end
25
+ end
26
+
27
+ def create (platform_name)
28
+ template = {"caps"=>{"app"=>"",
29
+ "automationName"=>"YouiEngine",
30
+ "deviceName"=>"DeviceName",
31
+ "platformName"=>"#{platform_name}",
32
+ "youiEngineAppAddress"=>""}}
33
+
34
+ File.open("./appium.txt","w") do |f|
35
+ f.puts(TOML::Generator.new(template).body)
36
+ end
37
+ update()
38
+ end
39
+
40
+ private
41
+
42
+ # Helper function used in creating ios specefic caps
43
+ def getTeamID()
44
+ path = "/Library/MobileDevice/Provisioning Profiles".shellescape
45
+ `ln -s ~#{path} ./temp`
46
+ Dir.foreach("./temp/") do |fname|
47
+ next if fname == '.' or fname == '..'
48
+ matches = open('./temp/'+fname) { |f| f.each_line.find { |line| line.include?("TeamIdentifier") } }
49
+ if matches then
50
+ s = IO.binread('./temp/'+fname)
51
+ teamID = s.match(/TeamIdentifier(.*)TeamName/m)[1].match(/string(.*)string/m)[1].match(/>(.*)</m)[1]
52
+ `rm -fr ./temp`
53
+ return teamID
54
+ end
55
+ end
56
+ end
57
+
58
+ def run_update(parsed_data)
59
+ #Make a copy of the parsed data
60
+ output_data = Marshal.load(Marshal.dump(parsed_data))
61
+
62
+ if parsed_data['caps'] == nil
63
+ raise '[caps] is missing form appium.txt'
64
+ else
65
+ platformName_value = parsed_data['caps']['platformName']
66
+
67
+ if platformName_value == nil
68
+ raise 'platformName is missing from appium.txt'
69
+ else
70
+ case platformName_value.downcase
71
+ when 'android'
72
+ update_android_caps (output_data)
73
+ when 'ios'
74
+ update_ios_caps (output_data)
75
+ else
76
+ raise 'platformName: ' + platformName_value + ' is not supported'
77
+ end
78
+ end
79
+ end
80
+ return output_data
81
+ end
82
+
83
+ def update_android_caps (output_data)
84
+ puts 'Looking for Android device'
85
+ #Get the device name
86
+ new_device_name = `adb devices | grep -w "device" | awk -F'\tdevice' '{print $1}'`
87
+ #Remove whitespace
88
+ new_device_name = new_device_name.strip
89
+ raise "No Devices found / attached. If it is connected then check that it USB debugging is allowed and access to usb debugging for this machine is granted." if new_device_name == ''
90
+ #Replace value of deviceName
91
+ output_data['caps']['deviceName'] = new_device_name
92
+ puts 'Device ID: ' + new_device_name
93
+
94
+ #Get the device's ip address and mask
95
+ address_String = `adb shell ifconfig wlan0 | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])'`
96
+ raise "Cannot get device details. Check that it USB debugging is authorized." if !$?.success?
97
+ #Split IP from mask
98
+ new_address = address_String.split("\n")
99
+ #Replace value of youiEngineAppAddress
100
+ output_data['caps']['youiEngineAppAddress'] = new_address[0]
101
+ puts 'IP address: ' + new_address[0]
102
+ rescue RuntimeError => ex
103
+ puts ex.message
104
+ raise
105
+ rescue Exception => ex
106
+ puts "An error of type #{ex.class} happened, message is #{ex.message}"
107
+ raise
108
+ end
109
+
110
+ def update_ios_caps (output_data)
111
+ puts 'Looking for iOS device'
112
+ #Get the device UDID
113
+ new_udid = %x[idevice_id -l]
114
+ #Remove whitespace
115
+ new_udid = new_udid.strip
116
+
117
+ raise "No Devices found / attached." if (new_udid == '')
118
+
119
+ #Replace value of udid
120
+ output_data['caps']['udid'] = new_udid
121
+ puts 'udid: ' + new_udid
122
+
123
+ if (output_data['caps']['skipYouiEngineAppAddress'] != nil)
124
+ puts
125
+ puts 'Skiping IP check since skipYouiEngineAppAddress is present in appium.txt'
126
+ else
127
+ puts 'Searching for IP, this may take a few seconds...'
128
+
129
+ # uswish/Test/tools/getIOSIP
130
+ myAppFolder = File.dirname(__FILE__) + "/../app/"
131
+ myApp = myAppFolder + "Payload/getIOSIP.app"
132
+ myZipApp = myAppFolder + "getIOSIP.zip"
133
+ %x[unzip -o #{myZipApp} -d #{myAppFolder}]
134
+
135
+ puts "Launching getIP app"
136
+ #Launching app and putting (5 seconds of) log into file
137
+ ipcounter = 1
138
+ while ipcounter <= 5 do
139
+ puts "Try \# #{ipcounter}"
140
+ logs = %x[ios-deploy --justlaunch --bundle #{myApp} & (idevicesyslog) & sleep 7 ; kill $!]
141
+ File.write('logs.txt', logs)
142
+ #Getting ip from file
143
+ ip = %x[grep -Eo "youiEngineAppAddress.*" logs.txt | head -1 | awk '{print $3}'| tr -d '"']
144
+ #Remove whitespace
145
+ ip = ip.strip
146
+ puts 'IP Address: ' + ip
147
+ if (ip == "")
148
+ ipcounter +=1
149
+ else
150
+ #Found it!
151
+ ipcounter = 999
152
+ end
153
+ end
154
+ # Get the device name before deleting the file
155
+ deviceName = %x[grep -Eo "deviceName =.*" logs.txt| head -1|cut -d " " -f 3-|tr -d '"'|tr -d '\n']
156
+ platformVersion = %x[grep -Eo "platformVersion =.*" logs.txt| head -1|awk '{print $3}'| tr -d '"'|tr -d '\n']
157
+ puts 'DeviceName: ' + deviceName
158
+ puts 'platformVersion: ' + platformVersion
159
+ File.delete('logs.txt')
160
+ #Replace value of ip if found
161
+ if (ip != '') then
162
+ output_data['caps']['youiEngineAppAddress'] = ip
163
+ else
164
+ puts "Update ip address manually"
165
+ end
166
+ output_data['caps']['deviceName'] = deviceName
167
+ output_data['caps']['platformVersion'] = platformVersion
168
+
169
+ xcodeBuildVersion = %x[xcodebuild -version | head -1 | awk '{print $2}']
170
+
171
+ # Add the xcodeConfigFile in the caps if dealing with iOS 10+
172
+ if (platformVersion.to_f>=10) then
173
+ output_data['caps']['xcodeOrgId'] = getTeamID()
174
+ # NewWDA: Forces uninstall of any existing WebDriverAgent app on device. This provides stability.
175
+ output_data['caps']['useNewWDA'] = true
176
+ # Confirm xcode command line tools > xcode 7
177
+ if (xcodeBuildVersion.to_f<8) then
178
+ puts "Change to xcode version higher than xcode 7! Current version is: "+xcodeBuildVersion
179
+ end
180
+ elsif (xcodeBuildVersion.to_f>8) then
181
+ puts "Change to xcode version to xcode 7! Current version is: "+xcodeBuildVersion
182
+ end
183
+ end
184
+
185
+ rescue Exception => ex
186
+ puts "An error of type #{ex.class} happened, message is #{ex.message}"
187
+ exit
188
+ end
189
+
190
+ def write_caps(caps_file_name, output_data)
191
+ #Write the new caps to file
192
+ doc = TOML::Generator.new(output_data).body
193
+ File.open(caps_file_name, "w") {|file| file.puts doc }
194
+ end
195
+ end
196
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yi_appium_caps_util
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Simon Granger
8
+ - Mohamed Maamoun
9
+ - Tamimi Ahmad
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2017-02-10 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: 'Updates real device caps: device ID and IP for Android & iOS'
16
+ email: simon.granger@youi.tv
17
+ executables:
18
+ - yi_appium_caps_util
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - app/getIOSIP.zip
23
+ - bin/yi_appium_caps_util
24
+ - lib/yi_appium_caps_util.rb
25
+ homepage: https://github.com/YOU-i-Labs/yi_appium_caps_util
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.4.5.1
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Updates your appium.txt capabilities
49
+ test_files: []