-
Notifications
You must be signed in to change notification settings - Fork 28
/
ext_test.go
164 lines (136 loc) · 3.35 KB
/
ext_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
package guia2
import (
"testing"
)
func TestUiSelectorHelper_NewUiSelectorHelper(t *testing.T) {
uiSelector := NewUiSelectorHelper().Text("a").String()
if uiSelector != `new UiSelector().text("a");` {
t.Fatal("[ERROR]", uiSelector)
}
uiSelector = NewUiSelectorHelper().Text("a").TextStartsWith("b").String()
if uiSelector != `new UiSelector().text("a").textStartsWith("b");` {
t.Fatal("[ERROR]", uiSelector)
}
uiSelector = NewUiSelectorHelper().ClassName("android.widget.LinearLayout").Index(6).String()
if uiSelector != `new UiSelector().className("android.widget.LinearLayout").index(6);` {
t.Fatal("[ERROR]", uiSelector)
}
uiSelector = NewUiSelectorHelper().Focused(false).Instance(6).String()
if uiSelector != `new UiSelector().focused(false).instance(6);` {
t.Fatal("[ERROR]", uiSelector)
}
uiSelector = NewUiSelectorHelper().ChildSelector(NewUiSelectorHelper().Enabled(true)).String()
if uiSelector != `new UiSelector().childSelector(new UiSelector().enabled(true));` {
t.Fatal("[ERROR]", uiSelector)
}
}
func Test_getFreePort(t *testing.T) {
freePort, err := getFreePort()
if err != nil {
t.Fatal(err)
}
t.Log(freePort)
}
func TestDeviceList(t *testing.T) {
devices, err := DeviceList()
if err != nil {
t.Fatal(err)
}
for i := range devices {
t.Log(devices[i].Serial())
}
}
func TestNewUSBDriver(t *testing.T) {
SetDebug(true)
driver, err := NewUSBDriver()
if err != nil {
t.Fatal(err)
}
defer driver.Dispose()
ready, err := driver.Status()
if err != nil {
t.Fatal(err)
}
if !ready {
t.Fatal("should be 'true'")
}
}
func TestDriver_ActiveAppPackageName(t *testing.T) {
devices, err := DeviceList()
if err != nil {
t.Fatal(err)
}
dev := devices[len(devices)-1]
// SetDebug(true)
driver, err := NewUSBDriver(dev)
if err != nil {
t.Fatal(err)
}
defer driver.Dispose()
appPackageName, err := driver.ActiveAppPackageName()
if err != nil {
t.Fatal(err)
}
t.Log(appPackageName)
}
func TestDriver_AppLaunch(t *testing.T) {
driver, err := NewUSBDriver()
if err != nil {
t.Fatal(err)
}
defer driver.Dispose()
// err = driver.AppLaunch("tv.danmaku.bili", BySelector{ResourceIdID: "tv.danmaku.bili:id/action_bar_root"})
err = driver.AppLaunch("com.android.settings", BySelector{ResourceIdID: "android:id/list"})
if err != nil {
t.Fatal(err)
}
// screenshot, err := driver.Screenshot()
// if err != nil {
// t.Fatal(err)
// }
// t.Log(ioutil.WriteFile("/Users/hero/Desktop/s1.png", screenshot.Bytes(), 0600))
}
func TestDriver_AppTerminate(t *testing.T) {
driver, err := NewUSBDriver()
if err != nil {
t.Fatal(err)
}
defer driver.Dispose()
err = driver.AppTerminate("tv.danmaku.bili")
if err != nil {
t.Fatal(err)
}
}
func TestNewWiFiDriver(t *testing.T) {
driver, err := NewWiFiDriver("192.168.1.28")
if err != nil {
t.Fatal(err)
}
// SetDebug(false, true)
_, err = driver.ActiveAppActivity()
if err != nil {
t.Fatal(err)
}
}
func TestDriver_AppInstall(t *testing.T) {
driver, err := NewUSBDriver()
if err != nil {
t.Fatal(err)
}
defer driver.Dispose()
err = driver.AppInstall("/Users/hero/Desktop/xuexi_android_10002068.apk")
if err != nil {
t.Fatal(err)
}
}
func TestDriver_AppUninstall(t *testing.T) {
driver, err := NewUSBDriver()
if err != nil {
t.Fatal(err)
}
defer driver.Dispose()
err = driver.AppUninstall("cn.xuexi.android")
if err != nil {
t.Fatal(err)
}
}