Class: Maze::Client::Appium::BaseClient
- Inherits:
-
Object
- Object
- Maze::Client::Appium::BaseClient
show all
- Defined in:
- lib/maze/client/appium/base_client.rb
Constant Summary
collapse
- FIXTURE_CONFIG =
'fixture_config.json'
Instance Method Summary
collapse
Constructor Details
Returns a new instance of BaseClient.
10
11
12
13
|
# File 'lib/maze/client/appium/base_client.rb', line 10
def initialize
@session_ids = []
@start_attempts = 0
end
|
Instance Method Details
#attempt_start_driver(config) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/maze/client/appium/base_client.rb', line 59
def attempt_start_driver(config)
config.capabilities = device_capabilities
driver = Maze::Driver::Appium.new config.appium_server_url,
config.capabilities,
config.locator
result = driver.start_driver
if result
$logger.info "Created Appium session: #{driver.session_id}"
@session_ids << driver.session_id
udid = driver.session_capabilities['udid']
$logger.info "Running on device: #{udid}" unless udid.nil?
end
driver
end
|
#device_capabilities ⇒ Object
124
125
126
|
# File 'lib/maze/client/appium/base_client.rb', line 124
def device_capabilities
raise 'Method not implemented by this class'
end
|
#handle_error(error) ⇒ Object
115
116
117
|
# File 'lib/maze/client/appium/base_client.rb', line 115
def handle_error(error)
raise 'Method not implemented by this class'
end
|
#log_run_intro ⇒ Object
128
129
130
|
# File 'lib/maze/client/appium/base_client.rb', line 128
def log_run_intro
raise 'Method not implemented by this class'
end
|
#log_run_outro ⇒ Object
132
133
134
|
# File 'lib/maze/client/appium/base_client.rb', line 132
def log_run_outro
raise 'Method not implemented by this class'
end
|
#maze_address ⇒ Object
51
52
53
|
# File 'lib/maze/client/appium/base_client.rb', line 51
def maze_address
raise 'Method not implemented by this class'
end
|
#prepare_session ⇒ Object
47
48
49
|
# File 'lib/maze/client/appium/base_client.rb', line 47
def prepare_session
raise 'Method not implemented by this class'
end
|
#retry_start_driver? ⇒ Boolean
55
56
57
|
# File 'lib/maze/client/appium/base_client.rb', line 55
def retry_start_driver?
raise 'Method not implemented by this class'
end
|
#start_driver(config, max_attempts = 5) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/maze/client/appium/base_client.rb', line 76
def start_driver(config, max_attempts = 5)
attempts = 0
while attempts < max_attempts && Maze.driver.nil?
attempts += 1
start_error = nil
begin
Maze.driver = attempt_start_driver(config)
rescue => error
$logger.error "Session creation failed: #{error}"
start_error = error
end
if Maze.driver
if Maze.config.farm == :local && Maze.config.os_version.nil?
version = case Maze.config.os
when 'android'
driver.session_capabilities['platformVersion'].to_f
when 'ios'
driver.session_capabilities['sdkVersion'].to_f
end
$logger.info "Inferred OS version to be #{version}"
Maze.config.os_version = version
end
else
interval = handle_error(start_error)
if interval && attempts < max_attempts
$logger.warn "Failed to create Appium driver, retrying in #{interval} seconds"
Kernel::sleep interval
else
$logger.error 'Failed to create Appium driver, exiting'
Kernel::exit(::Maze::Api::ExitCode::SESSION_CREATION_FAILURE)
end
end
end
end
|
#start_scenario ⇒ Object
119
120
121
122
|
# File 'lib/maze/client/appium/base_client.rb', line 119
def start_scenario
Maze.driver.get(Maze.config.app) if Maze.config.os == 'macos'
end
|
#start_session ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/maze/client/appium/base_client.rb', line 15
def start_session
prepare_session
start_driver(Maze.config)
Maze.driver.app_id = case Maze::Helper.get_current_platform
when 'android'
Maze.driver.session_capabilities['appPackage']
when 'ios'
unless app_id = Maze.driver.session_capabilities['CFBundleIdentifier']
app_id = Maze.driver.session_capabilities['bundleId']
end
app_id
end
if Maze.driver.app_id.nil?
$logger.error "Failed to determine app id."
$logger.debug "session_capabilities: #{Maze.driver.session_capabilities.inspect}"
end
begin
Maze.driver.unlock
rescue => error
Bugsnag.notify error
$logger.warn "Failed to unlock device: #{error}"
end
log_run_intro
end
|