-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathclient.go
889 lines (717 loc) · 20.8 KB
/
client.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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
package marionette_client
import (
"encoding/json"
"errors"
"fmt"
"math"
"strings"
)
const (
MARIONETTE_PROTOCOL_V3 = 3
WEBDRIVER_ELEMENT_KEY = "element-6066-11e4-a52e-4f735466cecf"
)
var RunningInDebugMode bool = false
type session struct {
SessionId string
Capabilities Capabilities
}
type Client struct {
session
transport Transporter
}
func NewClient() *Client {
return &Client{
session{},
&MarionetteTransport{},
}
}
func (c *Client) Transport(t Transporter) {
c.transport = t
}
func (c *Client) SessionID() string {
return c.SessionId
}
func (c *Client) Connect(host string, port int) error {
return c.transport.Connect(host, port)
}
/////////////
// SESSION //
/////////////
// NewSession create new session
func (c *Client) NewSession(sessionId string, cap *Capabilities) (*Response, error) {
data := map[string]interface{}{
"sessionId": sessionId,
"capabilities": cap,
}
var response *Response
response, err := c.transport.Send("WebDriver:NewSession", data)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(response.Value), &c)
if err != nil {
return nil, err
}
return response, nil
}
// DeleteSession Marionette currently only accepts a session id, so if
// we call delete session can also close the TCP Connection
func (c *Client) DeleteSession() error {
_, err := c.transport.Send("WebDriver:DeleteSession", nil)
if err != nil {
return err
}
return c.transport.Close()
}
// Capabilities informs the client of which WebDriver features are
// supported by Firefox and Marionette. They are immutable for the
// length of the session.
func (c *Client) GetCapabilities() (*Capabilities, error) {
r, err := c.transport.Send("WebDriver:GetCapabilities", map[string]string{})
if err != nil {
return nil, err
}
var d = map[string]any{}
err = json.Unmarshal([]byte(r.Value), &d)
if err != nil {
return nil, err
}
// older browser versions
if capabilities, exist := d["capabilities"]; exist {
var finalCap = Capabilities{}
bytes, _ := json.Marshal(capabilities)
if err := json.Unmarshal(bytes, &finalCap); err != nil {
return nil, err
}
return &finalCap, nil
}
// newer versions
if capabilities, exist := d["value"]; exist {
if value, ok := capabilities.(map[string]interface{}); ok {
var finalCap = Capabilities{}
bytes, _ := json.Marshal(value["capabilities"])
err = json.Unmarshal(bytes, &finalCap)
if err != nil {
return nil, err
}
return &finalCap, nil
}
return nil, errors.New("type assertion failed for *Capabilities")
}
return nil, errors.New("no capabilities")
}
// SetScriptTimeout Set the timeout for asynchronous script execution.
func (c *Client) SetScriptTimeout(milliseconds int) (*Response, error) {
data := map[string]int{"script": milliseconds}
return c.SetTimeouts(data)
}
// SetImplicitTimout Set timeout for searching for elements.
func (c *Client) SetImplicitTimout(milliseconds int) (*Response, error) {
data := map[string]int{"implicit": milliseconds}
return c.SetTimeouts(data)
}
// SetPageLoadTimeout Set timeout for page loading.
func (c *Client) SetPageLoadTimeout(milliseconds int) (*Response, error) {
data := map[string]int{"pageLoad": milliseconds}
return c.SetTimeouts(data)
}
// <h4>Timeouts object</h4>
//
// <dl>
// <dt><code>script</code> (number)
// <dd>Determines when to interrupt a script that is being evaluates.
//
// <dt><code>pageLoad</code> (number)
// <dd>Provides the timeout limit used to interrupt navigation of the
//
// browsing context.
//
// <dt><code>implicit</code> (number)
// <dd>Gives the timeout of when to abort when locating an element.
// </dl>
func (c *Client) SetTimeouts(data map[string]int) (*Response, error) {
r, err := c.transport.Send("WebDriver:SetTimeouts", data)
if err != nil {
return nil, err
}
return r, nil
}
// Get Timeouts Get current set timeouts
func (c *Client) GetTimeouts() (map[string]uint, error) {
r, err := c.transport.Send("WebDriver:GetTimeouts", map[string]string{})
if err != nil {
return nil, err
}
var d = map[string]uint{}
err = json.Unmarshal([]byte(r.Value), &d)
if err != nil {
return nil, err
}
return d, nil
}
////////////////
// NAVIGATION //
////////////////
// Navigate open url
func (c *Client) Navigate(url string) (*Response, error) {
r, err := c.transport.Send("WebDriver:Navigate", map[string]string{"url": url})
if err != nil {
return nil, err
}
return r, nil
}
// Title get title
func (c *Client) Title() (string, error) {
r, err := c.transport.Send("WebDriver:GetTitle", map[string]string{})
if err != nil {
return "", err
}
var d = map[string]string{}
err = json.Unmarshal([]byte(r.Value), &d)
if err != nil {
return "", err
}
return d["value"], nil
}
// Url get current url
func (c *Client) Url() (string, error) {
r, err := c.transport.Send("WebDriver:GetCurrentURL", nil)
if err != nil {
return "", err
}
var url map[string]string
err = json.Unmarshal([]byte(r.Value), &url)
if err != nil {
return "", err
}
return url["value"], nil
}
// Refresh refresh
func (c *Client) Refresh() error {
_, err := c.transport.Send("WebDriver:Refresh", nil)
if err != nil {
return err
}
return nil
}
// Back go back in navigation history
func (c *Client) Back() error {
_, err := c.transport.Send("WebDriver:Back", nil)
if err != nil {
return err
}
return nil
}
// Forward go forward in navigation history
func (c *Client) Forward() error {
_, err := c.transport.Send("WebDriver:Forward", nil)
if err != nil {
return err
}
return nil
}
// SetContext Sets the context of the subsequent commands to be either "chrome" or "content".
// Must be one of "chrome" or "content" only.
func (c *Client) SetContext(value Context) (*Response, error) {
response, err := c.transport.Send("Marionette:SetContext", map[string]string{"value": fmt.Sprint(value)})
if err != nil {
return nil, err
}
return response, nil
}
// Context Gets the context of the server, either "chrome" or "content".
func (c *Client) Context() (*Response, error) {
response, err := c.transport.Send("Marionette:GetContext", nil)
if err != nil {
return nil, err
}
return response, nil
}
/////////////////////
// WINDOWS HANDLES //
/////////////////////
// GetWindowHandle returns the current window Id
func (c *Client) GetWindowHandle() (string, error) {
r, err := c.transport.Send("WebDriver:GetWindowHandle", nil)
if err != nil {
return "", err
}
var d map[string]string
err = json.Unmarshal([]byte(r.Value), &d)
if err != nil {
return "", err
}
return d["value"], nil
}
// GetWindowHandles return array of window Id currently opened
func (c *Client) GetWindowHandles() ([]string, error) {
r, err := c.transport.Send("WebDriver:GetWindowHandles", nil)
if err != nil {
return nil, err
}
var d []string
err = json.Unmarshal([]byte(r.Value), &d)
if err != nil {
return nil, err
}
return d, nil
}
// SwitchToWindow switch to specific window.
func (c *Client) SwitchToWindow(name string) error {
_, err := c.transport.Send("WebDriver:SwitchToWindow", map[string]interface{}{"focus": true, "handle": name})
if err != nil {
return err
}
return nil
}
// GetWindowRect gets window position and size
func (c *Client) GetWindowRect() (rect *WindowRect, err error) {
r, err := c.transport.Send("WebDriver:GetWindowRect", nil)
if err != nil {
return nil, err
}
rect = new(WindowRect)
err = json.Unmarshal([]byte(r.Value), &rect)
if err != nil {
return nil, err
}
return
}
// SetWindowRect sets window position and size
func (c *Client) SetWindowRect(rect WindowRect) error {
_, err := c.transport.Send("WebDriver:SetWindowRect", map[string]interface{}{"x": rect.X, "y": rect.Y, "width": math.Floor(rect.Width), "height": math.Floor(rect.Height)})
if err != nil {
return err
}
return nil
}
// MaximizeWindow maximizes window.
func (c *Client) MaximizeWindow() (rect *WindowRect, err error) {
r, err := c.transport.Send("WebDriver:MaximizeWindow", nil)
if err != nil {
return nil, err
}
rect = new(WindowRect)
err = json.Unmarshal([]byte(r.Value), &rect)
if err != nil {
return nil, err
}
return
}
// MinimizeWindow Synchronously minimizes the user agent window as if the user pressed
// the minimize button.
func (c *Client) MinimizeWindow() (rect *WindowRect, err error) {
r, err := c.transport.Send("WebDriver:MinimizeWindow", nil)
if err != nil {
return nil, err
}
rect = new(WindowRect)
err = json.Unmarshal([]byte(r.Value), &rect)
if err != nil {
return nil, err
}
return
}
// FullscreenWindow Synchronously sets the user agent window to full screen as if the user
// had done "View > Enter Full Screen"
func (c *Client) FullscreenWindow() (rect *WindowRect, err error) {
r, err := c.transport.Send("WebDriver:FullscreenWindow", nil)
if err != nil {
return nil, err
}
rect = new(WindowRect)
err = json.Unmarshal([]byte(r.Value), &rect)
if err != nil {
return nil, err
}
return
}
// NewWindow opens a new top-level browsing context window.
//
// param: type string
// Optional type of the new top-level browsing context. Can be one of
// `tab` or `window`. Defaults to `tab`.
//
// param: focus bool
// Optional flag if the new top-level browsing context should be opened
// in foreground (focused) or background (not focused). Defaults to false.
//
// param: private bool
// Optional flag, which gets only evaluated for type `window`. True if the
// new top-level browsing context should be a private window.
// Defaults to false.
//
// return {"handle": string, "type": string}
// Handle and type of the new browsing context.
func (c *Client) NewWindow(focus bool, typ string, private bool) (*Response, error) {
r, err := c.transport.Send("WebDriver:NewWindow", map[string]interface{}{"focus": focus, "type": typ, "private": private})
if err != nil {
return nil, err
}
//TODO: would be nice if we could create a Window struct and return that struct instead of the Response object
return r, nil
}
// CloseWindow closes current window.
func (c *Client) CloseWindow() (*Response, error) {
r, err := c.transport.Send("WebDriver:CloseWindow", nil)
if err != nil {
return nil, err
}
return r, nil
}
// Close the currently selected chrome window.
//
// If it is the last window currently open, the chrome window will not be
// closed to prevent a shutdown of Firefox. Instead the returned
// list of chrome window handles is empty.
//
// return []string
// Unique chrome window handles of remaining chrome windows.
//
// error NoSuchWindowError
// Top-level browsing context has been discarded.
func (c *Client) CloseChromeWindow() (*Response, error) {
r, err := c.transport.Send("WebDriver:CloseChromeWindow", nil)
if err != nil {
return nil, err
}
return r, nil
}
////////////
// FRAMES //
////////////
// SwitchToFrame switch to frame - strategies: By(Id), By(Name) or name only.
func (c *Client) SwitchToFrame(by By, value string) error {
//with current marionette implementation we have to find the element first and send the switchToFrame
//command with the UUID, else it wont work.
//https://bugzilla.mozilla.org/show_bug.cgi?id=1143908
frame, err := c.FindElement(by, value)
if err != nil {
return err
}
_, err = c.transport.Send("WebDriver:SwitchToFrame", map[string]interface{}{"element": frame.Id(), "focus": true})
if err != nil {
return err
}
return nil
}
// SwitchToParentFrame switch to parent frame
func (c *Client) SwitchToParentFrame() error {
_, err := c.transport.Send("WebDriver:SwitchToParentFrame", nil)
if err != nil {
return err
}
return nil
}
/////////////
// COOKIES //
/////////////
// AddCookie Adds a cookie
func (c *Client) AddCookie(cookie Cookie) (*Response, error) {
r, err := c.transport.Send("WebDriver:AddCookie", map[string]interface{}{"cookie": cookie})
if err != nil {
return nil, err
}
return r, nil
}
// GetCookies Get all cookies
func (c *Client) GetCookies() ([]Cookie, error) {
r, err := c.transport.Send("WebDriver:GetCookies", nil)
if err != nil {
return nil, err
}
var cookies []Cookie
_ = json.Unmarshal([]byte(r.Value), &cookies)
return cookies, nil
}
// DeleteCookie Deletes cookie by name
func (c *Client) DeleteCookie(name string) (error, error) {
_, err := c.transport.Send("WebDriver:DeleteCookie", map[string]interface{}{"name": name})
return err, nil
}
// DeleteAllCookies Delete all cookies
func (c *Client) DeleteAllCookies() error {
_, err := c.transport.Send("WebDriver:DeleteAllCookies", nil)
return err
}
//////////////////
// WEB ELEMENTS //
//////////////////
func isElementEnabled(c *Client, id string) bool {
r, err := c.transport.Send("WebDriver:IsElementEnabled", map[string]interface{}{"id": id})
if err != nil {
return false
}
return strings.Contains(r.Value, "\"value\":true")
}
func isElementSelected(c *Client, id string) bool {
r, err := c.transport.Send("WebDriver:IsElementSelected", map[string]interface{}{"id": id})
if err != nil {
return false
}
return strings.Contains(r.Value, "\"value\":true")
}
func isElementDisplayed(c *Client, id string) bool {
r, err := c.transport.Send("WebDriver:IsElementDisplayed", map[string]interface{}{"id": id})
if err != nil {
return false
}
return strings.Contains(r.Value, "\"value\":true")
}
func getElementTagName(c *Client, id string) string {
r, err := c.transport.Send("WebDriver:GetElementTagName", map[string]interface{}{"id": id})
if err != nil {
return ""
}
var d = map[string]string{}
json.Unmarshal([]byte(r.Value), &d)
return d["value"]
}
func getElementText(c *Client, id string) string {
r, err := c.transport.Send("WebDriver:GetElementText", map[string]interface{}{"id": id})
if err != nil {
return ""
}
var d = map[string]string{}
json.Unmarshal([]byte(r.Value), &d)
return d["value"]
}
func getElementAttribute(c *Client, id string, name string) string {
r, err := c.transport.Send("WebDriver:GetElementAttribute", map[string]interface{}{"id": id, "name": name})
if err != nil {
return ""
}
var d = map[string]string{}
json.Unmarshal([]byte(r.Value), &d)
return d["value"]
}
func getElementProperty(c *Client, id string, name string) string {
r, err := c.transport.Send("WebDriver:GetElementProperty", map[string]interface{}{"id": id, "name": name})
if err != nil {
return ""
}
var d = map[string]string{}
json.Unmarshal([]byte(r.Value), &d)
return d["value"]
}
func getElementCssPropertyValue(c *Client, id string, property string) string {
r, err := c.transport.Send("WebDriver:GetElementCSSValue", map[string]interface{}{"id": id, "propertyName": property})
if err != nil {
return ""
}
var d = map[string]string{}
json.Unmarshal([]byte(r.Value), &d)
return d["value"]
}
func getElementRect(c *Client, id string) (*ElementRect, error) {
r, err := c.transport.Send("WebDriver:GetElementRect", map[string]interface{}{"id": id})
if err != nil {
return nil, err
}
var d = &ElementRect{}
err = json.Unmarshal([]byte(r.Value), &d)
if err != nil {
return nil, err
}
return d, nil
}
func clickElement(c *Client, id string) {
r, err := c.transport.Send("WebDriver:ElementClick", map[string]interface{}{"id": id})
if err != nil {
return
}
var d = map[string]interface{}{}
json.Unmarshal([]byte(r.Value), &d)
//return d
}
func sendKeysToElement(c *Client, id string, keys string) error {
//slice := make([]string, 0)
//for _, v := range keys {
// slice = append(slice, fmt.Sprintf("%c", v))
//}
//
//r, err := c.transport.Send("sendKeysToElement", map[string]interface{}{"id": id, "value": slice})
r, err := c.transport.Send("WebDriver:ElementSendKeys", map[string]interface{}{"id": id, "text": keys})
if err != nil {
return err
}
var d = map[string]interface{}{}
json.Unmarshal([]byte(r.Value), &d)
return nil
}
func clearElement(c *Client, id string) {
r, err := c.transport.Send("WebDriver:ElementClear", map[string]interface{}{"id": id})
if err != nil {
return
}
var d = map[string]interface{}{}
json.Unmarshal([]byte(r.Value), &d)
//return d
}
// FindElements Find elements using the indicated search strategy.
func (c *Client) FindElements(by By, value string) ([]*WebElement, error) {
return findElements(c, by, value, nil)
}
func findElements(c *Client, by By, value string, startNode *string) ([]*WebElement, error) {
var params map[string]interface{}
if startNode == nil || *startNode == "" {
params = map[string]interface{}{"using": fmt.Sprint(by), "value": value}
} else {
params = map[string]interface{}{"using": fmt.Sprint(by), "value": value, "element": *startNode}
}
response, err := c.transport.Send("WebDriver:FindElements", params)
if err != nil {
return nil, err
}
var d []map[string]string
err = json.Unmarshal([]byte(response.Value), &d)
if err != nil {
return nil, err
}
var e []*WebElement
for _, v := range d {
e = append(e, &WebElement{c: c, id: v[WEBDRIVER_ELEMENT_KEY]})
}
return e, nil
//return string(buf), nil
}
// FindElement Find an element using the indicated search strategy.
func (c *Client) FindElement(by By, value string) (*WebElement, error) {
return findElement(c, by, value, nil)
}
func findElement(c *Client, by By, value string, startNode *string) (*WebElement, error) {
var params map[string]string
if startNode == nil || *startNode == "" {
params = map[string]string{"using": fmt.Sprint(by), "value": value}
} else {
params = map[string]string{"using": fmt.Sprint(by), "value": value, "element": *startNode}
}
response, err := c.transport.Send("WebDriver:FindElement", params)
if err != nil {
return nil, err
}
var e = &WebElement{c: c}
err = json.Unmarshal([]byte(response.Value), &e)
if err != nil {
return nil, err
}
return e, nil
}
// GetActiveElement Returns the page's active element.
func (c *Client) GetActiveElement() (*WebElement, error) {
return getActiveElement(c)
}
func getActiveElement(c *Client) (*WebElement, error) {
response, err := c.transport.Send("WebDriver:GetActiveElement", nil)
if err != nil {
return nil, err
}
var e = &WebElement{c: c}
err = json.Unmarshal([]byte(response.Value), e)
if err != nil {
return nil, err
}
return e, nil
}
func takeScreenshot(c *Client, startNode *string) (string, error) {
var params map[string]string
if startNode == nil || *startNode == "" {
params = map[string]string{}
} else {
params = map[string]string{"id": *startNode}
}
r, err := c.transport.Send("WebDriver:TakeScreenshot", params)
if err != nil {
return "", err
}
return r.Value, nil
}
///////////////////////
// DOCUMENT HANDLING //
///////////////////////
// PageSource get page source
func (c *Client) PageSource() (*Response, error) {
response, err := c.transport.Send("WebDriver:GetPageSource", nil)
if err != nil {
return nil, err
}
return response, nil
}
// ExecuteScript Execute JS Script
func (c *Client) ExecuteScript(script string, args []interface{}, timeout uint, newSandbox bool) (*Response, error) {
parameters := map[string]interface{}{}
parameters["scriptTimeout"] = timeout
parameters["script"] = script
parameters["args"] = args
parameters["newSandbox"] = newSandbox
response, err := c.transport.Send("WebDriver:ExecuteScript", parameters)
if err != nil {
return nil, err
}
return response, nil
}
// ExecuteAsyncScript Execute JS Script Async
// TODO: Add missing arguments/options
func (c *Client) ExecuteAsyncScript(script string, args []interface{}, newSandbox bool) (*Response, error) {
parameters := map[string]interface{}{}
parameters["script"] = script
parameters["args"] = args
parameters["newSandbox"] = newSandbox
response, err := c.transport.Send("WebDriver:ExecuteAsyncScript", parameters)
if err != nil {
return nil, err
}
return response, nil
}
/////////////
// DIALOGS //
/////////////
// DismissAlert dismisses the dialog - like clicking No/Cancel
func (c *Client) DismissAlert() error {
_, err := c.transport.Send("WebDriver:DismissAlert", nil)
if err != nil {
return err
}
return nil
}
// AcceptAlert accepts the dialog - like clicking Ok/Yes
func (c *Client) AcceptAlert() error {
_, err := c.transport.Send("WebDriver:AcceptAlert", nil)
if err != nil {
return err
}
return nil
}
// TextFromAlert gets text from the dialog
func (c *Client) TextFromAlert() (string, error) {
r, err := c.transport.Send("WebDriver:GetAlertText", map[string]interface{}{"key": "value"})
if err != nil {
return "", err
}
var d = map[string]string{}
json.Unmarshal([]byte(r.Value), &d)
return d["value"], nil
}
// SendAlertText sends text to a dialog
func (c *Client) SendAlertText(keys string) error {
_, err := c.transport.Send("WebDriver:SendAlertText", map[string]interface{}{"text": keys})
if err != nil {
return err
}
return nil
}
///////////////////////
// DISPOSE TEAR DOWN //
///////////////////////
// Quit quits the session and request browser process to terminate.
func (c *Client) Quit() (*Response, error) {
r, err := c.transport.Send("Marionette:Quit", map[string][]string{"flags": {"eForceQuit"}})
if err != nil {
return nil, err
}
return r, nil
}
// Screenshot takes a screenshot of the page.
func (c *Client) Screenshot() (string, error) {
return takeScreenshot(c, nil)
}