appium_connect 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/AppiumConnect +3 -0
  3. data/lib/AppiumConnect.rb +143 -0
  4. metadata +47 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4e3a2c7d3e3a0e95dd757ddd2be4a73504a06679
4
+ data.tar.gz: f987f7acb5960c8f53637e88a05223a0f8ae70f6
5
+ SHA512:
6
+ metadata.gz: 6e4a219e7f0f68d318bc80796725887d1122a345f1fbca3c7e9b85e2bf2323d9389869f677b4be44a71d63ee9029ce7c9cc322cfbf01c9f9e8d286f513e1a0ec
7
+ data.tar.gz: 9644ddbd893ccf3f48475878c9fb3a898546e6d49c18f66703fb4f05226039ce801993a6bfa4cb3f34f888b28da8b6cce4f882d8e3c6415b467668281df71314
data/bin/AppiumConnect ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'AppiumConnect'
@@ -0,0 +1,143 @@
1
+ require 'parallel'
2
+ require 'json'
3
+ require 'fileutils'
4
+
5
+ def get_android_devices
6
+ ENV["DEVICES"] = JSON.generate((`adb devices`).lines.select { |line| line.match(/\tdevice$/) }.map.each_with_index { |line, index| { udid: line.split("\t")[0], thread: index + 1 } })
7
+ end
8
+
9
+ def get_ios_devices
10
+ ENV["IOS_DEVICES"] = JSON.generate((`system_profiler SPUSBDataType | sed -n -E -e '/(iPhone|iPad)/,/Serial/s/ *Serial Number: *(.+)/\\1/p'`).lines.map.each_with_index { |line, index| { udid: line.gsub(/\n/,""), thread: index + 1 } })
11
+ end
12
+
13
+ def get_device_osv udid
14
+ command = "adb -s #{udid} shell getprop ro.build.version.sdk"
15
+ `#{command}`
16
+ end
17
+
18
+ def appium_server_start(**options)
19
+ command = 'appium'
20
+ command << " --nodeconfig #{options[:config]}" if options.key?(:config)
21
+ command << " -p #{options[:port]}" if options.key?(:port)
22
+ command << " -bp #{options[:bp]}" if options.key?(:bp)
23
+ command << " --udid #{options[:udid]}" if options.key?(:udid)
24
+ command << " --automation-name #{options[:automationName]}" if options.key?(:automationName)
25
+ command << " --selendroid-port #{options[:selendroidPort]}" if options.key?(:selendroidPort)
26
+ command << " --log #{Dir.pwd}/output/#{options[:log]}" if options.key?(:log)
27
+ command << " --tmp /tmp/#{options[:tmp]}" if options.key?(:tmp)
28
+ Dir.chdir('.') {
29
+ if Gem::Platform.local.os == 'linux'
30
+ pid = system('x-terminal-emulator -e ' + command)
31
+ elsif Gem::Platform.local.os == 'darwin'
32
+ `osascript -e 'tell app "Terminal" to do script "#{command}"'`
33
+ else
34
+ pid = system('start ' + command)
35
+ end
36
+
37
+ puts 'Waiting for Appium to start up...'
38
+ sleep 5
39
+
40
+ if pid.nil?
41
+ puts 'Appium server did not start :('
42
+ end
43
+ }
44
+ end
45
+
46
+ def generate_node_config(file_name, udid, appium_port, ip, hubIp, platform)
47
+ f = File.new(Dir.pwd + "/node_configs/#{file_name}", "w")
48
+ f.write( JSON.generate({ capabilities: [{ browserName: udid, maxInstances: 1, platform: platform }],
49
+ configuration: { cleanUpCycle: 2000, timeout: 180000, registerCycle: 5000, proxy: "org.openqa.grid.selenium.proxy.DefaultRemoteProxy", url: "http://" + ip + ":#{appium_port}/wd/hub",
50
+ host: ip, port: appium_port, maxSession: 1, register: true, hubPort: 4444, hubHost: hubIp } } ) )
51
+ f.close
52
+ end
53
+
54
+ def launch_hub_and_nodes(ip, hubIp)
55
+
56
+ if Gem::Platform.local.os == 'darwin'
57
+
58
+ ios_devices = JSON.parse(get_ios_devices)
59
+
60
+ ios_devices.size.times do |index|
61
+ port = 4100 + index
62
+ config_name = "#{ios_devices[index]["udid"]}.json"
63
+ generate_node_config config_name, ios_devices[index]["udid"], port, ip, hubIp, 'MAC'
64
+ node_config = Dir.pwd + '/node_configs/' +"#{config_name}"
65
+ appium_server_start config: node_config, port: port, udid: ios_devices[index]["udid"], log: "appium-#{ios_devices[index]["udid"]}.log", tmp: ios_devices[index]["udid"]
66
+ end
67
+
68
+ else
69
+
70
+ devices = JSON.parse(get_android_devices)
71
+
72
+ devices.size.times do |index|
73
+ port = 4000 + index
74
+ bp = 2250 + index
75
+ sdp = 5000 + index
76
+ sdkv = get_device_osv(devices[index]['udid']).strip.to_i
77
+ config_name = "#{devices[index]["udid"]}.json"
78
+ generate_node_config config_name, devices[index]["udid"], port, ip, hubIp, 'android'
79
+ node_config = Dir.pwd + '/node_configs/' +"#{config_name}"
80
+ if sdkv === 16 || sdkv === 17
81
+ appium_server_start config: node_config, port: port, bp: bp, udid: devices[index]["udid"], automationName: "selendroid", selendroidPort: sdp, log: "appium-#{devices[index]["udid"]}.log", tmp: devices[index]["udid"]
82
+ else
83
+ appium_server_start config: node_config, port: port, bp: bp, udid: devices[index]["udid"], log: "appium-#{devices[index]["udid"]}.log", tmp: devices[index]["udid"]
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ def create_dir(name)
90
+ FileUtils::mkdir_p name
91
+ end
92
+
93
+ create_dir 'node_configs'
94
+ create_dir 'output'
95
+ if File.exist?('config.json')
96
+ config = JSON.parse(File.read('config.json'))
97
+
98
+ puts ''
99
+ puts 'Config file detected. Press enter to use last setting:'
100
+ puts "Hub: #{config['hubIp']} Node: #{config['nodeIp']}"
101
+
102
+ if gets.chomp() != ''
103
+
104
+ puts ''
105
+ puts 'Please Enter IP address of Hub:'
106
+ hubIp = gets.chomp()
107
+
108
+ puts ''
109
+ puts ''
110
+ puts 'Please Enter IP address of Node:'
111
+
112
+ ip = gets.chomp()
113
+
114
+ config = {hubIp: hubIp, nodeIp: ip}
115
+ File.open('config.json', 'w') do |f|
116
+ f.write(config.to_json)
117
+ end
118
+
119
+ puts 'Whoa.... Really??? [' + ip + ']? It\'s your funeral buddy!'
120
+ end
121
+ else
122
+
123
+ puts ''
124
+ puts 'Please Enter IP address of Hub:'
125
+ hubIp = gets.chomp()
126
+
127
+ puts ''
128
+ puts ''
129
+ puts 'Please Enter IP address of Node:'
130
+
131
+ ip = gets.chomp()
132
+
133
+ config = {hubIp: hubIp, nodeIp: ip}
134
+ File.open('config.json', 'w') do |f|
135
+ f.write(config.to_json)
136
+ end
137
+
138
+ puts 'Whoa.... Really??? [' + config + ']? It\'s your funeral buddy!'
139
+ end
140
+
141
+
142
+
143
+ launch_hub_and_nodes(config['nodeIp'], config['hubIp'])
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: appium_connect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Matt Watson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Looks for USB Connected devices and registers them as Appium Nodes on
14
+ Selenium Grid
15
+ email: Watson.Mattc@gmail.com
16
+ executables:
17
+ - AppiumConnect
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/AppiumConnect
22
+ - lib/AppiumConnect.rb
23
+ homepage: https://github.com/Mattwhooo/AppiumConnect
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.4.8
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Quickly Connect USB connected device to Selenium Grid
47
+ test_files: []