Merge branch 'fix-swipe-to-tap' into 'master'

修复 tap offset 问题

See merge request iesqa/httprunner!115
This commit is contained in:
李隆
2025-07-02 12:52:33 +00:00
7 changed files with 29 additions and 27 deletions

View File

@@ -90,9 +90,11 @@
{ {
"method": "tap_ocr", "method": "tap_ocr",
"params": "推荐", "params": "推荐",
"options": { "identifier": "点击推荐",
"identifier": "点击推荐" "offset": [
} 0,
-1
]
}, },
{ {
"method": "sleep", "method": "sleep",

View File

@@ -1 +1 @@
v5.0.0-250701 v5.0.0-250702

View File

@@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
hrp "github.com/httprunner/httprunner/v5" hrp "github.com/httprunner/httprunner/v5"
"github.com/httprunner/httprunner/v5/uixt/option"
) )
func TestLoadTestCases(t *testing.T) { func TestLoadTestCases(t *testing.T) {
@@ -63,3 +64,17 @@ func TestLoadCase(t *testing.T) {
assert.Equal(t, tcJSON.Steps[1].StepName, tcYAML.Steps[1].StepName) assert.Equal(t, tcJSON.Steps[1].StepName, tcYAML.Steps[1].StepName)
assert.Equal(t, tcJSON.Steps[1].Request, tcJSON.Steps[1].Request) assert.Equal(t, tcJSON.Steps[1].Request, tcJSON.Steps[1].Request)
} }
func TestLoadCaseWithTapOffset(t *testing.T) {
// Load the android_swipe_tap_loadmore.json test case
testCasePath := "../examples/uitest/demo_ios_wda_log.json"
tc := &hrp.TestCaseDef{}
err := hrp.LoadFileObject(testCasePath, tc)
assert.Nil(t, err)
action := tc.Steps[3].IOS.Actions[0]
assert.Equal(t, option.ACTION_TapByOCR, action.Method)
assert.Equal(t, "推荐", action.Params)
assert.Equal(t, "点击推荐", action.ActionOptions.Identifier)
assert.Equal(t, []int{0, -1}, action.ActionOptions.ScreenFilterOptions.TapOffset)
}

View File

@@ -98,9 +98,6 @@ func (dExt *XTDriver) SwipeToTapTexts(texts []string, opts ...option.ActionOptio
log.Info().Strs("texts", texts).Msg("swipe to tap texts") log.Info().Strs("texts", texts).Msg("swipe to tap texts")
opts = append(opts, option.WithMatchOne(true), option.WithRegex(true)) opts = append(opts, option.WithMatchOne(true), option.WithRegex(true))
actionOptions := option.NewActionOptions(opts...)
actionOptions.Identifier = ""
optionsWithoutIdentifier := actionOptions.Options()
var point ai.PointF var point ai.PointF
findTexts := func(d *XTDriver) error { findTexts := func(d *XTDriver) error {
var err error var err error
@@ -116,7 +113,7 @@ func (dExt *XTDriver) SwipeToTapTexts(texts []string, opts ...option.ActionOptio
} }
points, err := screenResult.Texts.FindTexts(texts, points, err := screenResult.Texts.FindTexts(texts,
convertToAbsoluteScope(dExt.IDriver, optionsWithoutIdentifier...)...) convertToAbsoluteScope(dExt.IDriver, opts...)...)
if err != nil { if err != nil {
log.Error().Err(err).Strs("texts", texts).Msg("find texts failed") log.Error().Err(err).Strs("texts", texts).Msg("find texts failed")
return err return err
@@ -132,8 +129,8 @@ func (dExt *XTDriver) SwipeToTapTexts(texts []string, opts ...option.ActionOptio
return d.TapAbsXY(point.X, point.Y, opts...) return d.TapAbsXY(point.X, point.Y, opts...)
} }
findAction := prepareSwipeAction(dExt, nil, optionsWithoutIdentifier...) findAction := prepareSwipeAction(dExt, nil, opts...)
return dExt.LoopUntil(findAction, findTexts, foundTextAction, optionsWithoutIdentifier...) return dExt.LoopUntil(findAction, findTexts, foundTextAction, opts...)
} }
func (dExt *XTDriver) SwipeToTapApp(appName string, opts ...option.ActionOption) error { func (dExt *XTDriver) SwipeToTapApp(appName string, opts ...option.ActionOption) error {
@@ -160,7 +157,7 @@ func (dExt *XTDriver) SwipeToTapApp(appName string, opts ...option.ActionOption)
actionOptions := option.NewActionOptions(opts...) actionOptions := option.NewActionOptions(opts...)
// tap app icon above the text // tap app icon above the text
if len(actionOptions.TapOffset) == 0 { if len(actionOptions.TapOffset) == 0 {
opts = append(opts, option.WithTapOffset(0, -25)) opts = append(opts, option.WithTapOffset(0, -100))
} }
// set default swipe interval to 1 second // set default swipe interval to 1 second
if builtin.IsZeroFloat64(actionOptions.Interval) { if builtin.IsZeroFloat64(actionOptions.Interval) {

View File

@@ -9,9 +9,10 @@ import (
"testing" "testing"
"time" "time"
"github.com/httprunner/httprunner/v5/uixt/option"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/httprunner/httprunner/v5/uixt/option"
) )
func TestDriverExt_NewMethod1(t *testing.T) { func TestDriverExt_NewMethod1(t *testing.T) {
@@ -142,7 +143,7 @@ func TestDriverExt_prepareSwipeAction(t *testing.T) {
func TestDriverExt_SwipeToTapApp(t *testing.T) { func TestDriverExt_SwipeToTapApp(t *testing.T) {
driver := setupDriverExt(t) driver := setupDriverExt(t)
err := driver.SwipeToTapApp("抖音") err := driver.SwipeToTapApp("抖音", option.WithPreMarkOperation(true))
assert.Nil(t, err) assert.Nil(t, err)
} }

View File

@@ -319,19 +319,6 @@ func (t *ToolSwipeToTapApp) Implement() server.ToolHandlerFunc {
// Build action options from request structure // Build action options from request structure
opts := unifiedReq.Options() opts := unifiedReq.Options()
// Add boolean options
if unifiedReq.IgnoreNotFoundError {
opts = append(opts, option.WithIgnoreNotFoundError(true))
}
// Add numeric options
if unifiedReq.MaxRetryTimes > 0 {
opts = append(opts, option.WithMaxRetryTimes(unifiedReq.MaxRetryTimes))
}
if unifiedReq.Index > 0 {
opts = append(opts, option.WithIndex(unifiedReq.Index))
}
// Swipe to tap app action logic // Swipe to tap app action logic
err = driverExt.SwipeToTapApp(unifiedReq.AppName, opts...) err = driverExt.SwipeToTapApp(unifiedReq.AppName, opts...)
if err != nil { if err != nil {

View File

@@ -227,7 +227,7 @@ type ScreenFilterOptions struct {
AbsScope AbsScope `json:"abs_scope,omitempty" yaml:"abs_scope,omitempty"` AbsScope AbsScope `json:"abs_scope,omitempty" yaml:"abs_scope,omitempty"`
Regex bool `json:"regex,omitempty" yaml:"regex,omitempty"` // use regex to match text Regex bool `json:"regex,omitempty" yaml:"regex,omitempty"` // use regex to match text
TapOffset []int `json:"tap_offset,omitempty" yaml:"tap_offset,omitempty"` // tap with absolute point offset TapOffset []int `json:"offset,omitempty" yaml:"offset,omitempty"` // tap with absolute point offset
TapRandomRect bool `json:"tap_random_rect,omitempty" yaml:"tap_random_rect,omitempty"` // tap random point in text/image rectangle TapRandomRect bool `json:"tap_random_rect,omitempty" yaml:"tap_random_rect,omitempty"` // tap random point in text/image rectangle
SwipeOffset []int `json:"swipe_offset,omitempty" yaml:"swipe_offset,omitempty"` // swipe with direction offset SwipeOffset []int `json:"swipe_offset,omitempty" yaml:"swipe_offset,omitempty"` // swipe with direction offset
OffsetRandomRange []int `json:"offset_random_range,omitempty" yaml:"offset_random_range,omitempty"` // set random range [min, max] for tap/swipe points OffsetRandomRange []int `json:"offset_random_range,omitempty" yaml:"offset_random_range,omitempty"` // set random range [min, max] for tap/swipe points