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
# File 'lib/testcentricity_web/appium_server.rb', line 40

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

#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



52
53
54
55
# File 'lib/testcentricity_web/appium_server.rb', line 52

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