mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-08 00:47:36 +08:00
change: FindScreenText return text rect
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0-beta-2503171436
|
v5.0.0-beta-2503171509
|
||||||
|
|||||||
+2
-5
@@ -86,13 +86,10 @@ func (t OCRText) Size() types.Size {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t OCRText) Center() PointF {
|
func (t OCRText) Center() PointF {
|
||||||
return getRectangleCenterPoint(t.Rect)
|
rect := t.Rect
|
||||||
}
|
|
||||||
|
|
||||||
func getRectangleCenterPoint(rect image.Rectangle) (point PointF) {
|
|
||||||
x, y := float64(rect.Min.X), float64(rect.Min.Y)
|
x, y := float64(rect.Min.X), float64(rect.Min.Y)
|
||||||
width, height := float64(rect.Dx()), float64(rect.Dy())
|
width, height := float64(rect.Dx()), float64(rect.Dy())
|
||||||
point = PointF{
|
point := PointF{
|
||||||
X: x + width*0.5,
|
X: x + width*0.5,
|
||||||
Y: y + height*0.5,
|
Y: y + height*0.5,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ func (dExt *XTDriver) GetScreenTexts(opts ...option.ActionOption) (ocrTexts ai.O
|
|||||||
return screenResult.Texts, nil
|
return screenResult.Texts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *XTDriver) FindScreenText(text string, opts ...option.ActionOption) (point ai.PointF, err error) {
|
func (dExt *XTDriver) FindScreenText(text string, opts ...option.ActionOption) (textRect ai.OCRText, err error) {
|
||||||
options := option.NewActionOptions(opts...)
|
options := option.NewActionOptions(opts...)
|
||||||
if options.ScreenShotFileName == "" {
|
if options.ScreenShotFileName == "" {
|
||||||
opts = append(opts, option.WithScreenShotFileName(fmt.Sprintf("find_screen_text_%s", text)))
|
opts = append(opts, option.WithScreenShotFileName(fmt.Sprintf("find_screen_text_%s", text)))
|
||||||
@@ -155,16 +155,15 @@ func (dExt *XTDriver) FindScreenText(text string, opts ...option.ActionOption) (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := ocrTexts.FindText(text, opts...)
|
textRect, err = ocrTexts.FindText(text, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Msgf("FindText failed: %s", err.Error())
|
log.Warn().Msgf("FindText failed: %s", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
point = result.Center()
|
|
||||||
|
|
||||||
log.Info().Str("text", text).
|
log.Info().Str("text", text).
|
||||||
Interface("point", point).Msgf("FindScreenText success")
|
Interface("textRect", textRect).Msgf("FindScreenText success")
|
||||||
return
|
return textRect, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *XTDriver) FindUIResult(opts ...option.ActionOption) (point ai.PointF, err error) {
|
func (dExt *XTDriver) FindUIResult(opts ...option.ActionOption) (point ai.PointF, err error) {
|
||||||
|
|||||||
@@ -12,13 +12,14 @@ func (dExt *XTDriver) TapByOCR(text string, opts ...option.ActionOption) error {
|
|||||||
opts = append(opts, option.WithScreenShotFileName(fmt.Sprintf("tap_by_ocr_%s", text)))
|
opts = append(opts, option.WithScreenShotFileName(fmt.Sprintf("tap_by_ocr_%s", text)))
|
||||||
}
|
}
|
||||||
|
|
||||||
point, err := dExt.FindScreenText(text, opts...)
|
textRect, err := dExt.FindScreenText(text, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if actionOptions.IgnoreNotFoundError {
|
if actionOptions.IgnoreNotFoundError {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
point := textRect.Center()
|
||||||
|
|
||||||
return dExt.TapAbsXY(point.X, point.Y, opts...)
|
return dExt.TapAbsXY(point.X, point.Y, opts...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ func TestDriverExt(t *testing.T) {
|
|||||||
driverExt.TapByOCR("推荐")
|
driverExt.TapByOCR("推荐")
|
||||||
texts, _ := driverExt.GetScreenTexts()
|
texts, _ := driverExt.GetScreenTexts()
|
||||||
t.Log(texts)
|
t.Log(texts)
|
||||||
point, _ := driverExt.FindScreenText("hello")
|
textRect, _ := driverExt.FindScreenText("hello")
|
||||||
t.Log(point)
|
t.Log(textRect)
|
||||||
|
|
||||||
err := driverExt.TapByCV(
|
err := driverExt.TapByCV(
|
||||||
option.WithScreenShotUITypes("deepseek_send"),
|
option.WithScreenShotUITypes("deepseek_send"),
|
||||||
@@ -98,13 +98,14 @@ func TestDriverExt_FindScreenText(t *testing.T) {
|
|||||||
func TestDriverExt_Seek(t *testing.T) {
|
func TestDriverExt_Seek(t *testing.T) {
|
||||||
driver := setupDriverExt(t)
|
driver := setupDriverExt(t)
|
||||||
|
|
||||||
point, err := driver.FindScreenText("首页")
|
textRect, err := driver.FindScreenText("首页")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
size, err := driver.WindowSize()
|
size, err := driver.WindowSize()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
width := size.Width
|
width := size.Width
|
||||||
|
|
||||||
|
point := textRect.Center()
|
||||||
y := point.Y - 40
|
y := point.Y - 40
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
err := driver.Swipe(0.5, 0.8, 0.5, 0.2)
|
err := driver.Swipe(0.5, 0.8, 0.5, 0.2)
|
||||||
@@ -180,4 +181,6 @@ func TestDriverExt_Action_Risk(t *testing.T) {
|
|||||||
err = driver.Swipe(0.5, 0.5, 0.5, 0.9,
|
err = driver.Swipe(0.5, 0.5, 0.5, 0.9,
|
||||||
option.WithSwipeOffset(-50, 50, -50, 50))
|
option.WithSwipeOffset(-50, 50, -50, 50))
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
err = driver.TapByOCR("首页", option.WithTapOffset(-10, 10))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user