forked from bunsenapp/go-selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote_driver_screenshot_test.go
91 lines (74 loc) · 1.93 KB
/
remote_driver_screenshot_test.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
package goselenium
import (
"errors"
"testing"
)
func Test_ScreenshotScreenshot_NoSessionIdCausesError(t *testing.T) {
api := &testableAPIService{
jsonToReturn: "",
errorToReturn: nil,
}
d := setUpDriver(setUpDefaultCaps(), api)
_, err := d.Screenshot()
if err == nil || !IsSessionIDError(err) {
t.Errorf(sessionIDErrorText)
}
}
func Test_ScreenshotScreenshot_CommunicationErrorIsReturnedCorrectly(t *testing.T) {
api := &testableAPIService{
jsonToReturn: "",
errorToReturn: errors.New("An error! :<"),
}
d := setUpDriver(setUpDefaultCaps(), api)
d.sessionID = "12345"
_, err := d.Screenshot()
if err == nil || !IsCommunicationError(err) {
t.Errorf(apiCommunicationErrorText)
}
}
func Test_ScreenshotScreenshot_UnmarshallingErrorIsReturnedCorrectly(t *testing.T) {
api := &testableAPIService{
jsonToReturn: "Invalid JSON",
errorToReturn: nil,
}
d := setUpDriver(setUpDefaultCaps(), api)
d.sessionID = "12345"
_, err := d.Screenshot()
if err == nil || !IsUnmarshallingError(err) {
t.Errorf(unmarshallingErrorText)
}
}
func Test_ScreenshotScreen_CorrectResponseCanBeReturned(t *testing.T) {
api := &testableAPIService{
jsonToReturn: `{
"state": "success",
"value": "dGVzdA=="
}`,
errorToReturn: nil,
}
d := setUpDriver(setUpDefaultCaps(), api)
d.sessionID = "12345"
resp, err := d.Screenshot()
if err != nil || resp.State != "success" || resp.EncodedImage != "dGVzdA==" {
t.Errorf(correctResponseErrorText)
}
}
func Test_ScreenshotScreenshot_Base64StringCanBeDecoded(t *testing.T) {
api := &testableAPIService{
jsonToReturn: `{
"state": "success",
"value": "dGVzdA=="
}`,
errorToReturn: nil,
}
d := setUpDriver(setUpDefaultCaps(), api)
d.sessionID = "12345"
resp, err := d.Screenshot()
if err != nil || resp.State != "success" {
t.Errorf(correctResponseErrorText)
}
bytes, err := resp.ImageBytes()
if err != nil || len(bytes) == 0 {
t.Errorf(correctResponseErrorText)
}
}