mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
feat: TapByCV WithTapRandomRect
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0-beta-2503171757
|
v5.0.0-beta-2503171806
|
||||||
|
|||||||
@@ -249,6 +249,15 @@ func (box Box) Center() PointF {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (box Box) RandomPoint() PointF {
|
||||||
|
width, height := float64(box.Width), float64(box.Height)
|
||||||
|
point := PointF{
|
||||||
|
X: box.Point.X + width*rand.Float64(),
|
||||||
|
Y: box.Point.Y + height*rand.Float64(),
|
||||||
|
}
|
||||||
|
return point
|
||||||
|
}
|
||||||
|
|
||||||
type UIResults []UIResult
|
type UIResults []UIResult
|
||||||
|
|
||||||
func (u UIResults) FilterScope(scope option.AbsScope) (results UIResults) {
|
func (u UIResults) FilterScope(scope option.AbsScope) (results UIResults) {
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ func (dExt *XTDriver) FindScreenText(text string, opts ...option.ActionOption) (
|
|||||||
return textRect, nil
|
return textRect, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *XTDriver) FindUIResult(opts ...option.ActionOption) (point ai.PointF, err error) {
|
func (dExt *XTDriver) FindUIResult(opts ...option.ActionOption) (uiResult ai.UIResult, err error) {
|
||||||
options := option.NewActionOptions(opts...)
|
options := option.NewActionOptions(opts...)
|
||||||
if options.ScreenShotFileName == "" {
|
if options.ScreenShotFileName == "" {
|
||||||
opts = append(opts, option.WithScreenShotFileName(
|
opts = append(opts, option.WithScreenShotFileName(
|
||||||
@@ -182,11 +182,10 @@ func (dExt *XTDriver) FindUIResult(opts ...option.ActionOption) (point ai.PointF
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
uiResult, err := uiResults.GetUIResult(opts...)
|
uiResult, err = uiResults.GetUIResult(opts...)
|
||||||
point = uiResult.Center()
|
|
||||||
|
|
||||||
log.Info().Interface("text", options.ScreenShotWithUITypes).
|
log.Info().Interface("text", options.ScreenShotWithUITypes).
|
||||||
Interface("point", point).Msg("FindUIResult success")
|
Interface("uiResult", uiResult).Msg("FindUIResult success")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-3
@@ -32,15 +32,22 @@ func (dExt *XTDriver) TapByOCR(text string, opts ...option.ActionOption) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *XTDriver) TapByCV(opts ...option.ActionOption) error {
|
func (dExt *XTDriver) TapByCV(opts ...option.ActionOption) error {
|
||||||
options := option.NewActionOptions(opts...)
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
|
|
||||||
point, err := dExt.FindUIResult(opts...)
|
uiResult, err := dExt.FindUIResult(opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if options.IgnoreNotFoundError {
|
if actionOptions.IgnoreNotFoundError {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var point ai.PointF
|
||||||
|
if actionOptions.TapRandomRect {
|
||||||
|
point = uiResult.RandomPoint()
|
||||||
|
} else {
|
||||||
|
point = uiResult.Center()
|
||||||
|
}
|
||||||
|
|
||||||
return dExt.TapAbsXY(point.X, point.Y, opts...)
|
return dExt.TapAbsXY(point.X, point.Y, opts...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,4 +193,10 @@ func TestDriverExt_Action_Risk(t *testing.T) {
|
|||||||
|
|
||||||
// tap random point in ocr text rect
|
// tap random point in ocr text rect
|
||||||
err = driver.TapByOCR("首页", option.WithTapRandomRect(true))
|
err = driver.TapByOCR("首页", option.WithTapRandomRect(true))
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
err = driver.TapByCV(
|
||||||
|
option.WithScreenShotUITypes("deepseek_send"),
|
||||||
|
option.WithTapRandomRect(true))
|
||||||
|
assert.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user