mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-07 16:59:34 +08:00
fix: modify function call parameters
This commit is contained in:
@@ -67,7 +67,7 @@ type MobileAction struct {
|
||||
Identifier string `json:"identifier,omitempty" yaml:"identifier,omitempty"` // used to identify the action in log
|
||||
MaxRetryTimes int `json:"max_retry_times,omitempty" yaml:"max_retry_times,omitempty"` // max retry times
|
||||
Direction interface{} `json:"direction,omitempty" yaml:"direction,omitempty"` // used by swipe to tap text or app
|
||||
RecognitionArea []float64 `json:"recognition_area,omitempty" yaml:"recognition_area,omitempty"` // used by ocr to get text position in the recognition area
|
||||
Scope []float64 `json:"scope,omitempty" yaml:"scope,omitempty"` // used by ocr to get text position in the scope
|
||||
Index int `json:"index,omitempty" yaml:"index,omitempty"` // index of the target element, should start from 1
|
||||
Timeout int `json:"timeout,omitempty" yaml:"timeout,omitempty"` // TODO: wait timeout in seconds for mobile action
|
||||
IgnoreNotFoundError bool `json:"ignore_NotFoundError,omitempty" yaml:"ignore_NotFoundError,omitempty"` // ignore error if target element not found
|
||||
@@ -104,10 +104,10 @@ func WithCustomDirection(sx, sy, ex, ey float64) ActionOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithRecognitionArea inputs area of [(x1,y1), (x2,y2)]
|
||||
func WithRecognitionArea(x1, y1, x2, y2 float64) ActionOption {
|
||||
// WithScope inputs area of [(x1,y1), (x2,y2)]
|
||||
func WithScope(x1, y1, x2, y2 float64) ActionOption {
|
||||
return func(o *MobileAction) {
|
||||
o.RecognitionArea = []float64{x1, y1, x2, y2}
|
||||
o.Scope = []float64{x1, y1, x2, y2}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ func (dExt *DriverExt) FindUIElement(param string) (ele WebElement, err error) {
|
||||
func (dExt *DriverExt) FindUIRectInUIKit(search string, index ...int) (x, y, width, height float64, err error) {
|
||||
// click on text, using OCR
|
||||
if !isPathExists(search) {
|
||||
return dExt.FindTextByOCR(search, nil, index...)
|
||||
return dExt.FindTextByOCR(search, WithCustomOption("index", index))
|
||||
}
|
||||
// click on image, using opencv
|
||||
return dExt.FindImageRectInUIKit(search, index...)
|
||||
@@ -347,7 +347,7 @@ func (dExt *DriverExt) IsLabelExist(label string) bool {
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) IsOCRExist(text string) bool {
|
||||
_, _, _, _, err := dExt.FindTextByOCR(text, nil)
|
||||
_, _, _, _, err := dExt.FindTextByOCR(text)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
@@ -379,10 +379,25 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
||||
AppLaunchUnattached, action.Params)
|
||||
case ACTION_SwipeToTapApp:
|
||||
if appName, ok := action.Params.(string); ok {
|
||||
if len(action.Scope) != 4 {
|
||||
action.Scope = []float64{0, 0, 1, 1}
|
||||
}
|
||||
|
||||
var options []DataOption
|
||||
options = append(options,
|
||||
WithCustomOption("index", []int{action.Index}),
|
||||
WithCustomOption("scope", []int{
|
||||
int(action.Scope[0] * float64(dExt.windowSize.Width) * dExt.scale),
|
||||
int(action.Scope[1] * float64(dExt.windowSize.Height) * dExt.scale),
|
||||
int(action.Scope[2] * float64(dExt.windowSize.Width) * dExt.scale),
|
||||
int(action.Scope[3] * float64(dExt.windowSize.Height) * dExt.scale),
|
||||
}),
|
||||
)
|
||||
|
||||
var point PointF
|
||||
findApp := func(d *DriverExt) error {
|
||||
var err error
|
||||
point, err = d.GetTextXY(appName, action.RecognitionArea, action.Index)
|
||||
point, err = d.GetTextXY(appName, options...)
|
||||
return err
|
||||
}
|
||||
foundAppAction := func(d *DriverExt) error {
|
||||
@@ -411,10 +426,25 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
||||
ACTION_SwipeToTapApp, action.Params)
|
||||
case ACTION_SwipeToTapText:
|
||||
if text, ok := action.Params.(string); ok {
|
||||
if len(action.Scope) != 4 {
|
||||
action.Scope = []float64{0, 0, 1, 1}
|
||||
}
|
||||
|
||||
var options []DataOption
|
||||
options = append(options,
|
||||
WithCustomOption("index", []int{action.Index}),
|
||||
WithCustomOption("scope", []int{
|
||||
int(action.Scope[0] * float64(dExt.windowSize.Width) * dExt.scale),
|
||||
int(action.Scope[1] * float64(dExt.windowSize.Height) * dExt.scale),
|
||||
int(action.Scope[2] * float64(dExt.windowSize.Width) * dExt.scale),
|
||||
int(action.Scope[3] * float64(dExt.windowSize.Height) * dExt.scale),
|
||||
}),
|
||||
)
|
||||
|
||||
var point PointF
|
||||
findText := func(d *DriverExt) error {
|
||||
var err error
|
||||
point, err = d.GetTextXY(text, action.RecognitionArea, action.Index)
|
||||
point, err = d.GetTextXY(text, options...)
|
||||
return err
|
||||
}
|
||||
foundTextAction := func(d *DriverExt) error {
|
||||
@@ -444,10 +474,24 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
||||
action.Params = textList
|
||||
}
|
||||
if texts, ok := action.Params.([]string); ok {
|
||||
if len(action.Scope) != 4 {
|
||||
action.Scope = []float64{0, 0, 1, 1}
|
||||
}
|
||||
|
||||
var options []DataOption
|
||||
options = append(options,
|
||||
WithCustomOption("scope", []int{
|
||||
int(action.Scope[0] * float64(dExt.windowSize.Width) * dExt.scale),
|
||||
int(action.Scope[1] * float64(dExt.windowSize.Height) * dExt.scale),
|
||||
int(action.Scope[2] * float64(dExt.windowSize.Width) * dExt.scale),
|
||||
int(action.Scope[3] * float64(dExt.windowSize.Height) * dExt.scale),
|
||||
}),
|
||||
)
|
||||
|
||||
var point PointF
|
||||
findText := func(d *DriverExt) error {
|
||||
var err error
|
||||
points, err := d.GetTextXYs(texts, action.RecognitionArea)
|
||||
points, err := d.GetTextXYs(texts, options...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -519,7 +563,21 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
||||
return fmt.Errorf("invalid %s params: %v", ACTION_Tap, action.Params)
|
||||
case ACTION_TapByOCR:
|
||||
if ocrText, ok := action.Params.(string); ok {
|
||||
return dExt.TapByOCR(ocrText, action.Identifier, action.IgnoreNotFoundError, action.RecognitionArea, action.Index)
|
||||
if len(action.Scope) != 4 {
|
||||
action.Scope = []float64{0, 0, 1, 1}
|
||||
}
|
||||
|
||||
var options []DataOption
|
||||
options = append(options,
|
||||
WithCustomOption("index", []int{action.Index}),
|
||||
WithCustomOption("scope", []int{
|
||||
int(action.Scope[0] * float64(dExt.windowSize.Width) * dExt.scale),
|
||||
int(action.Scope[1] * float64(dExt.windowSize.Height) * dExt.scale),
|
||||
int(action.Scope[2] * float64(dExt.windowSize.Width) * dExt.scale),
|
||||
int(action.Scope[3] * float64(dExt.windowSize.Height) * dExt.scale),
|
||||
}),
|
||||
)
|
||||
return dExt.TapByOCR(ocrText, action.Identifier, action.IgnoreNotFoundError, options...)
|
||||
}
|
||||
return fmt.Errorf("invalid %s params: %v", ACTION_TapByOCR, action.Params)
|
||||
case ACTION_TapByCV:
|
||||
|
||||
Reference in New Issue
Block a user