Sha256: 494395454f66bfc189a4a43a2257cbd8bdaa18e9c1cffe153bdc9a6670ba153d
Contents?: true
Size: 1.92 KB
Versions: 4
Compression:
Stored size: 1.92 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}" when "IOS" return "appium -p #{@port} --webdriveragent-port #{get_random_port}" 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