mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-08 09:19:41 +08:00
refactor: rename ApplyTapOffset
This commit is contained in:
@@ -99,9 +99,9 @@ func (o *ActionOptions) Options() []ActionOption {
|
||||
// for tap [x,y] offset
|
||||
options = append(options, WithTapOffset(o.TapOffset[0], o.TapOffset[1]))
|
||||
}
|
||||
if o.TapRandom {
|
||||
if o.TapRandomRect {
|
||||
// tap random point in OCR/CV rectangle
|
||||
options = append(options, WithTapRandom(true))
|
||||
options = append(options, WithTapRandomRect(true))
|
||||
}
|
||||
if len(o.SwipeOffset) == 4 {
|
||||
// for swipe [fromX, fromY, toX, toY] offset
|
||||
@@ -136,17 +136,17 @@ func (o *ActionOptions) Options() []ActionOption {
|
||||
return options
|
||||
}
|
||||
|
||||
func (o *ActionOptions) ApplyOffset(absX, absY float64) (float64, float64) {
|
||||
func (o *ActionOptions) ApplyTapOffset(absX, absY float64) (float64, float64) {
|
||||
if len(o.TapOffset) == 2 {
|
||||
absX += float64(o.TapOffset[0])
|
||||
absY += float64(o.TapOffset[1])
|
||||
}
|
||||
absX += o.GenerateRandomOffset()
|
||||
absY += o.GenerateRandomOffset()
|
||||
absX += o.generateRandomOffset()
|
||||
absY += o.generateRandomOffset()
|
||||
return absX, absY
|
||||
}
|
||||
|
||||
func (o *ActionOptions) GenerateRandomOffset() float64 {
|
||||
func (o *ActionOptions) generateRandomOffset() float64 {
|
||||
if len(o.OffsetRandomRange) != 2 {
|
||||
// invalid offset random range, should be [min, max]
|
||||
return 0
|
||||
|
||||
@@ -216,8 +216,8 @@ type ScreenFilterOptions struct {
|
||||
AbsScope AbsScope `json:"abs_scope,omitempty" yaml:"abs_scope,omitempty"`
|
||||
|
||||
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 point offset
|
||||
TapRandom bool `json:"tap_random,omitempty" yaml:"tap_random,omitempty"` // tap random point in text/image rectangle
|
||||
TapOffset []int `json:"tap_offset,omitempty" yaml:"tap_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
|
||||
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
|
||||
Index int `json:"index,omitempty" yaml:"index,omitempty"` // index of the target element
|
||||
@@ -248,11 +248,11 @@ func WithTapOffset(offsetX, offsetY int) ActionOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithTapRandom is used with TapByOCR and TapByCV
|
||||
// WithTapRandomRect is used with TapByOCR and TapByCV
|
||||
// when set true, tap random point in text/image rectangle
|
||||
func WithTapRandom(tapRandom bool) ActionOption {
|
||||
func WithTapRandomRect(tapRandom bool) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.TapRandom = tapRandom
|
||||
o.TapRandomRect = tapRandom
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user