-
Notifications
You must be signed in to change notification settings - Fork 69
/
screenshot_test.go
56 lines (48 loc) · 953 Bytes
/
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
package giDevice
import (
"image"
"image/jpeg"
"image/png"
"os"
"testing"
)
var screenshotSrv Screenshot
func setupScreenshotSrv(t *testing.T) {
setupLockdownSrv(t)
var err error
if lockdownSrv, err = dev.lockdownService(); err != nil {
t.Fatal(err)
}
if screenshotSrv, err = lockdownSrv.ScreenshotService(); err != nil {
t.Fatal(err)
}
}
func Test_screenshot_Take(t *testing.T) {
setupScreenshotSrv(t)
// raw, err := dev.Screenshot()
raw, err := screenshotSrv.Take()
if err != nil {
t.Fatal(err)
}
_ = raw
img, format, err := image.Decode(raw)
if err != nil {
t.Fatal(err)
}
userHomeDir, _ := os.UserHomeDir()
file, err := os.Create(userHomeDir + "/Desktop/s1." + format)
if err != nil {
t.Fatal(err)
}
defer func() { _ = file.Close() }()
switch format {
case "png":
err = png.Encode(file, img)
case "jpeg":
err = jpeg.Encode(file, img, nil)
}
if err != nil {
t.Fatal(err)
}
t.Log(file.Name())
}