mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-07 00:17:37 +08:00
compatibility: support indicating options separately in MobileAction level
This commit is contained in:
+20
-10
@@ -65,6 +65,16 @@ type MobileAction struct {
|
|||||||
Method ActionMethod `json:"method,omitempty" yaml:"method,omitempty"`
|
Method ActionMethod `json:"method,omitempty" yaml:"method,omitempty"`
|
||||||
Params interface{} `json:"params,omitempty" yaml:"params,omitempty"`
|
Params interface{} `json:"params,omitempty" yaml:"params,omitempty"`
|
||||||
Options *ActionOptions `json:"options,omitempty" yaml:"options,omitempty"`
|
Options *ActionOptions `json:"options,omitempty" yaml:"options,omitempty"`
|
||||||
|
ActionOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ma MobileAction) GetOptions() []ActionOption {
|
||||||
|
var actionOptionList []ActionOption
|
||||||
|
if ma.Options != nil {
|
||||||
|
actionOptionList = append(actionOptionList, ma.Options.Options()...)
|
||||||
|
}
|
||||||
|
actionOptionList = append(actionOptionList, ma.ActionOptions.Options()...)
|
||||||
|
return actionOptionList
|
||||||
}
|
}
|
||||||
|
|
||||||
// (x1, y1) is the top left corner, (x2, y2) is the bottom right corner
|
// (x1, y1) is the top left corner, (x2, y2) is the bottom right corner
|
||||||
@@ -403,19 +413,19 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
ACTION_AppLaunch, action.Params)
|
ACTION_AppLaunch, action.Params)
|
||||||
case ACTION_SwipeToTapApp:
|
case ACTION_SwipeToTapApp:
|
||||||
if appName, ok := action.Params.(string); ok {
|
if appName, ok := action.Params.(string); ok {
|
||||||
return dExt.swipeToTapApp(appName, action.Options.Options()...)
|
return dExt.swipeToTapApp(appName, action.GetOptions()...)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params, should be app name(string), got %v",
|
return fmt.Errorf("invalid %s params, should be app name(string), got %v",
|
||||||
ACTION_SwipeToTapApp, action.Params)
|
ACTION_SwipeToTapApp, action.Params)
|
||||||
case ACTION_SwipeToTapText:
|
case ACTION_SwipeToTapText:
|
||||||
if text, ok := action.Params.(string); ok {
|
if text, ok := action.Params.(string); ok {
|
||||||
return dExt.swipeToTapTexts([]string{text}, action.Options.Options()...)
|
return dExt.swipeToTapTexts([]string{text}, action.GetOptions()...)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params, should be app text(string), got %v",
|
return fmt.Errorf("invalid %s params, should be app text(string), got %v",
|
||||||
ACTION_SwipeToTapText, action.Params)
|
ACTION_SwipeToTapText, action.Params)
|
||||||
case ACTION_SwipeToTapTexts:
|
case ACTION_SwipeToTapTexts:
|
||||||
if texts, ok := action.Params.([]string); ok {
|
if texts, ok := action.Params.([]string); ok {
|
||||||
return dExt.swipeToTapTexts(texts, action.Options.Options()...)
|
return dExt.swipeToTapTexts(texts, action.GetOptions()...)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params, should be app text([]string), got %v",
|
return fmt.Errorf("invalid %s params, should be app text([]string), got %v",
|
||||||
ACTION_SwipeToTapText, action.Params)
|
ACTION_SwipeToTapText, action.Params)
|
||||||
@@ -441,7 +451,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
}
|
}
|
||||||
x, _ := location[0].(float64)
|
x, _ := location[0].(float64)
|
||||||
y, _ := location[1].(float64)
|
y, _ := location[1].(float64)
|
||||||
return dExt.TapXY(x, y, action.Options.Options()...)
|
return dExt.TapXY(x, y, action.GetOptions()...)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", ACTION_TapXY, action.Params)
|
return fmt.Errorf("invalid %s params: %v", ACTION_TapXY, action.Params)
|
||||||
case ACTION_TapAbsXY:
|
case ACTION_TapAbsXY:
|
||||||
@@ -452,22 +462,22 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
}
|
}
|
||||||
x, _ := location[0].(float64)
|
x, _ := location[0].(float64)
|
||||||
y, _ := location[1].(float64)
|
y, _ := location[1].(float64)
|
||||||
return dExt.TapAbsXY(x, y, action.Options.Options()...)
|
return dExt.TapAbsXY(x, y, action.GetOptions()...)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", ACTION_TapAbsXY, action.Params)
|
return fmt.Errorf("invalid %s params: %v", ACTION_TapAbsXY, action.Params)
|
||||||
case ACTION_Tap:
|
case ACTION_Tap:
|
||||||
if param, ok := action.Params.(string); ok {
|
if param, ok := action.Params.(string); ok {
|
||||||
return dExt.Tap(param, action.Options.Options()...)
|
return dExt.Tap(param, action.GetOptions()...)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", ACTION_Tap, action.Params)
|
return fmt.Errorf("invalid %s params: %v", ACTION_Tap, action.Params)
|
||||||
case ACTION_TapByOCR:
|
case ACTION_TapByOCR:
|
||||||
if ocrText, ok := action.Params.(string); ok {
|
if ocrText, ok := action.Params.(string); ok {
|
||||||
return dExt.TapByOCR(ocrText, action.Options.Options()...)
|
return dExt.TapByOCR(ocrText, action.GetOptions()...)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", ACTION_TapByOCR, action.Params)
|
return fmt.Errorf("invalid %s params: %v", ACTION_TapByOCR, action.Params)
|
||||||
case ACTION_TapByCV:
|
case ACTION_TapByCV:
|
||||||
if imagePath, ok := action.Params.(string); ok {
|
if imagePath, ok := action.Params.(string); ok {
|
||||||
return dExt.TapByCV(imagePath, action.Options.Options()...)
|
return dExt.TapByCV(imagePath, action.GetOptions()...)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", ACTION_TapByCV, action.Params)
|
return fmt.Errorf("invalid %s params: %v", ACTION_TapByCV, action.Params)
|
||||||
case ACTION_DoubleTapXY:
|
case ACTION_DoubleTapXY:
|
||||||
@@ -487,14 +497,14 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", ACTION_DoubleTap, action.Params)
|
return fmt.Errorf("invalid %s params: %v", ACTION_DoubleTap, action.Params)
|
||||||
case ACTION_Swipe:
|
case ACTION_Swipe:
|
||||||
swipeAction := dExt.prepareSwipeAction(action.Options.Options()...)
|
swipeAction := dExt.prepareSwipeAction(action.GetOptions()...)
|
||||||
return swipeAction(dExt)
|
return swipeAction(dExt)
|
||||||
case ACTION_Input:
|
case ACTION_Input:
|
||||||
// input text on current active element
|
// input text on current active element
|
||||||
// append \n to send text with enter
|
// append \n to send text with enter
|
||||||
// send \b\b\b to delete 3 chars
|
// send \b\b\b to delete 3 chars
|
||||||
param := fmt.Sprintf("%v", action.Params)
|
param := fmt.Sprintf("%v", action.Params)
|
||||||
return dExt.Driver.Input(param, action.Options.Options()...)
|
return dExt.Driver.Input(param, action.GetOptions()...)
|
||||||
case ACTION_Back:
|
case ACTION_Back:
|
||||||
return dExt.Driver.PressBack()
|
return dExt.Driver.PressBack()
|
||||||
case ACTION_Sleep:
|
case ACTION_Sleep:
|
||||||
|
|||||||
Reference in New Issue
Block a user