-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtap.go
52 lines (41 loc) · 1.54 KB
/
tap.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
package gwda_ext_opencv
import (
"github.com/electricbubble/gwda"
)
func (dExt *DriverExt) Tap(pathname string) error {
return dExt.TapOffset(pathname, 0.5, 0.5)
}
func (dExt *DriverExt) TapOffset(pathname string, xOffset, yOffset float64) (err error) {
var x, y, width, height float64
if x, y, width, height, err = dExt.FindImageRectInUIKit(pathname); err != nil {
return err
}
return dExt.driver.TapFloat(x+width*xOffset, y+height*yOffset)
}
func (dExt *DriverExt) DoubleTap(pathname string) (err error) {
return dExt.DoubleTapOffset(pathname, 0.5, 0.5)
}
func (dExt *DriverExt) DoubleTapOffset(pathname string, xOffset, yOffset float64) (err error) {
var x, y, width, height float64
if x, y, width, height, err = dExt.FindImageRectInUIKit(pathname); err != nil {
return err
}
return dExt.driver.DoubleTapFloat(x+width*xOffset, y+height*yOffset)
}
// TapWithNumber sends one or more taps
func (dExt *DriverExt) TapWithNumber(pathname string, numberOfTaps int) (err error) {
return dExt.TapWithNumberOffset(pathname, numberOfTaps, 0.5, 0.5)
}
func (dExt *DriverExt) TapWithNumberOffset(pathname string, numberOfTaps int, xOffset, yOffset float64) (err error) {
if numberOfTaps <= 0 {
numberOfTaps = 1
}
var x, y, width, height float64
if x, y, width, height, err = dExt.FindImageRectInUIKit(pathname); err != nil {
return err
}
x = x + width*xOffset
y = y + height*yOffset
touchActions := gwda.NewTouchActions().Tap(gwda.NewTouchActionTap().WithXYFloat(x, y).WithCount(numberOfTaps))
return dExt.PerformTouchActions(touchActions)
}