mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 19:39:44 +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)
|
||||
case ACTION_SwipeToTapApp:
|
||||
if appName, ok := action.Params.(string); ok {
|
||||
var x, y, width, height float64
|
||||
var point PointF
|
||||
findApp := func(d *DriverExt) error {
|
||||
var err error
|
||||
x, y, width, height, err = d.FindTextByOCR(appName, action.Index)
|
||||
point, err = d.GetTextCoordinate(appName, action.Index)
|
||||
return err
|
||||
}
|
||||
foundAppAction := func(d *DriverExt) error {
|
||||
// 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
|
||||
@@ -346,15 +346,15 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
||||
ACTION_SwipeToTapApp, action.Params)
|
||||
case ACTION_SwipeToTapText:
|
||||
if text, ok := action.Params.(string); ok {
|
||||
var x, y, width, height float64
|
||||
var point PointF
|
||||
findText := func(d *DriverExt) error {
|
||||
var err error
|
||||
x, y, width, height, err = d.FindTextByOCR(text)
|
||||
point, err = d.GetTextCoordinate(text, action.Index)
|
||||
return err
|
||||
}
|
||||
foundTextAction := func(d *DriverExt) error {
|
||||
// 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
|
||||
|
||||
@@ -8,15 +8,15 @@ func TestSwipeUntil(t *testing.T) {
|
||||
driverExt, err := InitWDAClient(nil)
|
||||
checkErr(t, err)
|
||||
|
||||
var x, y, width, height float64
|
||||
var point PointF
|
||||
findApp := func(d *DriverExt) error {
|
||||
var err error
|
||||
x, y, width, height, err = d.FindTextByOCR("抖音")
|
||||
point, err = d.GetTextCoordinate("抖音")
|
||||
return err
|
||||
}
|
||||
foundAppAction := func(d *DriverExt) error {
|
||||
// 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()
|
||||
@@ -32,12 +32,12 @@ func TestSwipeUntil(t *testing.T) {
|
||||
|
||||
findLive := func(d *DriverExt) error {
|
||||
var err error
|
||||
x, y, width, height, err = d.FindTextByOCR("点击进入直播间")
|
||||
point, err = d.GetTextCoordinate("点击进入直播间")
|
||||
return err
|
||||
}
|
||||
foundLiveAction := func(d *DriverExt) error {
|
||||
// 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
|
||||
|
||||
@@ -27,8 +27,21 @@ func (dExt *DriverExt) TapXY(x, y float64, identifier string) error {
|
||||
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...)
|
||||
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 ignoreNotFoundError {
|
||||
return nil
|
||||
@@ -36,7 +49,7 @@ func (dExt *DriverExt) TapByOCR(ocrText string, identifier string, ignoreNotFoun
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user