Class: AppiumServer

Inherits:
Object
  • Object
show all
Includes:
Waiter
Defined in:
lib/rutl/appium/appium_server.rb

Overview

Class to wrap Appium in a Rubyish way.

Constant Summary

Constants included from Waiter

Waiter::DEFAULT_TIMEOUT, Waiter::POLL_SLEEP_TIME

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Waiter

#await

Constructor Details

#initialize(server: nil, port: nil) ⇒ AppiumServer

Returns a new instance of AppiumServer.



10
11
12
13
# File 'lib/rutl/appium/appium_server.rb', line 10

def initialize(server: nil, port: nil)
  @server = server || 'localhost'
  @port = port || 4723
end

Instance Attribute Details

#portObject

Returns the value of attribute port.



8
9
10
# File 'lib/rutl/appium/appium_server.rb', line 8

def port
  @port
end

#serverObject

Returns the value of attribute server.



8
9
10
# File 'lib/rutl/appium/appium_server.rb', line 8

def server
  @server
end

Instance Method Details

#quiet_cmd(in_string) ⇒ Object



15
16
17
# File 'lib/rutl/appium/appium_server.rb', line 15

def quiet_cmd(in_string)
  system in_string + ' 1>nul 2>&1'
end

#startObject



19
20
21
22
23
# File 'lib/rutl/appium/appium_server.rb', line 19

def start
  raise 'server already started' if started?
  quiet_cmd('start "appium" cmd /c appium')
  await -> { started? }
end

#started?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
# File 'lib/rutl/appium/appium_server.rb', line 25

def started?
  Faraday.get("http://#{@server}:#{@port}/wd/hub/status")
  true
rescue Faraday::ConnectionFailed
  false
end

#stopObject



32
33
34
35
# File 'lib/rutl/appium/appium_server.rb', line 32

def stop
  raise 'server not started' unless started?
  quiet_cmd('taskkill /f /fi "WINDOWTITLE eq appium" /t')
end