/
session.go
219 lines (188 loc) · 8.42 KB
/
session.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package mobile
import "github.com/sclevine/agouti/api"
type Session struct {
*api.Session
}
//
// Appium-centric functions
//
type Action struct {
Action string `json:"action"`
Options ActionOptions `json:"options,omitempty"`
}
type ActionOptions struct {
// TODO: check which means what, what are the differences between ms and duration ?
Duration int `json:"duration,omitempty"` // which units ??
Millisecond int `json:"ms,omitempty"` // duplicates with Duration ??
X int `json:"x,omitempty"`
Y int `json:"y,omitempty"`
Element string `json:"element,omitempty"` // element ID
Count int `json:"count,omitempty"` // meaning ??
}
func (s *Session) PerformTouch(actions []Action) error {
request := struct {
Actions []Action `json:"actions"`
}{actions}
return s.Send("POST", "touch/perform", request, nil)
}
func (s *Session) InstallApp(appPath string) error {
request := struct {
AppPath string `json:"appPath"`
}{appPath}
return s.Send("POST", "appium/device/install_app", request, nil)
}
func (s *Session) RemoveApp(appId string) error {
request := struct {
AppID string `json:"appId"`
}{appId}
return s.Send("POST", "appium/device/remove_app", request, nil)
}
func (s *Session) IsAppInstalled(bundleId string) (bool, error) {
request := struct {
BundleID string `json:"bundleId"`
}{bundleId}
var out bool
if err := s.Send("POST", "appium/device/app_installed", request, &out); err != nil {
return false, err
}
return out, nil
}
func (s *Session) LaunchApp() error {
return s.Send("POST", "appium/app/launch", nil, nil)
}
func (s *Session) CloseApp() error {
return s.Send("POST", "appium/app/close", nil, nil)
}
func (s *Session) GetAppStrings(language string) ([]string, error) {
request := struct {
Language string `json:"language"`
}{language}
var strs []string
if err := s.Send("POST", "appium/app/strings", request, &strs); err != nil {
return nil, err
}
return strs, nil
}
func (s *Session) GetCurrentActivity() (string, error) {
var activity string
if err := s.Send("GET", "appium/device/current_activity", nil, &activity); err != nil {
return "", err
}
return activity, nil
}
func (s *Session) Lock() error {
return s.Send("POST", "appium/device/lock", nil, nil)
}
func (s *Session) Shake() error {
return s.Send("POST", "appium/device/shake", nil, nil)
}
func (s *Session) Reset() error {
return s.Send("POST", "appium/app/reset", nil, nil)
}
func (s *Session) OpenNotifications() error {
return s.Send("POST", "appium/device/open_notifications", nil, nil)
}
func (s *Session) GetSettings() (map[string]interface{}, error) {
var out map[string]interface{}
if err := s.Send("GET", "appium/settings", nil, &out); err != nil {
return nil, err
}
return out, nil
}
func (s *Session) UpdateSettings(settings map[string]interface{}) error {
request := struct {
Settings map[string]interface{} `json:"settings"`
}{settings}
return s.Send("POST", "appium/settings", request, nil)
}
func (s *Session) ToggleLocationServices() error {
return s.Send("POST", "appium/device/toggle_location_services", nil, nil)
}
func (s *Session) ReplaceValue(elementID, newValue string) error {
request := struct {
ElementId string `json:"elementId"`
Value []string `json:"value"`
}{elementID, []string{newValue}}
endpoint := "appium/element/" + elementID + "/replace_value"
return s.Send("POST", endpoint, request, nil)
}
var _ = `
self.command_executor._commands[Command.CONTEXTS] = \
('GET', '/session/$sessionId/contexts')
self.command_executor._commands[Command.GET_CURRENT_CONTEXT] = \
('GET', '/session/$sessionId/context')
self.command_executor._commands[Command.SWITCH_TO_CONTEXT] = \
('POST', '/session/$sessionId/context')
self.command_executor._commands[Command.TOUCH_ACTION] = \
('POST', '/session/$sessionId/touch/perform')
self.command_executor._commands[Command.MULTI_ACTION] = \
('POST', '/session/$sessionId/touch/multi/perform')
self.command_executor._commands[Command.GET_APP_STRINGS] = \
('POST', '/session/$sessionId/appium/app/strings')
# Needed for Selendroid
self.command_executor._commands[Command.KEY_EVENT] = \
('POST', '/session/$sessionId/appium/device/keyevent')
self.command_executor._commands[Command.PRESS_KEYCODE] = \
('POST', '/session/$sessionId/appium/device/press_keycode')
self.command_executor._commands[Command.LONG_PRESS_KEYCODE] = \
('POST', '/session/$sessionId/appium/device/long_press_keycode')
self.command_executor._commands[Command.GET_CURRENT_ACTIVITY] = \
('GET', '/session/$sessionId/appium/device/current_activity')
self.command_executor._commands[Command.SET_IMMEDIATE_VALUE] = \
('POST', '/session/$sessionId/appium/element/$elementId/value')
self.command_executor._commands[Command.PULL_FILE] = \
('POST', '/session/$sessionId/appium/device/pull_file')
self.command_executor._commands[Command.PULL_FOLDER] = \
('POST', '/session/$sessionId/appium/device/pull_folder')
self.command_executor._commands[Command.PUSH_FILE] = \
('POST', '/session/$sessionId/appium/device/push_file')
self.command_executor._commands[Command.BACKGROUND] = \
('POST', '/session/$sessionId/appium/app/background')
self.command_executor._commands[Command.IS_APP_INSTALLED] = \
('POST', '/session/$sessionId/appium/device/app_installed')
self.command_executor._commands[Command.INSTALL_APP] = \
('POST', '/session/$sessionId/appium/device/install_app')
self.command_executor._commands[Command.REMOVE_APP] = \
('POST', '/session/$sessionId/appium/device/remove_app')
self.command_executor._commands[Command.START_ACTIVITY] = \
('POST', '/session/$sessionId/appium/device/start_activity')
self.command_executor._commands[Command.LAUNCH_APP] = \
('POST', '/session/$sessionId/appium/app/launch')
self.command_executor._commands[Command.CLOSE_APP] = \
('POST', '/session/$sessionId/appium/app/close')
self.command_executor._commands[Command.END_TEST_COVERAGE] = \
('POST', '/session/$sessionId/appium/app/end_test_coverage')
self.command_executor._commands[Command.LOCK] = \
('POST', '/session/$sessionId/appium/device/lock')
self.command_executor._commands[Command.SHAKE] = \
('POST', '/session/$sessionId/appium/device/shake')
self.command_executor._commands[Command.RESET] = \
('POST', '/session/$sessionId/appium/app/reset')
self.command_executor._commands[Command.HIDE_KEYBOARD] = \
('POST', '/session/$sessionId/appium/device/hide_keyboard')
self.command_executor._commands[Command.OPEN_NOTIFICATIONS] = \
('POST', '/session/$sessionId/appium/device/open_notifications')
self.command_executor._commands[Command.GET_NETWORK_CONNECTION] = \
('GET', '/session/$sessionId/network_connection')
self.command_executor._commands[Command.SET_NETWORK_CONNECTION] = \
('POST', '/session/$sessionId/network_connection')
self.command_executor._commands[Command.GET_AVAILABLE_IME_ENGINES] = \
('GET', '/session/$sessionId/ime/available_engines')
self.command_executor._commands[Command.IS_IME_ACTIVE] = \
('GET', '/session/$sessionId/ime/activated')
self.command_executor._commands[Command.ACTIVATE_IME_ENGINE] = \
('POST', '/session/$sessionId/ime/activate')
self.command_executor._commands[Command.DEACTIVATE_IME_ENGINE] = \
('POST', '/session/$sessionId/ime/deactivate')
self.command_executor._commands[Command.GET_ACTIVE_IME_ENGINE] = \
('GET', '/session/$sessionId/ime/active_engine')
self.command_executor._commands[Command.REPLACE_KEYS] = \
('POST', '/session/$sessionId/appium/element/$elementId/replace_value')
self.command_executor._commands[Command.GET_SETTINGS] = \
('GET', '/session/$sessionId/appium/settings')
self.command_executor._commands[Command.UPDATE_SETTINGS] = \
('POST', '/session/$sessionId/appium/settings')
self.command_executor._commands[Command.TOGGLE_LOCATION_SERVICES] = \
('POST', '/session/$sessionId/appium/device/toggle_location_services')
:
`