Sha256: e800f3d970685547e0962c42eec186887469853abbff16a885574b6f732d60ef

Contents?: true

Size: 1.87 KB

Versions: 30

Compression:

Stored size: 1.87 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?
      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

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

    private

    # :nocov:
    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
    # :nocov:
  end
end

Version data entries

30 entries across 30 versions & 3 rubygems

Version Path
testcentricity_mobile-4.1.0 lib/testcentricity_mobile/appium_server.rb
testcentricity_web-4.6.0 lib/testcentricity_web/appium_server.rb
testcentricity_apps-4.0.15 lib/testcentricity_apps/appium_server.rb
testcentricity_mobile-4.0.14 lib/testcentricity_mobile/appium_server.rb
testcentricity_web-4.5.15 lib/testcentricity_web/appium_server.rb
testcentricity_web-4.5.14 lib/testcentricity_web/appium_server.rb
testcentricity_apps-4.0.14 lib/testcentricity_apps/appium_server.rb
testcentricity_web-4.5.13 lib/testcentricity_web/appium_server.rb
testcentricity_mobile-4.0.13 lib/testcentricity_mobile/appium_server.rb
testcentricity_apps-4.0.13 lib/testcentricity_apps/appium_server.rb
testcentricity_mobile-4.0.12 lib/testcentricity_mobile/appium_server.rb
testcentricity_web-4.5.12 lib/testcentricity_web/appium_server.rb
testcentricity_apps-4.0.12 lib/testcentricity_apps/appium_server.rb
testcentricity_web-4.5.11 lib/testcentricity_web/appium_server.rb
testcentricity_mobile-4.0.11 lib/testcentricity_mobile/appium_server.rb
testcentricity_web-4.5.10 lib/testcentricity_web/appium_server.rb
testcentricity_apps-4.0.11 lib/testcentricity_apps/appium_server.rb
testcentricity_mobile-4.0.10 lib/testcentricity_mobile/appium_server.rb
testcentricity_web-4.5.9.1 lib/testcentricity_web/appium_server.rb
testcentricity_apps-4.0.10 lib/testcentricity_apps/appium_server.rb