-
Notifications
You must be signed in to change notification settings - Fork 5
/
swipe.go
117 lines (87 loc) · 3.28 KB
/
swipe.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 gwda_ext_opencv
func (dExt *DriverExt) Swipe(pathname string, toX, toY int) (err error) {
return dExt.SwipeFloat(pathname, float64(toX), float64(toY))
}
func (dExt *DriverExt) SwipeFloat(pathname string, toX, toY float64) (err error) {
return dExt.SwipeOffsetFloat(pathname, toX, toY, 0.5, 0.5)
}
func (dExt *DriverExt) SwipeOffset(pathname string, toX, toY int, xOffset, yOffset float64) (err error) {
return dExt.SwipeOffsetFloat(pathname, float64(toX), float64(toY), xOffset, yOffset)
}
func (dExt *DriverExt) SwipeOffsetFloat(pathname string, toX, toY, xOffset, yOffset float64) (err error) {
var x, y, width, height float64
if x, y, width, height, err = dExt.FindImageRectInUIKit(pathname); err != nil {
return err
}
fromX := x + width*xOffset
fromY := y + height*yOffset
return dExt.driver.SwipeFloat(fromX, fromY, toX, toY)
}
func (dExt *DriverExt) SwipeUp(pathname string, distance ...float64) (err error) {
return dExt.SwipeUpOffset(pathname, 0.5, 0.9, distance...)
}
func (dExt *DriverExt) SwipeUpOffset(pathname string, xOffset, yOffset float64, distance ...float64) (err error) {
if len(distance) == 0 {
distance = []float64{1.0}
}
var x, y, width, height float64
if x, y, width, height, err = dExt.FindImageRectInUIKit(pathname); err != nil {
return err
}
fromX := x + width*xOffset
fromY := (y + height) - height*(1.0-yOffset)
toX := fromX
toY := fromY - height*distance[0]
return dExt.driver.SwipeFloat(fromX, fromY, toX, toY)
}
func (dExt *DriverExt) SwipeDown(pathname string, distance ...float64) (err error) {
return dExt.SwipeDownOffset(pathname, 0.5, 0.1, distance...)
}
func (dExt *DriverExt) SwipeDownOffset(pathname string, xOffset, yOffset float64, distance ...float64) (err error) {
if len(distance) == 0 {
distance = []float64{1.0}
}
var x, y, width, height float64
if x, y, width, height, err = dExt.FindImageRectInUIKit(pathname); err != nil {
return err
}
fromX := x + width*xOffset
fromY := y + height*yOffset
toX := fromX
toY := fromY + height*distance[0]
return dExt.driver.SwipeFloat(fromX, fromY, toX, toY)
}
func (dExt *DriverExt) SwipeLeft(pathname string, distance ...float64) (err error) {
return dExt.SwipeLeftOffset(pathname, 0.9, 0.5, distance...)
}
func (dExt *DriverExt) SwipeLeftOffset(pathname string, xOffset, yOffset float64, distance ...float64) (err error) {
if len(distance) == 0 {
distance = []float64{1.0}
}
var x, y, width, height float64
if x, y, width, height, err = dExt.FindImageRectInUIKit(pathname); err != nil {
return err
}
fromX := x + width*xOffset
fromY := y + height*yOffset
toX := fromX - width*distance[0]
toY := fromY
return dExt.driver.SwipeFloat(fromX, fromY, toX, toY)
}
func (dExt *DriverExt) SwipeRight(pathname string, distance ...float64) (err error) {
return dExt.SwipeRightOffset(pathname, 0.1, 0.5, distance...)
}
func (dExt *DriverExt) SwipeRightOffset(pathname string, xOffset, yOffset float64, distance ...float64) (err error) {
if len(distance) == 0 {
distance = []float64{1.0}
}
var x, y, width, height float64
if x, y, width, height, err = dExt.FindImageRectInUIKit(pathname); err != nil {
return err
}
fromX := x + width*xOffset
fromY := y + height*yOffset
toX := fromX + width*distance[0]
toY := fromY
return dExt.driver.SwipeFloat(fromX, fromY, toX, toY)
}