def launch_hub_and_nodes(platform)
      start_hub unless port_open?('localhost', 4444)
      devices = get_devices(platform)

      if devices.nil?
        puts "No devices for #{platform}, Exiting...."
        exit
      else
        save_device_data [devices]
      end

      threads = ENV['THREADS'].to_i
      if devices.size < threads
        puts "Not enough available devices, reducing to #{devices.size} threads"
        ENV['THREADS'] = devices.size.to_s
      else
        puts "Using #{threads} of the available #{devices.size} devices"
        devices = devices[0, threads]
      end


      Parallel.map_with_index(devices, in_processes: devices.size) do |device, index|
        offset = platform == 'android' ? 0 : threads
        port = 4000 + index + offset
        bp = 2250 + index + offset
        config_name = "#{device[:udid]}.json"
        generate_node_config config_name, port, device
        node_config = "#{Dir.pwd}/node_configs/#{config_name}"
        puts port
        appium_server_start config: node_config, port: port, bp: bp, udid: device[:udid],
                            log: "appium-#{device[:udid]}.log", tmp: device[:udid]
      end
    end
def launch_hub_and_nodes(platform)
      start_hub unless port_open?('localhost', 4444)
      devices = get_devices(platform)

      if devices.nil?
        puts "No devices for #{platform}, Exiting...."
        exit
      else
        save_device_data [devices]
      end

      threads = ENV['THREADS'].to_i
      if devices.size < threads
        puts "Not enough available devices, reducing to #{devices.size} threads"
        ENV['THREADS'] = devices.size.to_s
      else
        puts "Using #{threads} of the available #{devices.size} devices"
        devices = devices[0, threads]
      end


      Parallel.map_with_index(devices, in_processes: devices.size) do |device, index|
        offset = platform == 'android' ? 0 : threads
        port = 4000 + index + offset
        bp = 2250 + index + offset
        config_name = "#{device[:udid]}.json"
        generate_node_config config_name, port, device
        node_config = "#{Dir.pwd}/node_configs/#{config_name}"
        puts port
        appium_server_start config: node_config, port: port, bp: bp, udid: device[:udid],
                            log: "appium-#{device[:udid]}.log", tmp: device[:udid]
      end
    end
Launch the Selenium grid hub and required appium instances