Class: Maze::AppiumServer
- Inherits:
-
Object
- Object
- Maze::AppiumServer
- Defined in:
- lib/maze/appium_server.rb
Overview
Basic shell that runs an Appium server on a separate thread
Class Attribute Summary collapse
-
.appium_logger ⇒ Logger|nil
readonly
The logger used for creating the log file.
-
.appium_thread ⇒ thread|nil
readonly
The thread running the appium process (if available).
-
.pid ⇒ string|nil
readonly
The PID of the appium process (if available).
Class Method Summary collapse
-
.running ⇒ Boolean
Checks whether the server is running, as indicated by the @pid and the appium thread being alive.
-
.start(address: '0.0.0.0', port: '4723') ⇒ Object
Starts a separate thread running the appium server so long as: - An instance of the appium server isn’t already running - The port configured is available - The appium command is available via CLI.
-
.stop ⇒ Object
Stops the appium server, if running, using SIGINT for correct shutdown.
Class Attribute Details
.appium_logger ⇒ Logger|nil (readonly)
Returns The logger used for creating the log file.
17 18 19 |
# File 'lib/maze/appium_server.rb', line 17 def appium_logger @appium_logger end |
.appium_thread ⇒ thread|nil (readonly)
Returns The thread running the appium process (if available).
14 15 16 |
# File 'lib/maze/appium_server.rb', line 14 def appium_thread @appium_thread end |
.pid ⇒ string|nil (readonly)
Returns The PID of the appium process (if available).
11 12 13 |
# File 'lib/maze/appium_server.rb', line 11 def pid @pid end |
Class Method Details
.running ⇒ Boolean
Checks whether the server is running, as indicated by the @pid and the appium thread being alive
60 61 62 |
# File 'lib/maze/appium_server.rb', line 60 def running @appium_thread&.alive? ? true : false end |
.start(address: '0.0.0.0', port: '4723') ⇒ Object
Starts a separate thread running the appium server so long as:
- An instance of the appium server isn't already running
- The port configured is available
- The appium command is available via CLI
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/maze/appium_server.rb', line 26 def start(address: '0.0.0.0', port: '4723') return if running # Check if the appium server appears to be running already, warning and carrying on if so unless appium_port_available?(port) $logger.warn "Requested appium port:#{port} is in use. Aborting built-in appium server launch" return end # Check if appium is installed, warning if not unless appium_available? $logger.warn 'Appium is unavailable to be started from the command line. Install using `npm i -g appium`' return end start_logger @appium_thread = Thread.new do PTY.spawn('appium', '-a', address, '-p', port) do |stdout, _stdin, pid| @pid = pid $logger.trace("Appium:#{@pid}") { 'Appium server started' } stdout.each do |line| log_line(line) end end end # Temporary sleep to allow appium to start sleep 2 end |
.stop ⇒ Object
Stops the appium server, if running, using SIGINT for correct shutdown
65 66 67 68 69 70 71 72 73 |
# File 'lib/maze/appium_server.rb', line 65 def stop return unless running $logger.trace("Appium:#{@pid}") { 'Stopping appium server' } Process.kill('INT', @pid) @pid = nil @appium_thread.join @appium_thread = nil end |