class TestCentricity::AppiumServer

Attributes

process[RW]

Public Class Methods

new(params={}) click to toggle source
# File lib/testcentricity/app_core/appium_server.rb, line 12
def initialize(params={})
  @params = params
end

Public Instance Methods

running?() click to toggle source

Check to see if Appium Server is running

# File lib/testcentricity/app_core/appium_server.rb, line 41
def running?
  response = nil
  begin
    response = Net::HTTP.get_response(URI('http://127.0.0.1:4723/wd/hub/sessions'))
  rescue
  end
  response && response.code_type == Net::HTTPOK
end
start() click to toggle source

Start the Appium Server

# File lib/testcentricity/app_core/appium_server.rb, line 19
def start
  # terminate any currently running Appium Server
  if running?
    system('killall -9 node')
    puts 'Terminating existing Appium Server'
    sleep(5)
    puts 'Appium Server is being restarted'
  else
    puts 'Appium Server is being started'
  end
  # start new Appium Server
  @process = ChildProcess.build(*parameters)
  process.start
  # wait until confirmation that Appium Server is running
  wait = Selenium::WebDriver::Wait.new(timeout: 30)
  wait.until { running? }
  puts "Appium Server is running - PID = #{process.pid}"
end
stop() click to toggle source

Stop the Appium Server

# File lib/testcentricity/app_core/appium_server.rb, line 53
def stop
  process.stop
  puts 'Appium Server has been terminated'
end

Private Instance Methods

parameters() click to toggle source
# File lib/testcentricity/app_core/appium_server.rb, line 60
def parameters
  cmd = ['appium']
  @params.each do |key, value|
    cmd << '--' + key.to_s
    cmd << value.to_s if not value.nil? and value.size > 0
  end
  cmd
end