change: update function optional parameters to DataOptions

This commit is contained in:
xucong.053
2022-10-16 23:31:13 +08:00
parent 1ed4fcd1e0
commit 2df2792fe4
13 changed files with 149 additions and 150 deletions

View File

@@ -573,7 +573,7 @@ func (ud *uiaDriver) _swipe(startX, startY, endX, endY interface{}, options ...D
}
// append options in post data for extra uiautomator configurations
// e.g. use WithPressDuration to set pressForDuration
// e.g. use WithPressDurationOption to set pressForDuration
for _, option := range options {
option(data)
}
@@ -590,7 +590,7 @@ func (ud *uiaDriver) _swipe(startX, startY, endX, endY interface{}, options ...D
// per step. So for a 100 steps, the swipe will take about 1/2 second to complete.
// `steps` is the number of move steps sent to the system
func (ud *uiaDriver) Swipe(fromX, fromY, toX, toY int, options ...DataOption) error {
options = append(options, WithSteps(12))
options = append(options, WithStepsOption(12))
return ud.SwipeFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...)
}

View File

@@ -113,7 +113,7 @@ func (ue uiaElement) Swipe(fromX, fromY, toX, toY int) error {
func (ue uiaElement) SwipeFloat(fromX, fromY, toX, toY float64) error {
options := []DataOption{
WithSteps(12),
WithStepsOption(12),
WithCustomOption("elementId", ue.id),
}
return ue.parent._swipe(fromX, fromY, toX, toY, options...)

View File

@@ -38,7 +38,7 @@ func TestIOSDemo(t *testing.T) {
continue
}
err = driverExt.TapAbsXY(points[1].X, points[1].Y, "")
err = driverExt.TapAbsXY(points[1].X, points[1].Y)
if err != nil {
t.Fatal(err)
}

View File

@@ -26,5 +26,5 @@ func (dExt *DriverExt) DragOffsetFloat(pathname string, toX, toY, xOffset, yOffs
fromY := y + height*yOffset
return dExt.Driver.DragFloat(fromX, fromY, toX, toY,
WithPressDuration(pressForDuration[0]))
WithPressDurationOption(pressForDuration[0]))
}

View File

@@ -307,13 +307,13 @@ func (dExt *DriverExt) FindUIElement(param string) (ele WebElement, err error) {
return dExt.Driver.FindElement(selector)
}
func (dExt *DriverExt) FindUIRectInUIKit(search string, index ...int) (x, y, width, height float64, err error) {
func (dExt *DriverExt) FindUIRectInUIKit(search string, options ...DataOption) (x, y, width, height float64, err error) {
// click on text, using OCR
if !isPathExists(search) {
return dExt.FindTextByOCR(search, WithCustomOption("index", index))
return dExt.FindTextByOCR(search, options...)
}
// click on image, using opencv
return dExt.FindImageRectInUIKit(search, index...)
return dExt.FindImageRectInUIKit(search, options...)
}
func (dExt *DriverExt) MappingToRectInUIKit(rect image.Rectangle) (x, y, width, height float64) {
@@ -383,26 +383,19 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
action.Scope = []float64{0, 0, 1, 1}
}
var options []DataOption
options = append(options,
WithCustomOption("index", []int{action.Index}),
WithCustomOption("scope", []int{
int(action.Scope[0] * float64(dExt.windowSize.Width) * dExt.scale),
int(action.Scope[1] * float64(dExt.windowSize.Height) * dExt.scale),
int(action.Scope[2] * float64(dExt.windowSize.Width) * dExt.scale),
int(action.Scope[3] * float64(dExt.windowSize.Height) * dExt.scale),
}),
)
identifierOption := WithIdentifierOption(action.Identifier)
indexOption := WithIndexOption(action.Index)
scopeOption := WithScopeOption(dExt.GetAbsScope(action.Scope[0], action.Scope[1], action.Scope[2], action.Scope[3]))
var point PointF
findApp := func(d *DriverExt) error {
var err error
point, err = d.GetTextXY(appName, options...)
point, err = d.GetTextXY(appName, scopeOption, indexOption)
return err
}
foundAppAction := func(d *DriverExt) error {
// click app to launch
return d.TapAbsXY(point.X, point.Y-25, action.Identifier)
return d.TapAbsXY(point.X, point.Y-25, identifierOption)
}
// go to home screen
@@ -430,26 +423,19 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
action.Scope = []float64{0, 0, 1, 1}
}
var options []DataOption
options = append(options,
WithCustomOption("index", []int{action.Index}),
WithCustomOption("scope", []int{
int(action.Scope[0] * float64(dExt.windowSize.Width) * dExt.scale),
int(action.Scope[1] * float64(dExt.windowSize.Height) * dExt.scale),
int(action.Scope[2] * float64(dExt.windowSize.Width) * dExt.scale),
int(action.Scope[3] * float64(dExt.windowSize.Height) * dExt.scale),
}),
)
identifierOption := WithIdentifierOption(action.Identifier)
indexOption := WithIndexOption(action.Index)
scopeOption := WithScopeOption(dExt.GetAbsScope(action.Scope[0], action.Scope[1], action.Scope[2], action.Scope[3]))
var point PointF
findText := func(d *DriverExt) error {
var err error
point, err = d.GetTextXY(text, options...)
point, err = d.GetTextXY(text, indexOption, scopeOption)
return err
}
foundTextAction := func(d *DriverExt) error {
// tap text
return d.TapAbsXY(point.X, point.Y, action.Identifier)
return d.TapAbsXY(point.X, point.Y, identifierOption)
}
// default to retry 10 times
@@ -478,20 +464,12 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
action.Scope = []float64{0, 0, 1, 1}
}
var options []DataOption
options = append(options,
WithCustomOption("scope", []int{
int(action.Scope[0] * float64(dExt.windowSize.Width) * dExt.scale),
int(action.Scope[1] * float64(dExt.windowSize.Height) * dExt.scale),
int(action.Scope[2] * float64(dExt.windowSize.Width) * dExt.scale),
int(action.Scope[3] * float64(dExt.windowSize.Height) * dExt.scale),
}),
)
scopeOption := WithScopeOption(dExt.GetAbsScope(action.Scope[0], action.Scope[1], action.Scope[2], action.Scope[3]))
var point PointF
findText := func(d *DriverExt) error {
var err error
points, err := d.GetTextXYs(texts, options...)
points, err := d.GetTextXYs(texts, scopeOption)
if err != nil {
return err
}
@@ -504,7 +482,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
}
foundTextAction := func(d *DriverExt) error {
// tap text
return d.TapAbsXY(point.X, point.Y, action.Identifier)
return d.TapAbsXY(point.X, point.Y, WithIdentifierOption(action.Identifier))
}
// default to retry 10 times
@@ -542,7 +520,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
}
x, _ := location[0].(float64)
y, _ := location[1].(float64)
return dExt.TapXY(x, y, action.Identifier)
return dExt.TapXY(x, y, WithIdentifierOption(action.Identifier))
}
return fmt.Errorf("invalid %s params: %v", ACTION_TapXY, action.Params)
case ACTION_TapAbsXY:
@@ -553,12 +531,12 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
}
x, _ := location[0].(float64)
y, _ := location[1].(float64)
return dExt.TapAbsXY(x, y, action.Identifier)
return dExt.TapAbsXY(x, y, WithIdentifierOption(action.Identifier))
}
return fmt.Errorf("invalid %s params: %v", ACTION_TapAbsXY, action.Params)
case ACTION_Tap:
if param, ok := action.Params.(string); ok {
return dExt.Tap(param, action.Identifier, action.IgnoreNotFoundError, action.Index)
return dExt.Tap(param, WithIdentifierOption(action.Identifier), WithIgnoreNotFoundErrorOption(true), WithIndexOption(action.Index))
}
return fmt.Errorf("invalid %s params: %v", ACTION_Tap, action.Params)
case ACTION_TapByOCR:
@@ -567,22 +545,16 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
action.Scope = []float64{0, 0, 1, 1}
}
var options []DataOption
options = append(options,
WithCustomOption("index", []int{action.Index}),
WithCustomOption("scope", []int{
int(action.Scope[0] * float64(dExt.windowSize.Width) * dExt.scale),
int(action.Scope[1] * float64(dExt.windowSize.Height) * dExt.scale),
int(action.Scope[2] * float64(dExt.windowSize.Width) * dExt.scale),
int(action.Scope[3] * float64(dExt.windowSize.Height) * dExt.scale),
}),
)
return dExt.TapByOCR(ocrText, action.Identifier, action.IgnoreNotFoundError, options...)
indexOption := WithIndexOption(action.Index)
scopeOption := WithScopeOption(dExt.GetAbsScope(action.Scope[0], action.Scope[1], action.Scope[2], action.Scope[3]))
identifierOption := WithIdentifierOption(action.Identifier)
IgnoreNotFoundErrorOption := WithIgnoreNotFoundErrorOption(action.IgnoreNotFoundError)
return dExt.TapByOCR(ocrText, identifierOption, IgnoreNotFoundErrorOption, indexOption, scopeOption)
}
return fmt.Errorf("invalid %s params: %v", ACTION_TapByOCR, action.Params)
case ACTION_TapByCV:
if imagePath, ok := action.Params.(string); ok {
return dExt.TapByCV(imagePath, action.Identifier, action.IgnoreNotFoundError, action.Index)
return dExt.TapByCV(imagePath, WithIdentifierOption(action.Identifier), WithIgnoreNotFoundErrorOption(true), WithIndexOption(action.Index))
}
return fmt.Errorf("invalid %s params: %v", ACTION_TapByCV, action.Params)
case ACTION_DoubleTapXY:
@@ -602,6 +574,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
}
return fmt.Errorf("invalid %s params: %v", ACTION_DoubleTap, action.Params)
case ACTION_Swipe:
identifierOption := WithIdentifierOption(action.Identifier)
if positions, ok := action.Params.([]interface{}); ok {
// relative fromX, fromY, toX, toY of window size: [0.5, 0.9, 0.5, 0.1]
if len(positions) != 4 {
@@ -611,10 +584,10 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
fromY, _ := positions[1].(float64)
toX, _ := positions[2].(float64)
toY, _ := positions[3].(float64)
return dExt.SwipeRelative(fromX, fromY, toX, toY, action.Identifier)
return dExt.SwipeRelative(fromX, fromY, toX, toY, identifierOption)
}
if direction, ok := action.Params.(string); ok {
return dExt.SwipeTo(direction, action.Identifier)
return dExt.SwipeTo(direction, identifierOption)
}
return fmt.Errorf("invalid %s params: %v", ACTION_Swipe, action.Params)
case ACTION_Input:
@@ -633,10 +606,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
options = append(options, WithCustomOption("description", action.Description))
}
if action.Identifier != "" {
options = append(options, WithCustomOption("log", map[string]interface{}{
"enable": true,
"data": action.Identifier,
}))
options = append(options, WithIdentifierOption(action.Identifier))
}
return dExt.Driver.Input(param, options...)
case CtlSleep:
@@ -671,6 +641,13 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
return nil
}
func (dExt *DriverExt) GetAbsScope(x1, y1, x2, y2 float64) (int, int, int, int) {
return int(x1 * float64(dExt.windowSize.Width) * dExt.scale),
int(y1 * float64(dExt.windowSize.Height) * dExt.scale),
int(x2 * float64(dExt.windowSize.Width) * dExt.scale),
int(y2 * float64(dExt.windowSize.Height) * dExt.scale)
}
func (dExt *DriverExt) DoValidation(check, assert, expected string, message ...string) bool {
var exists bool
if assert == AssertionExists {

View File

@@ -781,24 +781,54 @@ func WithCustomOption(key string, value interface{}) DataOption {
}
}
func WithPressDuration(duraion float64) DataOption {
func WithPressDurationOption(duraion float64) DataOption {
return func(data map[string]interface{}) {
data["duration"] = duraion
}
}
func WithSteps(steps int) DataOption {
func WithStepsOption(steps int) DataOption {
return func(data map[string]interface{}) {
data["steps"] = steps
}
}
func WithFrequency(frequency int) DataOption {
func WithFrequencyOption(frequency int) DataOption {
return func(data map[string]interface{}) {
data["frequency"] = frequency
}
}
func WithIndexOption(index int) DataOption {
return func(data map[string]interface{}) {
data["index"] = index
}
}
func WithScopeOption(x1, x2, y1, y2 int) DataOption {
return func(data map[string]interface{}) {
data["scope"] = []int{x1, x2, y1, y2}
}
}
func WithIdentifierOption(identifier string) DataOption {
if identifier == "" {
return func(data map[string]interface{}) {}
}
return func(data map[string]interface{}) {
data["log"] = map[string]interface{}{
"enable": true,
"data": identifier,
}
}
}
func WithIgnoreNotFoundErrorOption(ignoreError bool) DataOption {
return func(data map[string]interface{}) {
data["ignoreNotFoundError"] = ignoreError
}
}
// current implemeted device: IOSDevice, AndroidDevice
type Device interface {
UUID() string
@@ -905,7 +935,7 @@ type WebDriver interface {
TouchAndHoldFloat(x, y float64, second ...float64) error
// Drag Initiates a press-and-hold gesture at the coordinate, then drags to another coordinate.
// WithPressDuration option can be used to set pressForDuration (default to 1 second).
// WithPressDurationOption option can be used to set pressForDuration (default to 1 second).
Drag(fromX, fromY, toX, toY int, options ...DataOption) error
DragFloat(fromX, fromY, toX, toY float64, options ...DataOption) error

View File

@@ -434,7 +434,7 @@ func (wd *wdaDriver) DragFloat(fromX, fromY, toX, toY float64, options ...DataOp
}
// append options in post data for extra WDA configurations
// e.g. use WithPressDuration to set pressForDuration
// e.g. use WithPressDurationOption to set pressForDuration
for _, option := range options {
option(data)
}
@@ -447,12 +447,12 @@ func (wd *wdaDriver) DragFloat(fromX, fromY, toX, toY float64, options ...DataOp
}
func (wd *wdaDriver) Swipe(fromX, fromY, toX, toY int, options ...DataOption) error {
options = append(options, WithPressDuration(0))
options = append(options, WithPressDurationOption(0))
return wd.SwipeFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...)
}
func (wd *wdaDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...DataOption) error {
options = append(options, WithPressDuration(0))
options = append(options, WithPressDurationOption(0))
return wd.DragFloat(fromX, fromY, toX, toY, options...)
}

View File

@@ -443,7 +443,7 @@ func Test_remoteWD_TouchAndHold(t *testing.T) {
func Test_remoteWD_Drag(t *testing.T) {
setup(t)
// err := driver.Drag(200, 300, 200, 500, WithPressDuration(0.5))
// err := driver.Drag(200, 300, 200, 500, WithPressDurationOption(0.5))
err := driver.Swipe(200, 300, 200, 500)
if err != nil {
t.Fatal(err)

View File

@@ -117,23 +117,14 @@ func (s *veDEMOCRService) FindText(text string, imageBuf []byte, options ...Data
}
if _, ok := data["index"]; !ok {
data["index"] = []int{0} // index not specified
data["index"] = 0 // index not specified
}
index, _ := data["index"].(int)
index, ok := data["index"].([]int)
if !ok || len(index) == 0 {
index = []int{0}
}
_, ok = data["scope"]
if !ok {
if _, ok := data["scope"]; !ok {
data["scope"] = []int{0, 0, math.MaxInt64, math.MaxInt64} // scope not specified
}
scope, ok := data["scope"].([]int)
if !ok || len(scope) != 4 {
scope = []int{0, 0, math.MaxInt64, math.MaxInt64}
}
scope, _ := data["scope"].([]int)
ocrResults, err := s.getOCRResult(imageBuf)
if err != nil {
@@ -172,7 +163,7 @@ func (s *veDEMOCRService) FindText(text string, imageBuf []byte, options ...Data
}
// match exactly, and not specify index, return the first one
if index[0] == 0 {
if index == 0 {
return rect, nil
}
}
@@ -183,7 +174,7 @@ func (s *veDEMOCRService) FindText(text string, imageBuf []byte, options ...Data
}
// get index
idx := index[0]
idx := index
if idx > 0 {
// NOTICE: index start from 1
idx = idx - 1
@@ -212,19 +203,15 @@ func (s *veDEMOCRService) FindTexts(texts []string, imageBuf []byte, options ...
option(data)
}
_, ok := data["scope"]
if !ok {
if _, ok := data["scope"]; !ok {
data["scope"] = []int{0, 0, math.MaxInt64, math.MaxInt64} // scope not specified
}
scope, ok := data["scope"].([]int)
if !ok || len(scope) != 4 {
scope = []int{0, 0, math.MaxInt64, math.MaxInt64}
}
scope, _ := data["scope"].([]int)
var success bool
var rect image.Rectangle
var ocrTexts []string
ocrTexts := map[string]bool{}
for _, text := range texts {
var found bool
for _, ocrResult := range ocrResults {
@@ -240,8 +227,8 @@ func (s *veDEMOCRService) FindTexts(texts []string, imageBuf []byte, options ...
},
}
if rect.Min.X > scope[0] && rect.Max.X < scope[2] && rect.Min.Y > scope[1] && rect.Max.Y < scope[3] {
ocrTexts = append(ocrTexts, ocrResult.Text)
if rect.Min.X >= scope[0] && rect.Max.X <= scope[2] && rect.Min.Y >= scope[1] && rect.Max.Y <= scope[3] {
ocrTexts[ocrResult.Text] = true
// not contains text
if !strings.Contains(ocrResult.Text, text) {

View File

@@ -17,7 +17,7 @@ func (dExt *DriverExt) FindAllImageRect(search string) (rects []image.Rectangle,
return
}
func (dExt *DriverExt) FindImageRectInUIKit(imagePath string, index ...int) (x, y, width, height float64, err error) {
func (dExt *DriverExt) FindImageRectInUIKit(imagePath string, options ...DataOption) (x, y, width, height float64, err error) {
log.Fatal().Msg("opencv is not supported")
return
}

View File

@@ -111,7 +111,7 @@ func (dExt *DriverExt) FindAllImageRect(search string) (rects []image.Rectangle,
return
}
func (dExt *DriverExt) FindImageRectInUIKit(imagePath string, index ...int) (x, y, width, height float64, err error) {
func (dExt *DriverExt) FindImageRectInUIKit(imagePath string, options ...DataOption) (x, y, width, height float64, err error) {
var bufSource, bufSearch *bytes.Buffer
if bufSearch, err = getBufFromDisk(imagePath); err != nil {
return 0, 0, 0, 0, err

View File

@@ -12,7 +12,7 @@ func assertRelative(p float64) bool {
}
// SwipeRelative swipe from relative position [fromX, fromY] to relative position [toX, toY]
func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, identifier ...string) error {
func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, options ...DataOption) error {
width := dExt.windowSize.Width
height := dExt.windowSize.Height
@@ -27,44 +27,37 @@ func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, identifier
toX = float64(width) * toX
toY = float64(height) * toY
if len(identifier) > 0 && identifier[0] != "" {
option := WithCustomOption("log", map[string]interface{}{
"enable": true,
"data": identifier[0],
})
return dExt.Driver.SwipeFloat(fromX, fromY, toX, toY, option)
}
return dExt.Driver.SwipeFloat(fromX, fromY, toX, toY)
return dExt.Driver.SwipeFloat(fromX, fromY, toX, toY, options...)
}
func (dExt *DriverExt) SwipeTo(direction string, identifier ...string) (err error) {
func (dExt *DriverExt) SwipeTo(direction string, options ...DataOption) (err error) {
switch direction {
case "up":
return dExt.SwipeUp(identifier...)
return dExt.SwipeUp(options...)
case "down":
return dExt.SwipeDown(identifier...)
return dExt.SwipeDown(options...)
case "left":
return dExt.SwipeLeft(identifier...)
return dExt.SwipeLeft(options...)
case "right":
return dExt.SwipeRight(identifier...)
return dExt.SwipeRight(options...)
}
return fmt.Errorf("unexpected direction: %s", direction)
}
func (dExt *DriverExt) SwipeUp(identifier ...string) (err error) {
return dExt.SwipeRelative(0.5, 0.5, 0.5, 0.1, identifier...)
func (dExt *DriverExt) SwipeUp(options ...DataOption) (err error) {
return dExt.SwipeRelative(0.5, 0.5, 0.5, 0.1, options...)
}
func (dExt *DriverExt) SwipeDown(identifier ...string) (err error) {
return dExt.SwipeRelative(0.5, 0.5, 0.5, 0.9, identifier...)
func (dExt *DriverExt) SwipeDown(options ...DataOption) (err error) {
return dExt.SwipeRelative(0.5, 0.5, 0.5, 0.9, options...)
}
func (dExt *DriverExt) SwipeLeft(identifier ...string) (err error) {
return dExt.SwipeRelative(0.5, 0.5, 0.1, 0.5, identifier...)
func (dExt *DriverExt) SwipeLeft(options ...DataOption) (err error) {
return dExt.SwipeRelative(0.5, 0.5, 0.1, 0.5, options...)
}
func (dExt *DriverExt) SwipeRight(identifier ...string) (err error) {
return dExt.SwipeRelative(0.5, 0.5, 0.9, 0.5, identifier...)
func (dExt *DriverExt) SwipeRight(options ...DataOption) (err error) {
return dExt.SwipeRelative(0.5, 0.5, 0.9, 0.5, options...)
}
// FindCondition indicates the condition to find a UI element

View File

@@ -4,19 +4,12 @@ import (
"fmt"
)
func (dExt *DriverExt) TapAbsXY(x, y float64, identifier string) error {
func (dExt *DriverExt) TapAbsXY(x, y float64, options ...DataOption) error {
// tap on absolute coordinate [x, y]
if len(identifier) > 0 {
option := WithCustomOption("log", map[string]interface{}{
"enable": true,
"data": identifier,
})
return dExt.Driver.TapFloat(x, y, option)
}
return dExt.Driver.TapFloat(x, y)
return dExt.Driver.TapFloat(x, y, options...)
}
func (dExt *DriverExt) TapXY(x, y float64, identifier string) error {
func (dExt *DriverExt) TapXY(x, y float64, options ...DataOption) error {
// tap on [x, y] percent of window size
if x > 1 || y > 1 {
return fmt.Errorf("x, y percentage should be < 1, got x=%v, y=%v", x, y)
@@ -25,7 +18,7 @@ func (dExt *DriverExt) TapXY(x, y float64, identifier string) error {
x = x * float64(dExt.windowSize.Width)
y = y * float64(dExt.windowSize.Height)
return dExt.TapAbsXY(x, y, identifier)
return dExt.TapAbsXY(x, y, options...)
}
func (dExt *DriverExt) GetTextXY(ocrText string, options ...DataOption) (point PointF, err error) {
@@ -58,8 +51,8 @@ func (dExt *DriverExt) GetTextXYs(ocrText []string, options ...DataOption) (poin
return points, nil
}
func (dExt *DriverExt) GetImageXY(imagePath string, index ...int) (point PointF, err error) {
x, y, width, height, err := dExt.FindImageRectInUIKit(imagePath, index...)
func (dExt *DriverExt) GetImageXY(imagePath string, options ...DataOption) (point PointF, err error) {
x, y, width, height, err := dExt.FindImageRectInUIKit(imagePath, options...)
if err != nil {
return PointF{}, err
}
@@ -71,50 +64,69 @@ func (dExt *DriverExt) GetImageXY(imagePath string, index ...int) (point PointF,
return point, nil
}
func (dExt *DriverExt) TapByOCR(ocrText string, identifier string, ignoreNotFoundError bool, options ...DataOption) error {
func (dExt *DriverExt) TapByOCR(ocrText string, options ...DataOption) error {
data := map[string]interface{}{}
for _, option := range options {
option(data)
}
point, err := dExt.GetTextXY(ocrText, options...)
if err != nil {
if ignoreNotFoundError {
return nil
if d, ok := data["ignoreNotFoundError"]; ok {
if b, ok := d.(bool); b && ok {
return nil
}
}
return err
}
return dExt.TapAbsXY(point.X, point.Y, identifier)
return dExt.TapAbsXY(point.X, point.Y, options...)
}
func (dExt *DriverExt) TapByCV(imagePath string, identifier string, ignoreNotFoundError bool, index ...int) error {
point, err := dExt.GetImageXY(imagePath, index...)
func (dExt *DriverExt) TapByCV(imagePath string, options ...DataOption) error {
data := map[string]interface{}{}
for _, option := range options {
option(data)
}
point, err := dExt.GetImageXY(imagePath, options...)
if err != nil {
if ignoreNotFoundError {
return nil
if d, ok := data["ignoreNotFoundError"]; ok {
if b, ok := d.(bool); b && ok {
return nil
}
}
return err
}
return dExt.TapAbsXY(point.X, point.Y, identifier)
return dExt.TapAbsXY(point.X, point.Y, options...)
}
func (dExt *DriverExt) Tap(param string, identifier string, ignoreNotFoundError bool, index ...int) error {
return dExt.TapOffset(param, 0.5, 0.5, identifier, ignoreNotFoundError, index...)
func (dExt *DriverExt) Tap(param string, options ...DataOption) error {
return dExt.TapOffset(param, 0.5, 0.5, options...)
}
func (dExt *DriverExt) TapOffset(param string, xOffset, yOffset float64, identifier string, ignoreNotFoundError bool, index ...int) (err error) {
func (dExt *DriverExt) TapOffset(param string, xOffset, yOffset float64, options ...DataOption) (err error) {
// click on element, find by name attribute
ele, err := dExt.FindUIElement(param)
if err == nil {
return ele.Click()
}
x, y, width, height, err := dExt.FindUIRectInUIKit(param, index...)
data := map[string]interface{}{}
for _, option := range options {
option(data)
}
x, y, width, height, err := dExt.FindUIRectInUIKit(param, options...)
if err != nil {
if ignoreNotFoundError {
return nil
if d, ok := data["ignoreNotFoundError"]; ok {
if b, ok := d.(bool); b && ok {
return nil
}
}
return err
}
return dExt.TapAbsXY(x+width*xOffset, y+height*yOffset, identifier)
return dExt.TapAbsXY(x+width*xOffset, y+height*yOffset, options...)
}
func (dExt *DriverExt) DoubleTapXY(x, y float64) error {