Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#appium_server_start(**options) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/Appium.rb', line 2

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 << " --log #{Dir.pwd}/output/#{options[:log]}" if options.key?(:log)
  command << " --tmp /tmp/#{options[:tmp]}" if options.key?(:tmp)
  command << " --chromedriver-port #{options[:cp]}" if options.key?(:cp)
  command << " --command-timeout 180"
  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}"'`
    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) ⇒ Object



23
24
25
# File 'lib/FileSystemHelpers.rb', line 23

def create_dir(name)
  FileUtils::mkdir_p name
end

#generate_node_config(nodeDir, file_name, udid, appium_port, ip, hubIp, platform, browser) ⇒ Object



12
13
14
15
16
17
18
19
20
# 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")
  puts ip
  puts appium_port
  f.write( JSON.generate({ capabilities: [{ udid: udid, browserName: udid, maxInstances: 1, platform: platform,  deviceName: udid },{ browserName: browser, maxInstances: 1,  deviceName: udid, udid: udid, seleniumProtocol: 'WebDriver', platform: platform , applicationName: udid}],
                           configuration: { cleanUpCycle: 2000, timeout: 180000, 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_devicesObject



1
2
3
# 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) ⇒ Object



5
6
7
8
# 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_devicesObject



1
2
3
# 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_platformObject



2
3
4
5
6
7
8
9
10
# 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) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/Appium.rb', line 34

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
      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"]
    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
      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
      end
    end
  end
end