Sha256: e97d90e28eaaf70a1a013ccaddc7c31a5548415dc42966b8673c59e38ed3600b
Contents?: true
Size: 1.95 KB
Versions: 4
Compression:
Stored size: 1.95 KB
Contents
require 'random-port' require 'socket' require 'open3' class AppiumLocalService @@sessions_with_pid = [] def get_session_details @@sessions_with_pid end def launch_appium_sessions(device_details) sessions = [] p "Device details in Launch Appium Sessions = #{device_details}" p "Device details in Launch Appium Sessions = #{device_details.length}" device_details.each do |device_detail| session_id = create_session device_detail session_info = {} session_info["sessionUrl"] = session_id session_info["sessionCapabilities"] = device_detail sessions.push(session_info) end sessions end def launch_appium_session(device_detail) session_detail = create_session device_detail p session_detail return session_detail end def create_session(device_detail) RandomPort::Pool::SINGLETON.acquire do |port| @port = port end puts @port begin Timeout.timeout(5) do @pid = spawn(get_cmd(device_detail)) Process.wait @pid end end rescue Timeout::Error p @pid @ipaddress = get_ip_address session_id = get_session_id add_session_details session_id return session_id end private def get_cmd(device_detail) case device_detail["platform"] when "ANDROID" return "appium -p #{@port} --bootstrap-port #{get_random_port} --relaxed-security" when "IOS" return "appium -p #{@port} --webdriveragent-port #{get_random_port} --relaxed-security" end end def get_random_port port = RandomPort::Pool.new.acquire return port end def get_session_id "http://#{@ipaddress}:#{@port}/wd/hub" end def get_ip_address ip = Socket.ip_address_list.detect{|intf| intf.ipv4_private?} ip.ip_address end def add_session_details(session_id) session_details = {} session_details["session_id"] = session_id session_details["session_pid"] = @pid @@sessions_with_pid.push session_details end end
Version data entries
4 entries across 4 versions & 1 rubygems