Sha256: 68571dd5ec6e1ca8d9fc7598625b72ecae413384a67b62d3a1289fb3735eea9c

Contents?: true

Size: 1.63 KB

Versions: 58

Compression:

Stored size: 1.63 KB

Contents

require 'childprocess'

#
# This class is designed to start and stop the Appium Server process.  In order to use it you must have Appium
# and node installed on your computer.  You can pass parameters to Appium at startup via the constructor.
#
module TestCentricity
  class AppiumServer
    attr_accessor :process

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

    #
    # Start the Appium Server
    #
    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

    #
    # Check to see if Appium Server is running
    #
    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

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

    private

    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
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
testcentricity_web-4.0.3 lib/testcentricity_web/appium_server.rb
testcentricity_web-4.0.2 lib/testcentricity_web/appium_server.rb
testcentricity_web-4.0.1 lib/testcentricity_web/appium_server.rb
testcentricity_web-4.0.0 lib/testcentricity_web/appium_server.rb
testcentricity_web-3.3.0 lib/testcentricity_web/appium_server.rb
testcentricity_web-3.2.25 lib/testcentricity_web/appium_server.rb
testcentricity_web-3.2.24 lib/testcentricity_web/appium_server.rb
testcentricity_web-3.2.23 lib/testcentricity_web/appium_server.rb
testcentricity_web-3.2.22 lib/testcentricity_web/appium_server.rb
testcentricity_web-3.2.21 lib/testcentricity_web/appium_server.rb
testcentricity_web-3.2.20 lib/testcentricity_web/appium_server.rb
testcentricity_web-3.2.19 lib/testcentricity_web/appium_server.rb
testcentricity_web-3.2.18 lib/testcentricity_web/appium_server.rb
testcentricity_web-3.2.17 lib/testcentricity_web/appium_server.rb
testcentricity_web-3.2.16 lib/testcentricity_web/appium_server.rb
testcentricity_web-3.2.15 lib/testcentricity_web/appium_server.rb
testcentricity_web-3.2.14 lib/testcentricity_web/appium_server.rb
testcentricity_web-3.2.13 lib/testcentricity_web/appium_server.rb
testcentricity_web-3.2.12 lib/testcentricity_web/appium_server.rb
testcentricity_web-3.2.11 lib/testcentricity_web/appium_server.rb