Class: TestCentricity::AppiumServer

Inherits:
Object
  • Object
show all
Defined in:
lib/testcentricity_web/appium_server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ AppiumServer

Returns a new instance of AppiumServer.



11
12
13
# File 'lib/testcentricity_web/appium_server.rb', line 11

def initialize(params = {})
  @params = params
end

Instance Attribute Details

#processObject

Returns the value of attribute process.



9
10
11
# File 'lib/testcentricity_web/appium_server.rb', line 9

def process
  @process
end

Instance Method Details

#running?Boolean

Check to see if Appium Server is running

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/testcentricity_web/appium_server.rb', line 40

def running?
  endpoint = if ENV['APPIUM_SERVER_VERSION'] && ENV['APPIUM_SERVER_VERSION'].to_i == 1
               'http://0.0.0.0:4723/wd/hub/sessions'
             else
               'http://0.0.0.0:4723/sessions'
             end
  response = false
  begin
    response = Net::HTTP.get_response(URI(endpoint))
  rescue
  end
  response && response.code_type == Net::HTTPOK
end

#startObject

Start the Appium Server



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/testcentricity_web/appium_server.rb', line 18

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 starting'
  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

#stopObject

Stop the Appium Server



57
58
59
60
# File 'lib/testcentricity_web/appium_server.rb', line 57

def stop
  process.stop
  puts 'Appium Server has been terminated'
end