-
Notifications
You must be signed in to change notification settings - Fork 69
/
device_test.go
174 lines (137 loc) · 2.96 KB
/
device_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
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
package giDevice
import (
"fmt"
"os"
"os/signal"
"testing"
"time"
)
var dev Device
func setupDevice(t *testing.T) {
setupUsbmux(t)
devices, err := um.Devices()
if err != nil {
t.Fatal(err)
}
if len(devices) == 0 {
t.Fatal("No Device")
}
dev = devices[0]
}
func Test_device_ReadPairRecord(t *testing.T) {
setupDevice(t)
pairRecord, err := dev.ReadPairRecord()
if err != nil {
t.Fatal(err)
}
t.Log(pairRecord.HostID, pairRecord.SystemBUID, pairRecord.WiFiMACAddress)
}
func Test_device_NewConnect(t *testing.T) {
setupDevice(t)
if _, err := dev.NewConnect(LockdownPort); err != nil {
t.Fatal(err)
}
}
func Test_device_DeletePairRecord(t *testing.T) {
setupDevice(t)
if err := dev.DeletePairRecord(); err != nil {
t.Fatal(err)
}
}
func Test_device_SavePairRecord(t *testing.T) {
setupLockdownSrv(t)
pairRecord, err := lockdownSrv.Pair()
if err != nil {
t.Fatal(err)
}
err = dev.SavePairRecord(pairRecord)
if err != nil {
t.Fatal(err)
}
}
func Test_device_XCTest(t *testing.T) {
setupLockdownSrv(t)
bundleID = "com.leixipaopao.WebDriverAgentRunner.xctrunner"
out, cancel, err := dev.XCTest(bundleID)
// out, cancel, err := dev.XCTest(bundleID, WithXCTestEnv(map[string]interface{}{"USE_PORT": 8222, "MJPEG_SERVER_PORT": 8333}))
if err != nil {
t.Fatal(err)
}
done := make(chan os.Signal, 1)
signal.Notify(done, os.Interrupt)
go func() {
for s := range out {
fmt.Print(s)
}
done <- os.Interrupt
}()
for {
select {
case <-done:
cancel()
fmt.Println()
t.Log("DONE")
return
}
}
}
func Test_device_AppInstall(t *testing.T) {
setupLockdownSrv(t)
ipaPath := "/private/tmp/derivedDataPath/Build/Products/Release-iphoneos/WebDriverAgentRunner-Runner.ipa"
err := dev.AppInstall(ipaPath)
if err != nil {
t.Fatal(err)
}
}
func Test_device_AppUninstall(t *testing.T) {
setupLockdownSrv(t)
bundleID = "com.leixipaopao.WebDriverAgentRunner.xctrunner"
err := dev.AppUninstall(bundleID)
if err != nil {
t.Fatal(err)
}
}
func Test_device_Syslog(t *testing.T) {
setupLockdownSrv(t)
dev.SyslogStop()
lines, err := dev.Syslog()
if err != nil {
t.Fatal(err)
}
done := make(chan os.Signal, 1)
go func() {
for line := range lines {
fmt.Println(line)
}
done <- os.Interrupt
t.Log("DONE!!!")
}()
signal.Notify(done, os.Interrupt, os.Kill)
// <-done
time.Sleep(3 * time.Second)
dev.SyslogStop()
time.Sleep(200 * time.Millisecond)
}
func Test_device_Reboot(t *testing.T) {
setupDevice(t)
dev.Reboot()
}
func Test_device_Shutdown(t *testing.T) {
setupDevice(t)
dev.Shutdown()
}
func Test_device_InstallationProxyBrowse(t *testing.T) {
setupDevice(t)
list, err := dev.InstallationProxyBrowse(
WithApplicationType(ApplicationTypeUser),
WithReturnAttributes("CFBundleDisplayName", "CFBundleIdentifier", "SequenceNumber", "SequenceNumber"),
)
// list, err := dev.InstallationProxyBrowse()
if err != nil {
t.Fatal(err)
}
t.Log(len(list))
for _, l := range list {
t.Logf("%#v", l)
}
}