/
session.go
500 lines (402 loc) · 9.27 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
package mocks
import (
"encoding/json"
"github.com/sclevine/agouti/api"
)
type Session struct {
GetElementCall struct {
Selector api.Selector
ReturnElement *api.Element
Err error
}
GetElementsCall struct {
Selector api.Selector
ReturnElements []*api.Element
Err error
}
GetActiveElementCall struct {
ReturnElement *api.Element
Err error
}
DeleteCall struct {
Called bool
Err error
}
GetWindowCall struct {
ReturnWindow *api.Window
Err error
}
GetWindowsCall struct {
ReturnWindows []*api.Window
Err error
}
SetWindowCall struct {
Window *api.Window
Err error
}
SetWindowByNameCall struct {
Name string
Err error
}
DeleteWindowCall struct {
Called bool
Err error
}
GetScreenshotCall struct {
ReturnImage []byte
Err error
}
GetCookiesCall struct {
ReturnCookies []*api.Cookie
Err error
}
SetCookieCall struct {
Cookie *api.Cookie
Err error
}
DeleteCookieCall struct {
Name string
Err error
}
DeleteCookiesCall struct {
Called bool
Err error
}
GetURLCall struct {
ReturnURL string
Err error
}
SetURLCall struct {
URL string
Err error
}
GetTitleCall struct {
ReturnTitle string
Err error
}
GetSourceCall struct {
ReturnSource string
Err error
}
MoveToCall struct {
Element *api.Element
Offset api.Offset
Err error
}
FrameCall struct {
Frame *api.Element
Err error
}
FrameParentCall struct {
Called bool
Err error
}
ExecuteCall struct {
Body string
Arguments []interface{}
Result string
Err error
}
ForwardCall struct {
Called bool
Err error
}
BackCall struct {
Called bool
Err error
}
RefreshCall struct {
Called bool
Err error
}
GetAlertTextCall struct {
ReturnText string
Err error
}
SetAlertTextCall struct {
Text string
Err error
}
AcceptAlertCall struct {
Called bool
Err error
}
DismissAlertCall struct {
Called bool
Err error
}
NewLogsCall struct {
LogType string
ReturnLogs []api.Log
Err error
}
GetLogTypesCall struct {
ReturnTypes []string
Err error
}
DoubleClickCall struct {
Called bool
Err error
}
ClickCall struct {
Button api.Button
Err error
}
ButtonDownCall struct {
Button api.Button
Err error
}
ButtonUpCall struct {
Button api.Button
Err error
}
TouchDownCall struct {
X int
Y int
Err error
}
TouchUpCall struct {
X int
Y int
Err error
}
TouchMoveCall struct {
X int
Y int
Err error
}
TouchScrollCall struct {
Element *api.Element
Offset api.Offset
Err error
}
TouchClickCall struct {
Element *api.Element
Err error
}
TouchFlickCall struct {
Element *api.Element
Offset api.Offset
Speed api.Speed
Err error
}
TouchDoubleClickCall struct {
Element *api.Element
Err error
}
TouchLongClickCall struct {
Element *api.Element
Err error
}
DeleteLocalStorageCall struct {
Called bool
Err error
}
DeleteSessionStorageCall struct {
Called bool
Err error
}
SetImplicitWaitCall struct {
Called bool
Err error
}
SetPageLoadCall struct {
Called bool
Err error
}
SetScriptTimeoutCall struct {
Called bool
Err error
}
}
func (s *Session) Delete() error {
s.DeleteCall.Called = true
return s.DeleteCall.Err
}
func (s *Session) GetElement(selector api.Selector) (*api.Element, error) {
s.GetElementCall.Selector = selector
return s.GetElementCall.ReturnElement, s.GetElementCall.Err
}
func (s *Session) GetElements(selector api.Selector) ([]*api.Element, error) {
s.GetElementsCall.Selector = selector
return s.GetElementsCall.ReturnElements, s.GetElementsCall.Err
}
func (s *Session) GetActiveElement() (*api.Element, error) {
return s.GetActiveElementCall.ReturnElement, s.GetActiveElementCall.Err
}
func (s *Session) GetWindow() (*api.Window, error) {
return s.GetWindowCall.ReturnWindow, s.GetWindowCall.Err
}
func (s *Session) GetWindows() ([]*api.Window, error) {
return s.GetWindowsCall.ReturnWindows, s.GetWindowsCall.Err
}
func (s *Session) SetWindow(window *api.Window) error {
s.SetWindowCall.Window = window
return s.SetWindowCall.Err
}
func (s *Session) SetWindowByName(name string) error {
s.SetWindowByNameCall.Name = name
return s.SetWindowByNameCall.Err
}
func (s *Session) DeleteWindow() error {
s.DeleteWindowCall.Called = true
return s.DeleteWindowCall.Err
}
func (s *Session) GetScreenshot() ([]byte, error) {
return s.GetScreenshotCall.ReturnImage, s.GetScreenshotCall.Err
}
func (s *Session) GetCookies() ([]*api.Cookie, error) {
return s.GetCookiesCall.ReturnCookies, s.GetCookiesCall.Err
}
func (s *Session) SetCookie(cookie *api.Cookie) error {
s.SetCookieCall.Cookie = cookie
return s.SetCookieCall.Err
}
func (s *Session) DeleteCookie(name string) error {
s.DeleteCookieCall.Name = name
return s.DeleteCookieCall.Err
}
func (s *Session) DeleteCookies() error {
s.DeleteCookiesCall.Called = true
return s.DeleteCookiesCall.Err
}
func (s *Session) GetURL() (string, error) {
return s.GetURLCall.ReturnURL, s.GetURLCall.Err
}
func (s *Session) SetURL(url string) error {
s.SetURLCall.URL = url
return s.SetURLCall.Err
}
func (s *Session) GetTitle() (string, error) {
return s.GetTitleCall.ReturnTitle, s.GetTitleCall.Err
}
func (s *Session) GetSource() (string, error) {
return s.GetSourceCall.ReturnSource, s.GetSourceCall.Err
}
func (s *Session) MoveTo(element *api.Element, offset api.Offset) error {
s.MoveToCall.Element = element
s.MoveToCall.Offset = offset
return s.MoveToCall.Err
}
func (s *Session) Frame(frame *api.Element) error {
s.FrameCall.Frame = frame
return s.FrameCall.Err
}
func (s *Session) FrameParent() error {
s.FrameParentCall.Called = true
return s.FrameParentCall.Err
}
func (s *Session) Execute(body string, arguments []interface{}, result interface{}) error {
s.ExecuteCall.Body = body
s.ExecuteCall.Arguments = arguments
json.Unmarshal([]byte(s.ExecuteCall.Result), result)
return s.ExecuteCall.Err
}
func (s *Session) Forward() error {
s.ForwardCall.Called = true
return s.ForwardCall.Err
}
func (s *Session) Back() error {
s.BackCall.Called = true
return s.BackCall.Err
}
func (s *Session) Refresh() error {
s.RefreshCall.Called = true
return s.RefreshCall.Err
}
func (s *Session) GetAlertText() (string, error) {
return s.GetAlertTextCall.ReturnText, s.GetAlertTextCall.Err
}
func (s *Session) SetAlertText(text string) error {
s.SetAlertTextCall.Text = text
return s.SetAlertTextCall.Err
}
func (s *Session) AcceptAlert() error {
s.AcceptAlertCall.Called = true
return s.AcceptAlertCall.Err
}
func (s *Session) DismissAlert() error {
s.DismissAlertCall.Called = true
return s.DismissAlertCall.Err
}
func (s *Session) NewLogs(logType string) ([]api.Log, error) {
s.NewLogsCall.LogType = logType
return s.NewLogsCall.ReturnLogs, s.NewLogsCall.Err
}
func (s *Session) GetLogTypes() ([]string, error) {
return s.GetLogTypesCall.ReturnTypes, s.GetLogTypesCall.Err
}
func (s *Session) DoubleClick() error {
s.DoubleClickCall.Called = true
return s.DoubleClickCall.Err
}
func (s *Session) Click(button api.Button) error {
s.ClickCall.Button = button
return s.ClickCall.Err
}
func (s *Session) ButtonDown(button api.Button) error {
s.ButtonDownCall.Button = button
return s.ButtonDownCall.Err
}
func (s *Session) ButtonUp(button api.Button) error {
s.ButtonUpCall.Button = button
return s.ButtonUpCall.Err
}
func (s *Session) TouchDown(x, y int) error {
s.TouchDownCall.X = x
s.TouchDownCall.Y = y
return s.TouchDownCall.Err
}
func (s *Session) TouchUp(x, y int) error {
s.TouchUpCall.X = x
s.TouchUpCall.Y = y
return s.TouchUpCall.Err
}
func (s *Session) TouchMove(x, y int) error {
s.TouchMoveCall.X = x
s.TouchMoveCall.Y = y
return s.TouchMoveCall.Err
}
func (s *Session) TouchClick(element *api.Element) error {
s.TouchClickCall.Element = element
return s.TouchClickCall.Err
}
func (s *Session) TouchDoubleClick(element *api.Element) error {
s.TouchDoubleClickCall.Element = element
return s.TouchDoubleClickCall.Err
}
func (s *Session) TouchLongClick(element *api.Element) error {
s.TouchLongClickCall.Element = element
return s.TouchLongClickCall.Err
}
func (s *Session) TouchFlick(element *api.Element, offset api.Offset, speed api.Speed) error {
s.TouchFlickCall.Element = element
s.TouchFlickCall.Offset = offset
s.TouchFlickCall.Speed = speed
return s.TouchFlickCall.Err
}
func (s *Session) TouchScroll(element *api.Element, offset api.Offset) error {
s.TouchScrollCall.Element = element
s.TouchScrollCall.Offset = offset
return s.TouchScrollCall.Err
}
func (s *Session) DeleteLocalStorage() error {
s.DeleteLocalStorageCall.Called = true
return s.DeleteLocalStorageCall.Err
}
func (s *Session) DeleteSessionStorage() error {
s.DeleteSessionStorageCall.Called = true
return s.DeleteSessionStorageCall.Err
}
func (s *Session) SetImplicitWait(timeout int) error {
s.SetImplicitWaitCall.Called = true
return s.SetImplicitWaitCall.Err
}
func (s *Session) SetPageLoad(timeout int) error {
s.SetPageLoadCall.Called = true
return s.SetPageLoadCall.Err
}
func (s *Session) SetScriptTimeout(timeout int) error {
s.SetScriptTimeoutCall.Called = true
return s.SetScriptTimeoutCall.Err
}