Merge branch 'fix-filter-scope' into 'v5'

fix: convert abs scope for FindScreenText

See merge request iesqa/httprunner!78
This commit is contained in:
李隆 2025-03-25 06:24:25 +00:00
commit 6d2a4276e8
3 changed files with 21 additions and 2 deletions

View File

@ -1 +1 @@
v5.0.0-beta-2503172040
v5.0.0-beta-2503251404

View File

@ -150,6 +150,25 @@ func (dExt *XTDriver) FindScreenText(text string, opts ...option.ActionOption) (
if options.ScreenShotFileName == "" {
opts = append(opts, option.WithScreenShotFileName(fmt.Sprintf("find_screen_text_%s", text)))
}
// convert relative scope to absolute scope
if options.AbsScope == nil && len(options.Scope) == 4 {
windowSize, err := dExt.WindowSize()
if err != nil {
return ai.OCRText{}, err
}
absScope := option.AbsScope{
int(options.Scope[0] * float64(windowSize.Width)),
int(options.Scope[1] * float64(windowSize.Height)),
int(options.Scope[2] * float64(windowSize.Width)),
int(options.Scope[3] * float64(windowSize.Height)),
}
opts = append(opts, option.WithAbsScope(
absScope[0], absScope[1], absScope[2], absScope[3]))
log.Info().Interface("scope", options.Scope).
Interface("absScope", absScope).Msg("convert to abs scope")
}
ocrTexts, err := dExt.GetScreenTexts(opts...)
if err != nil {
return

View File

@ -119,7 +119,7 @@ func TestDriverExt_Seek(t *testing.T) {
func TestDriverExt_TapByOCR(t *testing.T) {
driver := setupDriverExt(t)
err := driver.TapByOCR("天气")
err := driver.TapByOCR("天气", option.WithScope(0, 0.7, 0.3, 1))
assert.Nil(t, err)
}