Class: Maze::Api::Appium::AppManager

Inherits:
Manager
  • Object
show all
Defined in:
lib/maze/api/appium/app_manager.rb

Overview

Provides operations for working with the app.

Instance Method Summary collapse

Methods inherited from Manager

#fail_driver, #failed_driver?, #initialize

Constructor Details

This class inherits a constructor from Maze::Api::Appium::Manager

Instance Method Details

#activateObject

Activates the app



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/maze/api/appium/app_manager.rb', line 12

def activate
  if failed_driver?
    $logger.error 'Cannot activate the app - Appium driver failed.'
    return false
  end

  @driver.activate_app(@driver.app_id)
  true
rescue Selenium::WebDriver::Error::ServerError, Selenium::WebDriver::Error::UnknownError => e
  $logger.error "Failed to activate app: #{e.message}"
  # Assume the remote appium session has stopped, so crash out of the session
  fail_driver(e.message)
  raise e
end

#background(seconds = -1)) ⇒ Object

Instructs Appium to background the app

Parameters:

  • seconds (Integers) (defaults to: -1))

    The number of seconds to background the app for, or -1 for indefinitely



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/maze/api/appium/app_manager.rb', line 49

def background(seconds = -1)
  if failed_driver?
    $logger.error 'Cannot background the app - Appium driver failed.'
    return false
  end

  @driver.background_app(seconds)
  true
rescue Selenium::WebDriver::Error::ServerError, Selenium::WebDriver::Error::UnknownError => e
  $logger.error "Failed to background app: #{e.message}"
  # Assume the remote appium session has stopped, so crash out of the session
  fail_driver(e.message)
  raise e
end

#closeObject

Closes the app (legacy method).



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/maze/api/appium/app_manager.rb', line 83

def close
  if failed_driver?
    $logger.error 'Cannot close the app - Appium driver failed.'
    return false
  end

  @driver.close_app
  true
rescue Selenium::WebDriver::Error::ServerError, Selenium::WebDriver::Error::UnknownError => e
  $logger.error "Failed to close app: #{e.message}"
  # Assume the remote appium session has stopped, so crash out of the session
  fail_driver(e.message)
  raise e
end

#launchObject

Launches the app (legacy method).



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/maze/api/appium/app_manager.rb', line 66

def launch
  if failed_driver?
    $logger.error 'Cannot launch the app - Appium driver failed.'
    return false
  end

  @driver.launch_app
  true
rescue Selenium::WebDriver::Error::ServerError, Selenium::WebDriver::Error::UnknownError => e
  $logger.error "Failed to launch app: #{e.message}"
  # Assume the remote appium session has stopped, so crash out of the session
  fail_driver(e.message)
  raise e
end

#stateObject

Gets the app state.



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/maze/api/appium/app_manager.rb', line 100

def state
  if failed_driver?
    $logger.error('Cannot get the app state - Appium driver failed.')
    return nil
  end

  @driver.app_state(@driver.app_id)
rescue Selenium::WebDriver::Error::ServerError, Selenium::WebDriver::Error::UnknownError => e
  $logger.error "Failed to get app state: #{e.message}"
  # Assume the remote appium session has stopped, so crash out of the session
  fail_driver(e.message)
  raise e
end

#terminate(fail_driver = true) ⇒ Object

Terminates the app. If terminate fails then clients may wish to ty the legacy close method, so an option is provided to not fail the Appium driver.

Parameters:

  • fail_driver (Boolean) (defaults to: true)

    Whether to fail the Appium driver if the app cannot be terminated



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/maze/api/appium/app_manager.rb', line 31

def terminate(fail_driver = true)
  if failed_driver?
    $logger.error 'Cannot terminate the app - Appium driver failed.'
    return false
  end

  @driver.terminate_app(@driver.app_id)
  true
rescue Selenium::WebDriver::Error::ServerError, Selenium::WebDriver::Error::UnknownError => e
  $logger.error "Failed to terminate app: #{e.message}"
  # Assume the remote appium session has stopped, so crash out of the session
  fail_driver(e.message) if fail_driver
  raise e
end