mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
feat: add WithSwipeOffset to set offset for swipe start/end point
This commit is contained in:
@@ -9,6 +9,8 @@ plugin related:
|
|||||||
- feat: add hrp executable directory for searching plugin
|
- feat: add hrp executable directory for searching plugin
|
||||||
- feat: init device driver with plugin options, `WithDriverCapabilities` and `WithDriverPlugin`
|
- feat: init device driver with plugin options, `WithDriverCapabilities` and `WithDriverPlugin`
|
||||||
- feat: support printing stderr output in myexec.RunCommand
|
- feat: support printing stderr output in myexec.RunCommand
|
||||||
|
- feat: add `WithSwipeOffset` to set offset for swipe start/end point
|
||||||
|
- change: set `WithOffset` deprecated, replace with `WithTapOffset`
|
||||||
- change: upgrade funplugin to 0.5.3
|
- change: upgrade funplugin to 0.5.3
|
||||||
- refactor: move internal myexec to funplugin/myexec
|
- refactor: move internal myexec to funplugin/myexec
|
||||||
- change: create python3 plugin venv with latest funppy/httprunner
|
- change: create python3 plugin venv with latest funppy/httprunner
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ func TestAndroidExpertTest(t *testing.T) {
|
|||||||
hrp.NewStep("home 以及 swipe_to_tap_app 自定义配置").
|
hrp.NewStep("home 以及 swipe_to_tap_app 自定义配置").
|
||||||
Android().
|
Android().
|
||||||
Home().
|
Home().
|
||||||
SwipeToTapApp("$app_name", uixt.WithMaxRetryTimes(5), uixt.WithInterval(1), uixt.WithOffset(0, -50)).
|
SwipeToTapApp("$app_name", uixt.WithMaxRetryTimes(5), uixt.WithInterval(1), uixt.WithTapOffset(0, -50)).
|
||||||
Sleep(10),
|
Sleep(10),
|
||||||
hrp.NewStep("处理弹窗 close_popups 自定义配置 以及 ui_ocr exists 断言").
|
hrp.NewStep("处理弹窗 close_popups 自定义配置 以及 ui_ocr exists 断言").
|
||||||
Android().
|
Android().
|
||||||
@@ -265,7 +265,7 @@ func TestIOSExpertTest(t *testing.T) {
|
|||||||
hrp.NewStep("home 以及 swipe_to_tap_app 自定义配置").
|
hrp.NewStep("home 以及 swipe_to_tap_app 自定义配置").
|
||||||
IOS().
|
IOS().
|
||||||
Home().
|
Home().
|
||||||
SwipeToTapApp("$app_name", uixt.WithMaxRetryTimes(5), uixt.WithInterval(1), uixt.WithOffset(0, -50)).
|
SwipeToTapApp("$app_name", uixt.WithMaxRetryTimes(5), uixt.WithInterval(1), uixt.WithTapOffset(0, -50)).
|
||||||
Sleep(10),
|
Sleep(10),
|
||||||
hrp.NewStep("处理弹窗 close_popups 自定义配置 以及 ui_ocr exists 断言").
|
hrp.NewStep("处理弹窗 close_popups 自定义配置 以及 ui_ocr exists 断言").
|
||||||
IOS().
|
IOS().
|
||||||
|
|||||||
+54
-1
@@ -108,6 +108,7 @@ type ActionOptions struct {
|
|||||||
|
|
||||||
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
|
||||||
Offset []int `json:"offset,omitempty" yaml:"offset,omitempty"` // used to tap offset of point
|
Offset []int `json:"offset,omitempty" yaml:"offset,omitempty"` // used to tap offset of point
|
||||||
|
OffsetRandomScale float64 `json:"offset_random_scale,omitempty" yaml:"offset_random_scale,omitempty"` // used with Offset, set random scale for point
|
||||||
Index int `json:"index,omitempty" yaml:"index,omitempty"` // index of the target element
|
Index int `json:"index,omitempty" yaml:"index,omitempty"` // index of the target element
|
||||||
MatchOne bool `json:"match_one,omitempty" yaml:"match_one,omitempty"` // match one of the targets if existed
|
MatchOne bool `json:"match_one,omitempty" yaml:"match_one,omitempty"` // match one of the targets if existed
|
||||||
|
|
||||||
@@ -181,7 +182,12 @@ func (o *ActionOptions) Options() []ActionOption {
|
|||||||
o.AbsScope[0], o.AbsScope[1], o.AbsScope[2], o.AbsScope[3]))
|
o.AbsScope[0], o.AbsScope[1], o.AbsScope[2], o.AbsScope[3]))
|
||||||
}
|
}
|
||||||
if len(o.Offset) == 2 {
|
if len(o.Offset) == 2 {
|
||||||
options = append(options, WithOffset(o.Offset[0], o.Offset[1]))
|
// for tap [x,y] offset
|
||||||
|
options = append(options, WithTapOffset(o.Offset[0], o.Offset[1]))
|
||||||
|
} else if len(o.Offset) == 4 {
|
||||||
|
// for swipe [fromX, fromY, toX, toY] offset
|
||||||
|
options = append(options, WithSwipeOffset(
|
||||||
|
o.Offset[0], o.Offset[1], o.Offset[2], o.Offset[3]))
|
||||||
}
|
}
|
||||||
if o.Regex {
|
if o.Regex {
|
||||||
options = append(options, WithRegex(true))
|
options = append(options, WithRegex(true))
|
||||||
@@ -266,6 +272,42 @@ func mergeDataWithOptions(data map[string]interface{}, options ...ActionOption)
|
|||||||
yf, _ := builtin.Interface2Float64(y)
|
yf, _ := builtin.Interface2Float64(y)
|
||||||
data["y"] = yf + float64(actionOptions.Offset[1])
|
data["y"] = yf + float64(actionOptions.Offset[1])
|
||||||
}
|
}
|
||||||
|
} else if len(actionOptions.Offset) == 4 {
|
||||||
|
// Android uia2: [startX, startY, endX, endY]
|
||||||
|
if startX, ok := data["startX"]; ok {
|
||||||
|
vf, _ := builtin.Interface2Float64(startX)
|
||||||
|
data["startX"] = vf + float64(actionOptions.Offset[0])
|
||||||
|
}
|
||||||
|
if startY, ok := data["startY"]; ok {
|
||||||
|
vf, _ := builtin.Interface2Float64(startY)
|
||||||
|
data["startY"] = vf + float64(actionOptions.Offset[1])
|
||||||
|
}
|
||||||
|
if endX, ok := data["endX"]; ok {
|
||||||
|
vf, _ := builtin.Interface2Float64(endX)
|
||||||
|
data["endX"] = vf + float64(actionOptions.Offset[2])
|
||||||
|
}
|
||||||
|
if endY, ok := data["endY"]; ok {
|
||||||
|
vf, _ := builtin.Interface2Float64(endY)
|
||||||
|
data["endY"] = vf + float64(actionOptions.Offset[3])
|
||||||
|
}
|
||||||
|
|
||||||
|
// iOS WDA: [fromX, fromY, toX, toY]
|
||||||
|
if fromX, ok := data["fromX"]; ok {
|
||||||
|
vf, _ := builtin.Interface2Float64(fromX)
|
||||||
|
data["fromX"] = vf + float64(actionOptions.Offset[0])
|
||||||
|
}
|
||||||
|
if fromY, ok := data["fromY"]; ok {
|
||||||
|
vf, _ := builtin.Interface2Float64(fromY)
|
||||||
|
data["fromY"] = vf + float64(actionOptions.Offset[1])
|
||||||
|
}
|
||||||
|
if toX, ok := data["toX"]; ok {
|
||||||
|
vf, _ := builtin.Interface2Float64(toX)
|
||||||
|
data["toX"] = vf + float64(actionOptions.Offset[2])
|
||||||
|
}
|
||||||
|
if toY, ok := data["toY"]; ok {
|
||||||
|
vf, _ := builtin.Interface2Float64(toY)
|
||||||
|
data["toY"] = vf + float64(actionOptions.Offset[3])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if actionOptions.Steps > 0 {
|
if actionOptions.Steps > 0 {
|
||||||
@@ -377,12 +419,23 @@ func WithAbsScope(x1, y1, x2, y2 int) ActionOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: use WithTapOffset instead
|
||||||
func WithOffset(offsetX, offsetY int) ActionOption {
|
func WithOffset(offsetX, offsetY int) ActionOption {
|
||||||
return func(o *ActionOptions) {
|
return func(o *ActionOptions) {
|
||||||
o.Offset = []int{offsetX, offsetY}
|
o.Offset = []int{offsetX, offsetY}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tap [x, y] with offset [offsetX, offsetY]
|
||||||
|
var WithTapOffset = WithOffset
|
||||||
|
|
||||||
|
// swipe [fromX, fromY, toX, toY] with offset [offsetFromX, offsetFromY, offsetToX, offsetToY]
|
||||||
|
func WithSwipeOffset(offsetFromX, offsetFromY, offsetToX, offsetToY int) ActionOption {
|
||||||
|
return func(o *ActionOptions) {
|
||||||
|
o.Offset = []int{offsetFromX, offsetFromY, offsetToX, offsetToY}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func WithRegex(regex bool) ActionOption {
|
func WithRegex(regex bool) ActionOption {
|
||||||
return func(o *ActionOptions) {
|
return func(o *ActionOptions) {
|
||||||
o.Regex = regex
|
o.Regex = regex
|
||||||
|
|||||||
@@ -272,6 +272,15 @@ func (ad *adbDriver) Swipe(fromX, fromY, toX, toY int, options ...ActionOption)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ad *adbDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...ActionOption) error {
|
func (ad *adbDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...ActionOption) error {
|
||||||
|
actionOptions := NewActionOptions(options...)
|
||||||
|
|
||||||
|
if len(actionOptions.Offset) == 4 {
|
||||||
|
fromX += float64(actionOptions.Offset[0])
|
||||||
|
fromY += float64(actionOptions.Offset[1])
|
||||||
|
toX += float64(actionOptions.Offset[2])
|
||||||
|
toY += float64(actionOptions.Offset[3])
|
||||||
|
}
|
||||||
|
|
||||||
// adb shell input swipe fromX fromY toX toY
|
// adb shell input swipe fromX fromY toX toY
|
||||||
_, err := ad.adbClient.RunShellCommand(
|
_, err := ad.adbClient.RunShellCommand(
|
||||||
"input", "swipe",
|
"input", "swipe",
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ func (dExt *DriverExt) swipeToTapApp(appName string, options ...ActionOption) er
|
|||||||
}
|
}
|
||||||
// tap app icon above the text
|
// tap app icon above the text
|
||||||
if len(actionOptions.Offset) == 0 {
|
if len(actionOptions.Offset) == 0 {
|
||||||
options = append(options, WithOffset(0, -25))
|
options = append(options, WithTapOffset(0, -25))
|
||||||
}
|
}
|
||||||
// set default swipe interval to 1 second
|
// set default swipe interval to 1 second
|
||||||
if builtin.IsZeroFloat64(actionOptions.Interval) {
|
if builtin.IsZeroFloat64(actionOptions.Interval) {
|
||||||
|
|||||||
Reference in New Issue
Block a user