mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-07 00:17:37 +08:00
change: update function optional parameters to DataOptions
This commit is contained in:
@@ -573,7 +573,7 @@ func (ud *uiaDriver) _swipe(startX, startY, endX, endY interface{}, options ...D
|
|||||||
}
|
}
|
||||||
|
|
||||||
// append options in post data for extra uiautomator configurations
|
// 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 {
|
for _, option := range options {
|
||||||
option(data)
|
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.
|
// 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
|
// `steps` is the number of move steps sent to the system
|
||||||
func (ud *uiaDriver) Swipe(fromX, fromY, toX, toY int, options ...DataOption) error {
|
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...)
|
return ud.SwipeFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ func (ue uiaElement) Swipe(fromX, fromY, toX, toY int) error {
|
|||||||
|
|
||||||
func (ue uiaElement) SwipeFloat(fromX, fromY, toX, toY float64) error {
|
func (ue uiaElement) SwipeFloat(fromX, fromY, toX, toY float64) error {
|
||||||
options := []DataOption{
|
options := []DataOption{
|
||||||
WithSteps(12),
|
WithStepsOption(12),
|
||||||
WithCustomOption("elementId", ue.id),
|
WithCustomOption("elementId", ue.id),
|
||||||
}
|
}
|
||||||
return ue.parent._swipe(fromX, fromY, toX, toY, options...)
|
return ue.parent._swipe(fromX, fromY, toX, toY, options...)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func TestIOSDemo(t *testing.T) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err = driverExt.TapAbsXY(points[1].X, points[1].Y, "")
|
err = driverExt.TapAbsXY(points[1].X, points[1].Y)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,5 +26,5 @@ func (dExt *DriverExt) DragOffsetFloat(pathname string, toX, toY, xOffset, yOffs
|
|||||||
fromY := y + height*yOffset
|
fromY := y + height*yOffset
|
||||||
|
|
||||||
return dExt.Driver.DragFloat(fromX, fromY, toX, toY,
|
return dExt.Driver.DragFloat(fromX, fromY, toX, toY,
|
||||||
WithPressDuration(pressForDuration[0]))
|
WithPressDurationOption(pressForDuration[0]))
|
||||||
}
|
}
|
||||||
|
|||||||
+36
-59
@@ -307,13 +307,13 @@ func (dExt *DriverExt) FindUIElement(param string) (ele WebElement, err error) {
|
|||||||
return dExt.Driver.FindElement(selector)
|
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
|
// click on text, using OCR
|
||||||
if !isPathExists(search) {
|
if !isPathExists(search) {
|
||||||
return dExt.FindTextByOCR(search, WithCustomOption("index", index))
|
return dExt.FindTextByOCR(search, options...)
|
||||||
}
|
}
|
||||||
// click on image, using opencv
|
// 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) {
|
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}
|
action.Scope = []float64{0, 0, 1, 1}
|
||||||
}
|
}
|
||||||
|
|
||||||
var options []DataOption
|
identifierOption := WithIdentifierOption(action.Identifier)
|
||||||
options = append(options,
|
indexOption := WithIndexOption(action.Index)
|
||||||
WithCustomOption("index", []int{action.Index}),
|
scopeOption := WithScopeOption(dExt.GetAbsScope(action.Scope[0], action.Scope[1], action.Scope[2], action.Scope[3]))
|
||||||
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),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
var point PointF
|
var point PointF
|
||||||
findApp := func(d *DriverExt) error {
|
findApp := func(d *DriverExt) error {
|
||||||
var err error
|
var err error
|
||||||
point, err = d.GetTextXY(appName, options...)
|
point, err = d.GetTextXY(appName, scopeOption, indexOption)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
foundAppAction := func(d *DriverExt) error {
|
foundAppAction := func(d *DriverExt) error {
|
||||||
// click app to launch
|
// 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
|
// go to home screen
|
||||||
@@ -430,26 +423,19 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
action.Scope = []float64{0, 0, 1, 1}
|
action.Scope = []float64{0, 0, 1, 1}
|
||||||
}
|
}
|
||||||
|
|
||||||
var options []DataOption
|
identifierOption := WithIdentifierOption(action.Identifier)
|
||||||
options = append(options,
|
indexOption := WithIndexOption(action.Index)
|
||||||
WithCustomOption("index", []int{action.Index}),
|
scopeOption := WithScopeOption(dExt.GetAbsScope(action.Scope[0], action.Scope[1], action.Scope[2], action.Scope[3]))
|
||||||
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),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
var point PointF
|
var point PointF
|
||||||
findText := func(d *DriverExt) error {
|
findText := func(d *DriverExt) error {
|
||||||
var err error
|
var err error
|
||||||
point, err = d.GetTextXY(text, options...)
|
point, err = d.GetTextXY(text, indexOption, scopeOption)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
foundTextAction := func(d *DriverExt) error {
|
foundTextAction := func(d *DriverExt) error {
|
||||||
// tap text
|
// tap text
|
||||||
return d.TapAbsXY(point.X, point.Y, action.Identifier)
|
return d.TapAbsXY(point.X, point.Y, identifierOption)
|
||||||
}
|
}
|
||||||
|
|
||||||
// default to retry 10 times
|
// default to retry 10 times
|
||||||
@@ -478,20 +464,12 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
action.Scope = []float64{0, 0, 1, 1}
|
action.Scope = []float64{0, 0, 1, 1}
|
||||||
}
|
}
|
||||||
|
|
||||||
var options []DataOption
|
scopeOption := WithScopeOption(dExt.GetAbsScope(action.Scope[0], action.Scope[1], action.Scope[2], action.Scope[3]))
|
||||||
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),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
var point PointF
|
var point PointF
|
||||||
findText := func(d *DriverExt) error {
|
findText := func(d *DriverExt) error {
|
||||||
var err error
|
var err error
|
||||||
points, err := d.GetTextXYs(texts, options...)
|
points, err := d.GetTextXYs(texts, scopeOption)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -504,7 +482,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
}
|
}
|
||||||
foundTextAction := func(d *DriverExt) error {
|
foundTextAction := func(d *DriverExt) error {
|
||||||
// tap text
|
// 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
|
// default to retry 10 times
|
||||||
@@ -542,7 +520,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
}
|
}
|
||||||
x, _ := location[0].(float64)
|
x, _ := location[0].(float64)
|
||||||
y, _ := location[1].(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)
|
return fmt.Errorf("invalid %s params: %v", ACTION_TapXY, action.Params)
|
||||||
case ACTION_TapAbsXY:
|
case ACTION_TapAbsXY:
|
||||||
@@ -553,12 +531,12 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
}
|
}
|
||||||
x, _ := location[0].(float64)
|
x, _ := location[0].(float64)
|
||||||
y, _ := location[1].(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)
|
return fmt.Errorf("invalid %s params: %v", ACTION_TapAbsXY, action.Params)
|
||||||
case ACTION_Tap:
|
case ACTION_Tap:
|
||||||
if param, ok := action.Params.(string); ok {
|
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)
|
return fmt.Errorf("invalid %s params: %v", ACTION_Tap, action.Params)
|
||||||
case ACTION_TapByOCR:
|
case ACTION_TapByOCR:
|
||||||
@@ -567,22 +545,16 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
action.Scope = []float64{0, 0, 1, 1}
|
action.Scope = []float64{0, 0, 1, 1}
|
||||||
}
|
}
|
||||||
|
|
||||||
var options []DataOption
|
indexOption := WithIndexOption(action.Index)
|
||||||
options = append(options,
|
scopeOption := WithScopeOption(dExt.GetAbsScope(action.Scope[0], action.Scope[1], action.Scope[2], action.Scope[3]))
|
||||||
WithCustomOption("index", []int{action.Index}),
|
identifierOption := WithIdentifierOption(action.Identifier)
|
||||||
WithCustomOption("scope", []int{
|
IgnoreNotFoundErrorOption := WithIgnoreNotFoundErrorOption(action.IgnoreNotFoundError)
|
||||||
int(action.Scope[0] * float64(dExt.windowSize.Width) * dExt.scale),
|
return dExt.TapByOCR(ocrText, identifierOption, IgnoreNotFoundErrorOption, indexOption, scopeOption)
|
||||||
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...)
|
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", ACTION_TapByOCR, action.Params)
|
return fmt.Errorf("invalid %s params: %v", ACTION_TapByOCR, action.Params)
|
||||||
case ACTION_TapByCV:
|
case ACTION_TapByCV:
|
||||||
if imagePath, ok := action.Params.(string); ok {
|
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)
|
return fmt.Errorf("invalid %s params: %v", ACTION_TapByCV, action.Params)
|
||||||
case ACTION_DoubleTapXY:
|
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)
|
return fmt.Errorf("invalid %s params: %v", ACTION_DoubleTap, action.Params)
|
||||||
case ACTION_Swipe:
|
case ACTION_Swipe:
|
||||||
|
identifierOption := WithIdentifierOption(action.Identifier)
|
||||||
if positions, ok := action.Params.([]interface{}); ok {
|
if positions, ok := action.Params.([]interface{}); ok {
|
||||||
// relative fromX, fromY, toX, toY of window size: [0.5, 0.9, 0.5, 0.1]
|
// relative fromX, fromY, toX, toY of window size: [0.5, 0.9, 0.5, 0.1]
|
||||||
if len(positions) != 4 {
|
if len(positions) != 4 {
|
||||||
@@ -611,10 +584,10 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
fromY, _ := positions[1].(float64)
|
fromY, _ := positions[1].(float64)
|
||||||
toX, _ := positions[2].(float64)
|
toX, _ := positions[2].(float64)
|
||||||
toY, _ := positions[3].(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 {
|
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)
|
return fmt.Errorf("invalid %s params: %v", ACTION_Swipe, action.Params)
|
||||||
case ACTION_Input:
|
case ACTION_Input:
|
||||||
@@ -633,10 +606,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
options = append(options, WithCustomOption("description", action.Description))
|
options = append(options, WithCustomOption("description", action.Description))
|
||||||
}
|
}
|
||||||
if action.Identifier != "" {
|
if action.Identifier != "" {
|
||||||
options = append(options, WithCustomOption("log", map[string]interface{}{
|
options = append(options, WithIdentifierOption(action.Identifier))
|
||||||
"enable": true,
|
|
||||||
"data": action.Identifier,
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
return dExt.Driver.Input(param, options...)
|
return dExt.Driver.Input(param, options...)
|
||||||
case CtlSleep:
|
case CtlSleep:
|
||||||
@@ -671,6 +641,13 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
return nil
|
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 {
|
func (dExt *DriverExt) DoValidation(check, assert, expected string, message ...string) bool {
|
||||||
var exists bool
|
var exists bool
|
||||||
if assert == AssertionExists {
|
if assert == AssertionExists {
|
||||||
|
|||||||
@@ -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{}) {
|
return func(data map[string]interface{}) {
|
||||||
data["duration"] = duraion
|
data["duration"] = duraion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithSteps(steps int) DataOption {
|
func WithStepsOption(steps int) DataOption {
|
||||||
return func(data map[string]interface{}) {
|
return func(data map[string]interface{}) {
|
||||||
data["steps"] = steps
|
data["steps"] = steps
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithFrequency(frequency int) DataOption {
|
func WithFrequencyOption(frequency int) DataOption {
|
||||||
return func(data map[string]interface{}) {
|
return func(data map[string]interface{}) {
|
||||||
data["frequency"] = frequency
|
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
|
// current implemeted device: IOSDevice, AndroidDevice
|
||||||
type Device interface {
|
type Device interface {
|
||||||
UUID() string
|
UUID() string
|
||||||
@@ -905,7 +935,7 @@ type WebDriver interface {
|
|||||||
TouchAndHoldFloat(x, y float64, second ...float64) error
|
TouchAndHoldFloat(x, y float64, second ...float64) error
|
||||||
|
|
||||||
// Drag Initiates a press-and-hold gesture at the coordinate, then drags to another coordinate.
|
// 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
|
Drag(fromX, fromY, toX, toY int, options ...DataOption) error
|
||||||
DragFloat(fromX, fromY, toX, toY float64, options ...DataOption) error
|
DragFloat(fromX, fromY, toX, toY float64, options ...DataOption) error
|
||||||
|
|
||||||
|
|||||||
@@ -434,7 +434,7 @@ func (wd *wdaDriver) DragFloat(fromX, fromY, toX, toY float64, options ...DataOp
|
|||||||
}
|
}
|
||||||
|
|
||||||
// append options in post data for extra WDA configurations
|
// 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 {
|
for _, option := range options {
|
||||||
option(data)
|
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 {
|
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...)
|
return wd.SwipeFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wd *wdaDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...DataOption) error {
|
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...)
|
return wd.DragFloat(fromX, fromY, toX, toY, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -443,7 +443,7 @@ func Test_remoteWD_TouchAndHold(t *testing.T) {
|
|||||||
func Test_remoteWD_Drag(t *testing.T) {
|
func Test_remoteWD_Drag(t *testing.T) {
|
||||||
setup(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)
|
err := driver.Swipe(200, 300, 200, 500)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
+12
-25
@@ -117,23 +117,14 @@ func (s *veDEMOCRService) FindText(text string, imageBuf []byte, options ...Data
|
|||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := data["index"]; !ok {
|
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 := data["scope"]; !ok {
|
||||||
if !ok || len(index) == 0 {
|
|
||||||
index = []int{0}
|
|
||||||
}
|
|
||||||
|
|
||||||
_, ok = data["scope"]
|
|
||||||
if !ok {
|
|
||||||
data["scope"] = []int{0, 0, math.MaxInt64, math.MaxInt64} // scope not specified
|
data["scope"] = []int{0, 0, math.MaxInt64, math.MaxInt64} // scope not specified
|
||||||
}
|
}
|
||||||
|
scope, _ := data["scope"].([]int)
|
||||||
scope, ok := data["scope"].([]int)
|
|
||||||
if !ok || len(scope) != 4 {
|
|
||||||
scope = []int{0, 0, math.MaxInt64, math.MaxInt64}
|
|
||||||
}
|
|
||||||
|
|
||||||
ocrResults, err := s.getOCRResult(imageBuf)
|
ocrResults, err := s.getOCRResult(imageBuf)
|
||||||
if err != nil {
|
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
|
// match exactly, and not specify index, return the first one
|
||||||
if index[0] == 0 {
|
if index == 0 {
|
||||||
return rect, nil
|
return rect, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,7 +174,7 @@ func (s *veDEMOCRService) FindText(text string, imageBuf []byte, options ...Data
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get index
|
// get index
|
||||||
idx := index[0]
|
idx := index
|
||||||
if idx > 0 {
|
if idx > 0 {
|
||||||
// NOTICE: index start from 1
|
// NOTICE: index start from 1
|
||||||
idx = idx - 1
|
idx = idx - 1
|
||||||
@@ -212,19 +203,15 @@ func (s *veDEMOCRService) FindTexts(texts []string, imageBuf []byte, options ...
|
|||||||
option(data)
|
option(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ok := data["scope"]
|
if _, ok := data["scope"]; !ok {
|
||||||
if !ok {
|
|
||||||
data["scope"] = []int{0, 0, math.MaxInt64, math.MaxInt64} // scope not specified
|
data["scope"] = []int{0, 0, math.MaxInt64, math.MaxInt64} // scope not specified
|
||||||
}
|
}
|
||||||
|
scope, _ := data["scope"].([]int)
|
||||||
scope, ok := data["scope"].([]int)
|
|
||||||
if !ok || len(scope) != 4 {
|
|
||||||
scope = []int{0, 0, math.MaxInt64, math.MaxInt64}
|
|
||||||
}
|
|
||||||
|
|
||||||
var success bool
|
var success bool
|
||||||
var rect image.Rectangle
|
var rect image.Rectangle
|
||||||
var ocrTexts []string
|
ocrTexts := map[string]bool{}
|
||||||
|
|
||||||
for _, text := range texts {
|
for _, text := range texts {
|
||||||
var found bool
|
var found bool
|
||||||
for _, ocrResult := range ocrResults {
|
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] {
|
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)
|
ocrTexts[ocrResult.Text] = true
|
||||||
|
|
||||||
// not contains text
|
// not contains text
|
||||||
if !strings.Contains(ocrResult.Text, text) {
|
if !strings.Contains(ocrResult.Text, text) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func (dExt *DriverExt) FindAllImageRect(search string) (rects []image.Rectangle,
|
|||||||
return
|
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")
|
log.Fatal().Msg("opencv is not supported")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ func (dExt *DriverExt) FindAllImageRect(search string) (rects []image.Rectangle,
|
|||||||
return
|
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
|
var bufSource, bufSearch *bytes.Buffer
|
||||||
if bufSearch, err = getBufFromDisk(imagePath); err != nil {
|
if bufSearch, err = getBufFromDisk(imagePath); err != nil {
|
||||||
return 0, 0, 0, 0, err
|
return 0, 0, 0, 0, err
|
||||||
|
|||||||
+15
-22
@@ -12,7 +12,7 @@ func assertRelative(p float64) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SwipeRelative swipe from relative position [fromX, fromY] to relative position [toX, toY]
|
// 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
|
width := dExt.windowSize.Width
|
||||||
height := dExt.windowSize.Height
|
height := dExt.windowSize.Height
|
||||||
|
|
||||||
@@ -27,44 +27,37 @@ func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, identifier
|
|||||||
toX = float64(width) * toX
|
toX = float64(width) * toX
|
||||||
toY = float64(height) * toY
|
toY = float64(height) * toY
|
||||||
|
|
||||||
if len(identifier) > 0 && identifier[0] != "" {
|
return dExt.Driver.SwipeFloat(fromX, fromY, toX, toY, options...)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeTo(direction string, identifier ...string) (err error) {
|
func (dExt *DriverExt) SwipeTo(direction string, options ...DataOption) (err error) {
|
||||||
switch direction {
|
switch direction {
|
||||||
case "up":
|
case "up":
|
||||||
return dExt.SwipeUp(identifier...)
|
return dExt.SwipeUp(options...)
|
||||||
case "down":
|
case "down":
|
||||||
return dExt.SwipeDown(identifier...)
|
return dExt.SwipeDown(options...)
|
||||||
case "left":
|
case "left":
|
||||||
return dExt.SwipeLeft(identifier...)
|
return dExt.SwipeLeft(options...)
|
||||||
case "right":
|
case "right":
|
||||||
return dExt.SwipeRight(identifier...)
|
return dExt.SwipeRight(options...)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("unexpected direction: %s", direction)
|
return fmt.Errorf("unexpected direction: %s", direction)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeUp(identifier ...string) (err error) {
|
func (dExt *DriverExt) SwipeUp(options ...DataOption) (err error) {
|
||||||
return dExt.SwipeRelative(0.5, 0.5, 0.5, 0.1, identifier...)
|
return dExt.SwipeRelative(0.5, 0.5, 0.5, 0.1, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeDown(identifier ...string) (err error) {
|
func (dExt *DriverExt) SwipeDown(options ...DataOption) (err error) {
|
||||||
return dExt.SwipeRelative(0.5, 0.5, 0.5, 0.9, identifier...)
|
return dExt.SwipeRelative(0.5, 0.5, 0.5, 0.9, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeLeft(identifier ...string) (err error) {
|
func (dExt *DriverExt) SwipeLeft(options ...DataOption) (err error) {
|
||||||
return dExt.SwipeRelative(0.5, 0.5, 0.1, 0.5, identifier...)
|
return dExt.SwipeRelative(0.5, 0.5, 0.1, 0.5, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeRight(identifier ...string) (err error) {
|
func (dExt *DriverExt) SwipeRight(options ...DataOption) (err error) {
|
||||||
return dExt.SwipeRelative(0.5, 0.5, 0.9, 0.5, identifier...)
|
return dExt.SwipeRelative(0.5, 0.5, 0.9, 0.5, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindCondition indicates the condition to find a UI element
|
// FindCondition indicates the condition to find a UI element
|
||||||
|
|||||||
+38
-26
@@ -4,19 +4,12 @@ import (
|
|||||||
"fmt"
|
"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]
|
// tap on absolute coordinate [x, y]
|
||||||
if len(identifier) > 0 {
|
return dExt.Driver.TapFloat(x, y, options...)
|
||||||
option := WithCustomOption("log", map[string]interface{}{
|
|
||||||
"enable": true,
|
|
||||||
"data": identifier,
|
|
||||||
})
|
|
||||||
return dExt.Driver.TapFloat(x, y, option)
|
|
||||||
}
|
|
||||||
return dExt.Driver.TapFloat(x, y)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
// tap on [x, y] percent of window size
|
||||||
if x > 1 || y > 1 {
|
if x > 1 || y > 1 {
|
||||||
return fmt.Errorf("x, y percentage should be < 1, got x=%v, y=%v", x, y)
|
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)
|
x = x * float64(dExt.windowSize.Width)
|
||||||
y = y * float64(dExt.windowSize.Height)
|
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) {
|
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
|
return points, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) GetImageXY(imagePath string, index ...int) (point PointF, err error) {
|
func (dExt *DriverExt) GetImageXY(imagePath string, options ...DataOption) (point PointF, err error) {
|
||||||
x, y, width, height, err := dExt.FindImageRectInUIKit(imagePath, index...)
|
x, y, width, height, err := dExt.FindImageRectInUIKit(imagePath, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return PointF{}, err
|
return PointF{}, err
|
||||||
}
|
}
|
||||||
@@ -71,50 +64,69 @@ func (dExt *DriverExt) GetImageXY(imagePath string, index ...int) (point PointF,
|
|||||||
return point, nil
|
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...)
|
point, err := dExt.GetTextXY(ocrText, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if ignoreNotFoundError {
|
if d, ok := data["ignoreNotFoundError"]; ok {
|
||||||
|
if b, ok := d.(bool); b && ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return err
|
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 {
|
func (dExt *DriverExt) TapByCV(imagePath string, options ...DataOption) error {
|
||||||
point, err := dExt.GetImageXY(imagePath, index...)
|
data := map[string]interface{}{}
|
||||||
|
for _, option := range options {
|
||||||
|
option(data)
|
||||||
|
}
|
||||||
|
point, err := dExt.GetImageXY(imagePath, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if ignoreNotFoundError {
|
if d, ok := data["ignoreNotFoundError"]; ok {
|
||||||
|
if b, ok := d.(bool); b && ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return err
|
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 {
|
func (dExt *DriverExt) Tap(param string, options ...DataOption) error {
|
||||||
return dExt.TapOffset(param, 0.5, 0.5, identifier, ignoreNotFoundError, index...)
|
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
|
// click on element, find by name attribute
|
||||||
ele, err := dExt.FindUIElement(param)
|
ele, err := dExt.FindUIElement(param)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return ele.Click()
|
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 err != nil {
|
||||||
if ignoreNotFoundError {
|
if d, ok := data["ignoreNotFoundError"]; ok {
|
||||||
|
if b, ok := d.(bool); b && ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return err
|
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 {
|
func (dExt *DriverExt) DoubleTapXY(x, y float64) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user