mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-08 18:51:49 +08:00
fix: swipe to tap with identifier
This commit is contained in:
@@ -314,15 +314,15 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
AppLaunchUnattached, action.Params)
|
AppLaunchUnattached, action.Params)
|
||||||
case ACTION_SwipeToTapApp:
|
case ACTION_SwipeToTapApp:
|
||||||
if appName, ok := action.Params.(string); ok {
|
if appName, ok := action.Params.(string); ok {
|
||||||
var x, y, width, height float64
|
var point PointF
|
||||||
findApp := func(d *DriverExt) error {
|
findApp := func(d *DriverExt) error {
|
||||||
var err error
|
var err error
|
||||||
x, y, width, height, err = d.FindTextByOCR(appName, action.Index)
|
point, err = d.GetTextCoordinate(appName, action.Index)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
foundAppAction := func(d *DriverExt) error {
|
foundAppAction := func(d *DriverExt) error {
|
||||||
// click app to launch
|
// click app to launch
|
||||||
return d.Driver.TapFloat(x+width*0.5, y+height*0.5-20)
|
return d.tapFloat(point.X, point.Y-20, action.Identifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
// go to home screen
|
// go to home screen
|
||||||
@@ -346,15 +346,15 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
ACTION_SwipeToTapApp, action.Params)
|
ACTION_SwipeToTapApp, action.Params)
|
||||||
case ACTION_SwipeToTapText:
|
case ACTION_SwipeToTapText:
|
||||||
if text, ok := action.Params.(string); ok {
|
if text, ok := action.Params.(string); ok {
|
||||||
var x, y, width, height float64
|
var point PointF
|
||||||
findText := func(d *DriverExt) error {
|
findText := func(d *DriverExt) error {
|
||||||
var err error
|
var err error
|
||||||
x, y, width, height, err = d.FindTextByOCR(text)
|
point, err = d.GetTextCoordinate(text, action.Index)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
foundTextAction := func(d *DriverExt) error {
|
foundTextAction := func(d *DriverExt) error {
|
||||||
// tap text
|
// tap text
|
||||||
return d.Driver.TapFloat(x+width*0.5, y+height*0.5)
|
return d.tapFloat(point.X, point.Y, action.Identifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
// default to retry 10 times
|
// default to retry 10 times
|
||||||
|
|||||||
@@ -8,15 +8,15 @@ func TestSwipeUntil(t *testing.T) {
|
|||||||
driverExt, err := InitWDAClient(nil)
|
driverExt, err := InitWDAClient(nil)
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
|
|
||||||
var x, y, width, height float64
|
var point PointF
|
||||||
findApp := func(d *DriverExt) error {
|
findApp := func(d *DriverExt) error {
|
||||||
var err error
|
var err error
|
||||||
x, y, width, height, err = d.FindTextByOCR("抖音")
|
point, err = d.GetTextCoordinate("抖音")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
foundAppAction := func(d *DriverExt) error {
|
foundAppAction := func(d *DriverExt) error {
|
||||||
// click app, launch douyin
|
// click app, launch douyin
|
||||||
return d.Driver.TapFloat(x+width*0.5, y+height*0.5-20)
|
return d.tapFloat(point.X, point.Y, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
driverExt.Driver.Homescreen()
|
driverExt.Driver.Homescreen()
|
||||||
@@ -32,12 +32,12 @@ func TestSwipeUntil(t *testing.T) {
|
|||||||
|
|
||||||
findLive := func(d *DriverExt) error {
|
findLive := func(d *DriverExt) error {
|
||||||
var err error
|
var err error
|
||||||
x, y, width, height, err = d.FindTextByOCR("点击进入直播间")
|
point, err = d.GetTextCoordinate("点击进入直播间")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
foundLiveAction := func(d *DriverExt) error {
|
foundLiveAction := func(d *DriverExt) error {
|
||||||
// enter live room
|
// enter live room
|
||||||
return d.Driver.TapFloat(x+width*0.5, y+height*0.5)
|
return d.tapFloat(point.X, point.Y, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// swipe until live room found
|
// swipe until live room found
|
||||||
|
|||||||
@@ -27,8 +27,21 @@ func (dExt *DriverExt) TapXY(x, y float64, identifier string) error {
|
|||||||
return dExt.tapFloat(x, y, identifier)
|
return dExt.tapFloat(x, y, identifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) TapByOCR(ocrText string, identifier string, ignoreNotFoundError bool, index ...int) error {
|
func (dExt *DriverExt) GetTextCoordinate(ocrText string, index ...int) (point PointF, err error) {
|
||||||
x, y, width, height, err := dExt.FindTextByOCR(ocrText, index...)
|
x, y, width, height, err := dExt.FindTextByOCR(ocrText, index...)
|
||||||
|
if err != nil {
|
||||||
|
return PointF{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
point = PointF{
|
||||||
|
X: x + width*0.5,
|
||||||
|
Y: y + height*0.5,
|
||||||
|
}
|
||||||
|
return point, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dExt *DriverExt) TapByOCR(ocrText string, identifier string, ignoreNotFoundError bool, index ...int) error {
|
||||||
|
point, err := dExt.GetTextCoordinate(ocrText, index...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if ignoreNotFoundError {
|
if ignoreNotFoundError {
|
||||||
return nil
|
return nil
|
||||||
@@ -36,7 +49,7 @@ func (dExt *DriverExt) TapByOCR(ocrText string, identifier string, ignoreNotFoun
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return dExt.tapFloat(x+width*0.5, y+height*0.5, identifier)
|
return dExt.tapFloat(point.X, point.Y, identifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) TapByCV(imagePath string, identifier string, ignoreNotFoundError bool, index ...int) error {
|
func (dExt *DriverExt) TapByCV(imagePath string, identifier string, ignoreNotFoundError bool, index ...int) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user