forked from electricbubble/gwda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
117 lines (101 loc) · 2.41 KB
/
main.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
package main
import (
"log"
"github.com/electricbubble/gwda"
)
func main() {
driver, err := gwda.NewUSBDriver(nil)
if err != nil {
log.Fatalln(err)
}
x, y := 50, 256
err = driver.Tap(x, y)
if err != nil {
log.Fatalln(err)
}
// tap action with specified identifier
option := gwda.WithCustomOption("log", map[string]interface{}{
"enable": true,
"data": "identifier-tap-A",
})
err = driver.Tap(x, y, option)
if err != nil {
log.Fatalln(err)
}
err = driver.DoubleTap(x, y)
if err != nil {
log.Fatalln(err)
}
err = driver.TouchAndHold(x, y)
if err != nil {
log.Fatalln(err)
}
fromX, fromY, toX, toY := 50, 256, 100, 256
err = driver.Drag(fromX, fromY, toX, toY)
if err != nil {
log.Fatalln(err)
}
// drag action with specified identifier
option = gwda.WithCustomOption("log", map[string]interface{}{
"enable": true,
"data": "identifier-drag-B",
})
err = driver.Drag(fromX, fromY, toX, toY, option)
if err != nil {
log.Fatalln(err)
}
err = driver.Swipe(fromX, fromY, toX, toY)
if err != nil {
log.Fatalln(err)
}
// swipe action with specified identifier
option = gwda.WithCustomOption("log", map[string]interface{}{
"enable": true,
"data": "identifier-swipe-C",
})
err = driver.Swipe(fromX, fromY, toX, toY, option)
if err != nil {
log.Fatalln(err)
}
// 需要 3D Touch 硬件支持
// err = driver.ForceTouch(x, y, 0.8)
// if err != nil {
// log.Fatalln(err)
// }
// 多点触控
// actions := gwda.NewW3CActions().FingerAction(
// gwda.NewFingerAction().
// Move(gwda.NewFingerMove().WithXY(50, 128)).
// Down().
// Pause(0.25).
// Move(gwda.NewFingerMove().WithXY(200, 160)).
// Pause(0.25).
// Up(),
// gwda.NewFingerAction().
// Move(gwda.NewFingerMove().WithXY(300, 256)).
// Down().
// Pause(0.25).
// Move(gwda.NewFingerMove().WithXY(200, 160)).
// Pause(0.25).
// Up(),
// )
// err = driver.PerformW3CActions(actions)
// if err != nil {
// log.Fatal(err)
// }
// 一笔画手势
// touchActs := gwda.NewTouchActions().
// Press(gwda.NewTouchActionPress().WithXY(50, 150)).
// Wait(0.2).
// MoveTo(gwda.NewTouchActionMoveTo().WithXY(300, 150)).
// Wait(0.2).
// MoveTo(gwda.NewTouchActionMoveTo().WithXY(50, 256)).
// Wait(0.2).
// MoveTo(gwda.NewTouchActionMoveTo().WithXY(300, 256)).
// Release()
//
// err = driver.PerformAppiumTouchActions(touchActs)
// if err != nil {
// log.Fatal(err)
// }
}