mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 15:37:35 +08:00
change: tap/swipe with offset
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0-beta-2503141055
|
v5.0.0-beta-2503171436
|
||||||
|
|||||||
@@ -156,7 +156,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.Offset) == 0 {
|
if len(actionOptions.TapOffset) == 0 {
|
||||||
opts = append(opts, option.WithTapOffset(0, -25))
|
opts = append(opts, option.WithTapOffset(0, -25))
|
||||||
}
|
}
|
||||||
// set default swipe interval to 1 second
|
// set default swipe interval to 1 second
|
||||||
|
|||||||
@@ -168,3 +168,16 @@ func TestDriverExt_ClosePopupsHandler(t *testing.T) {
|
|||||||
err := driver.ClosePopupsHandler()
|
err := driver.ClosePopupsHandler()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDriverExt_Action_Risk(t *testing.T) {
|
||||||
|
driver := setupADBDriverExt(t)
|
||||||
|
|
||||||
|
// tap point with offset
|
||||||
|
err := driver.TapXY(0.5, 0.5, option.WithTapOffset(-10, 10))
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
// swipe direction with offset
|
||||||
|
err = driver.Swipe(0.5, 0.5, 0.5, 0.9,
|
||||||
|
option.WithSwipeOffset(-50, 50, -50, 50))
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|||||||
@@ -95,13 +95,14 @@ func (o *ActionOptions) Options() []ActionOption {
|
|||||||
options = append(options, WithScope(
|
options = append(options, WithScope(
|
||||||
o.Scope[0], o.Scope[1], o.Scope[2], o.Scope[3]))
|
o.Scope[0], o.Scope[1], o.Scope[2], o.Scope[3]))
|
||||||
}
|
}
|
||||||
if len(o.Offset) == 2 {
|
if len(o.TapOffset) == 2 {
|
||||||
// for tap [x,y] offset
|
// for tap [x,y] offset
|
||||||
options = append(options, WithTapOffset(o.Offset[0], o.Offset[1]))
|
options = append(options, WithTapOffset(o.TapOffset[0], o.TapOffset[1]))
|
||||||
} else if len(o.Offset) == 4 {
|
}
|
||||||
|
if len(o.SwipeOffset) == 4 {
|
||||||
// for swipe [fromX, fromY, toX, toY] offset
|
// for swipe [fromX, fromY, toX, toY] offset
|
||||||
options = append(options, WithSwipeOffset(
|
options = append(options, WithSwipeOffset(
|
||||||
o.Offset[0], o.Offset[1], o.Offset[2], o.Offset[3]))
|
o.SwipeOffset[0], o.SwipeOffset[1], o.SwipeOffset[2], o.SwipeOffset[3]))
|
||||||
}
|
}
|
||||||
if len(o.OffsetRandomRange) == 2 {
|
if len(o.OffsetRandomRange) == 2 {
|
||||||
options = append(options, WithOffsetRandomRange(
|
options = append(options, WithOffsetRandomRange(
|
||||||
@@ -132,9 +133,9 @@ func (o *ActionOptions) Options() []ActionOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o *ActionOptions) ApplyOffset(absX, absY float64) (float64, float64) {
|
func (o *ActionOptions) ApplyOffset(absX, absY float64) (float64, float64) {
|
||||||
if len(o.Offset) == 2 {
|
if len(o.TapOffset) == 2 {
|
||||||
absX += float64(o.Offset[0])
|
absX += float64(o.TapOffset[0])
|
||||||
absY += float64(o.Offset[1])
|
absY += float64(o.TapOffset[1])
|
||||||
}
|
}
|
||||||
absX += o.GenerateRandomOffset()
|
absX += o.GenerateRandomOffset()
|
||||||
absY += o.GenerateRandomOffset()
|
absY += o.GenerateRandomOffset()
|
||||||
@@ -276,7 +277,7 @@ func WithCustomDirection(sx, sy, ex, ey float64) ActionOption {
|
|||||||
// swipe [fromX, fromY, toX, toY] with offset [offsetFromX, offsetFromY, offsetToX, offsetToY]
|
// swipe [fromX, fromY, toX, toY] with offset [offsetFromX, offsetFromY, offsetToX, offsetToY]
|
||||||
func WithSwipeOffset(offsetFromX, offsetFromY, offsetToX, offsetToY int) ActionOption {
|
func WithSwipeOffset(offsetFromX, offsetFromY, offsetToX, offsetToY int) ActionOption {
|
||||||
return func(o *ActionOptions) {
|
return func(o *ActionOptions) {
|
||||||
o.Offset = []int{offsetFromX, offsetFromY, offsetToX, offsetToY}
|
o.SwipeOffset = []int{offsetFromX, offsetFromY, offsetToX, offsetToY}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -216,7 +216,8 @@ 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
|
||||||
Offset []int `json:"offset,omitempty" yaml:"offset,omitempty"` // used to tap offset of point
|
TapOffset []int `json:"tap_offset,omitempty" yaml:"tap_offset,omitempty"` // tap with point 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
|
||||||
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"`
|
MatchOne bool `json:"match_one,omitempty" yaml:"match_one,omitempty"`
|
||||||
@@ -242,7 +243,7 @@ func WithAbsScope(x1, y1, x2, y2 int) ActionOption {
|
|||||||
// tap [x, y] with offset [offsetX, offsetY]
|
// tap [x, y] with offset [offsetX, offsetY]
|
||||||
func WithTapOffset(offsetX, offsetY int) ActionOption {
|
func WithTapOffset(offsetX, offsetY int) ActionOption {
|
||||||
return func(o *ActionOptions) {
|
return func(o *ActionOptions) {
|
||||||
o.Offset = []int{offsetX, offsetY}
|
o.TapOffset = []int{offsetX, offsetY}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user