class Object
Public Instance Methods
appium_server_start(**options)
click to toggle source
# File lib/Appium.rb, line 14 def appium_server_start(**options) command = 'appium' command << " --nodeconfig #{options[:config]}" if options.key?(:config) command << " -p #{options[:port]}" if options.key?(:port) command << " -bp #{options[:bp]}" if options.key?(:bp) command << " --udid #{options[:udid]}" if options.key?(:udid) command << " --automation-name #{options[:automationName]}" if options.key?(:automationName) command << " --selendroid-port #{options[:selendroidPort]}" if options.key?(:selendroidPort) command << " --webkit-debug-proxy-port #{options[:webkitPort]}" if options.key?(:webkitPort) platform = get_platform() if platform == :windows command << " --log #{options[:config_dir]}/output/#{options[:log]}" if options.key?(:log) else command << " --log #{options[:config_dir]}/output/#{options[:log]}" if options.key?(:log) end command << " --tmp /tmp/#{options[:tmp]}" if options.key?(:tmp) command << " --chromedriver-port #{options[:cp]}" if options.key?(:cp) command << " --command-timeout 180" puts command Dir.chdir('.') { if Gem::Platform.local.os == 'linux' pid = system('x-terminal-emulator -e ' + command + '&') elsif Gem::Platform.local.os == 'darwin' `osascript -e 'tell app "Terminal" to do script "#{command}"'` `osascript -e 'tell app "Terminal" to do script "ios_webkit_debug_proxy -c #{options[:udid]}:#{options[:webkitPort]} -d"'` else pid = system('start ' + command) end puts 'Waiting for Appium to start up...' sleep 5 if pid.nil? puts 'Appium server did not start :(' end } end
create_dir(name)
click to toggle source
# File lib/FileSystemHelpers.rb, line 47 def create_dir(name) FileUtils::mkdir_p name end
generate_node_config(nodeDir, file_name, udid, appium_port, ip, hubIp, platform, browser)
click to toggle source
# File lib/FileSystemHelpers.rb, line 12 def generate_node_config(nodeDir, file_name, udid, appium_port, ip, hubIp, platform, browser) f = File.new(nodeDir + "/node_configs/#{file_name}", "w") f.write( JSON.generate({ capabilities: [ { udid: udid, browserName: udid, maxInstances: 1, platform: platform, deviceName: udid, applicationName: udid }, { browserName: browser, maxInstances: 1, deviceName: udid, udid: udid, seleniumProtocol: 'WebDriver', platform: platform , applicationName: udid}], configuration: { cleanUpCycle: 2000, timeout: 299000, registerCycle: 5000, proxy: "org.openqa.grid.selenium.proxy.DefaultRemoteProxy", url: "http://#{ip}:#{appium_port}/wd/hub", host: ip, port: appium_port, maxSession: 1, register: true, hubPort: 4444, hubHost: hubIp } } ) ) f.close end
get_android_devices()
click to toggle source
# File lib/Android.rb, line 1 def get_android_devices 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 } }) end
get_device_osv(udid)
click to toggle source
# File lib/Android.rb, line 5 def get_device_osv udid command = "adb -s #{udid} shell getprop ro.build.version.sdk" `#{command}` end
get_ios_devices()
click to toggle source
# File lib/iOS.rb, line 1 def get_ios_devices 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 } }) end
get_platform()
click to toggle source
# File lib/FileSystemHelpers.rb, line 2 def get_platform() if Gem::Platform.local.os == 'darwin' return :mac elsif Gem::Platform.local.os == 'linux' return :linux else return :windows end end
launch_hub_and_nodes(ip, hubIp, nodeDir)
click to toggle source
# File lib/Appium.rb, line 56 def launch_hub_and_nodes(ip, hubIp, nodeDir) if Gem::Platform.local.os == 'darwin' ios_devices = JSON.parse(get_ios_devices) ios_devices.size.times do |index| port = 4100 + index webkitPort = 27753 + index config_name = "#{ios_devices[index]["udid"]}.json" generate_node_config nodeDir, config_name, ios_devices[index]["udid"], port, ip, hubIp, 'MAC', 'safari' node_config = nodeDir + '/node_configs/' +"#{config_name}" 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"], webkitPort: webkitPort, config_dir: nodeDir end else devices = JSON.parse(get_android_devices) devices.size.times do |index| port = 4000 + index bp = 2250 + index sdp = 5000 + index cp = 6000 + index sdkv = get_device_osv(devices[index]['udid']).strip.to_i config_name = "#{devices[index]["udid"]}.json" generate_node_config nodeDir, config_name, devices[index]["udid"], port, ip, hubIp, 'android', 'chrome' node_config = nodeDir + '/node_configs/' +"#{config_name}" if sdkv === 16 || sdkv === 17 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"], cp: cp, config_dir: nodeDir else appium_server_start config: node_config, port: port, bp: bp, udid: devices[index]["udid"], log: "appium-#{devices[index]["udid"]}.log", tmp: devices[index]["udid"], cp: cp, config_dir: nodeDir end end end end
restart_devices()
click to toggle source
# File lib/Android.rb, line 10 def restart_devices devices = JSON.parse(get_android_devices) devices.each do |device| `adb -s #{device['udid']} reboot` end end
shortname(long_name)
click to toggle source
# File lib/Appium.rb, line 7 def shortname long_name max_path = 1024 short_name = " " * max_path lfn_size = Win32API.new("kernel32", "GetShortPathName", ['P','P','L'],'L').call(long_name, short_name, max_path) return short_name[0..lfn_size-1] end