Class: Maze::Api::Appium::DeviceManager

Inherits:
Manager
  • Object
show all
Defined in:
lib/maze/api/appium/device_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

#backObject

Presses the Back button.



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

def back
  if failed_driver?
    $logger.error 'Cannot press the Back button - Appium driver failed.'
    return false
  end

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

#get_log(log_type) ⇒ Object

Gets logs from the device.

Parameters:

  • log_type (String)

    The type pf log to get as recognised by Appium, such as ‘syslog’



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

def get_log(log_type)
  if failed_driver?
    $logger.error 'Cannot get logs - Appium driver failed.'
    return nil
  end

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

#infoObject

Gets the device info, in JSON format



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

def info
  if failed_driver?
    $logger.error 'Cannot get the device info - Appium driver failed.'
    return nil
  end

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

#set_rotation(orientation) ⇒ Object

Sets the rotation of the device.

Parameters:

  • orientation (Symbol)

    The orientation to set the device to, :portrait or :landscape



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

def set_rotation(orientation)
  if failed_driver?
    $logger.error 'Cannot set the device rotation - Appium driver failed.'
    return false
  end

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

#unlockObject

Unlocks the device.



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

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

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