mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
feat: add GetAbsScope
This commit is contained in:
+37
-5
@@ -66,6 +66,17 @@ type MobileAction struct {
|
|||||||
Options *ActionOptions `json:"options,omitempty" yaml:"options,omitempty"`
|
Options *ActionOptions `json:"options,omitempty" yaml:"options,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// (x1, y1) is the top left corner, (x2, y2) is the bottom right corner
|
||||||
|
// [x1, y1, x2, y2] in percentage of the screen
|
||||||
|
type Scope []float64
|
||||||
|
|
||||||
|
// [x1, y1, x2, y2] in absolute pixels
|
||||||
|
type AbsScope []int
|
||||||
|
|
||||||
|
func (s AbsScope) Option() ActionOption {
|
||||||
|
return WithAbsScope(s[0], s[1], s[2], s[3])
|
||||||
|
}
|
||||||
|
|
||||||
type ActionOptions struct {
|
type ActionOptions struct {
|
||||||
// log
|
// log
|
||||||
Identifier string `json:"identifier,omitempty" yaml:"identifier,omitempty"` // used to identify the action in log
|
Identifier string `json:"identifier,omitempty" yaml:"identifier,omitempty"` // used to identify the action in log
|
||||||
@@ -81,9 +92,8 @@ type ActionOptions struct {
|
|||||||
Frequency int `json:"frequency,omitempty" yaml:"frequency,omitempty"`
|
Frequency int `json:"frequency,omitempty" yaml:"frequency,omitempty"`
|
||||||
|
|
||||||
// scope related
|
// scope related
|
||||||
// (x1, y1) is the top left corner, (x2, y2) is the bottom right corner
|
Scope Scope `json:"scope,omitempty" yaml:"scope,omitempty"`
|
||||||
Scope []float64 `json:"scope,omitempty" yaml:"scope,omitempty"` // [x1, y1, x2, y2] in percentage of the screen
|
AbsScope AbsScope `json:"abs_scope,omitempty" yaml:"abs_scope,omitempty"`
|
||||||
AbsScope []int `json:"abs_scope,omitempty" yaml:"abs_scope,omitempty"` // [x1, y1, x2, y2] in absolute pixels
|
|
||||||
|
|
||||||
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
|
||||||
@@ -288,7 +298,7 @@ func WithCustomDirection(sx, sy, ex, ey float64) ActionOption {
|
|||||||
// x1, y1, x2, y2 are all in [0, 1], which means the relative position of the screen
|
// x1, y1, x2, y2 are all in [0, 1], which means the relative position of the screen
|
||||||
func WithScope(x1, y1, x2, y2 float64) ActionOption {
|
func WithScope(x1, y1, x2, y2 float64) ActionOption {
|
||||||
return func(o *ActionOptions) {
|
return func(o *ActionOptions) {
|
||||||
o.Scope = []float64{x1, y1, x2, y2}
|
o.Scope = Scope{x1, y1, x2, y2}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,7 +306,7 @@ func WithScope(x1, y1, x2, y2 float64) ActionOption {
|
|||||||
// x1, y1, x2, y2 are all absolute position of the screen
|
// x1, y1, x2, y2 are all absolute position of the screen
|
||||||
func WithAbsScope(x1, y1, x2, y2 int) ActionOption {
|
func WithAbsScope(x1, y1, x2, y2 int) ActionOption {
|
||||||
return func(o *ActionOptions) {
|
return func(o *ActionOptions) {
|
||||||
o.AbsScope = []int{x1, y1, x2, y2}
|
o.AbsScope = AbsScope{x1, y1, x2, y2}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,6 +346,28 @@ func WithIgnoreNotFoundError(ignoreError bool) ActionOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dExt *DriverExt) ParseActionOptions(options ...ActionOption) []ActionOption {
|
||||||
|
actionOptions := NewActionOptions(options...)
|
||||||
|
|
||||||
|
// convert relative scope to absolute scope
|
||||||
|
if len(actionOptions.AbsScope) != 4 && len(actionOptions.Scope) == 4 {
|
||||||
|
scope := actionOptions.Scope
|
||||||
|
actionOptions.AbsScope = dExt.GenAbsScope(
|
||||||
|
scope[0], scope[1], scope[2], scope[3])
|
||||||
|
}
|
||||||
|
|
||||||
|
return actionOptions.Options()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dExt *DriverExt) GenAbsScope(x1, y1, x2, y2 float64) AbsScope {
|
||||||
|
// convert relative scope to absolute scope
|
||||||
|
absX1 := int(x1 * float64(dExt.windowSize.Width))
|
||||||
|
absY1 := int(y1 * float64(dExt.windowSize.Height))
|
||||||
|
absX2 := int(x2 * float64(dExt.windowSize.Width))
|
||||||
|
absY2 := int(y2 * float64(dExt.windowSize.Height))
|
||||||
|
return AbsScope{absX1, absY1, absX2, absY2}
|
||||||
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) DoAction(action MobileAction) error {
|
func (dExt *DriverExt) DoAction(action MobileAction) error {
|
||||||
log.Info().Str("method", string(action.Method)).Interface("params", action.Params).Msg("start UI action")
|
log.Info().Str("method", string(action.Method)).Interface("params", action.Params).Msg("start UI action")
|
||||||
|
|
||||||
|
|||||||
@@ -219,22 +219,6 @@ func (dExt *DriverExt) IsImageExist(text string) bool {
|
|||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) ParseActionOptions(options ...ActionOption) []ActionOption {
|
|
||||||
actionOptions := NewActionOptions(options...)
|
|
||||||
|
|
||||||
// convert relative scope to absolute scope
|
|
||||||
if len(actionOptions.AbsScope) != 4 && len(actionOptions.Scope) == 4 {
|
|
||||||
scope := actionOptions.Scope
|
|
||||||
x1 := int(scope[0] * float64(dExt.windowSize.Width))
|
|
||||||
y1 := int(scope[1] * float64(dExt.windowSize.Height))
|
|
||||||
x2 := int(scope[2] * float64(dExt.windowSize.Width))
|
|
||||||
y2 := int(scope[3] * float64(dExt.windowSize.Height))
|
|
||||||
actionOptions.AbsScope = []int{x1, y1, x2, y2}
|
|
||||||
}
|
|
||||||
|
|
||||||
return actionOptions.Options()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dExt *DriverExt) DoValidation(check, assert, expected string, message ...string) bool {
|
func (dExt *DriverExt) DoValidation(check, assert, expected string, message ...string) bool {
|
||||||
var exp bool
|
var exp bool
|
||||||
if assert == AssertionExists || assert == AssertionEqual {
|
if assert == AssertionExists || assert == AssertionEqual {
|
||||||
|
|||||||
Reference in New Issue
Block a user