mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-29 03:57:22 +08:00
feat: support action options for AppLaunch/AppTerminate
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0-beta-2505092330
|
v5.0.0-beta-2505100001
|
||||||
|
|||||||
+8
-6
@@ -91,18 +91,20 @@ func (s *StepMobile) WebLoginNoneUI(packageName, phoneNumber string, captcha, pa
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepMobile) AppLaunch(bundleId string) *StepMobile {
|
func (s *StepMobile) AppLaunch(bundleId string, opts ...option.ActionOption) *StepMobile {
|
||||||
s.obj().Actions = append(s.obj().Actions, uixt.MobileAction{
|
s.obj().Actions = append(s.obj().Actions, uixt.MobileAction{
|
||||||
Method: uixt.ACTION_AppLaunch,
|
Method: uixt.ACTION_AppLaunch,
|
||||||
Params: bundleId,
|
Params: bundleId,
|
||||||
|
Options: option.NewActionOptions(opts...),
|
||||||
})
|
})
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepMobile) AppTerminate(bundleId string) *StepMobile {
|
func (s *StepMobile) AppTerminate(bundleId string, opts ...option.ActionOption) *StepMobile {
|
||||||
s.obj().Actions = append(s.obj().Actions, uixt.MobileAction{
|
s.obj().Actions = append(s.obj().Actions, uixt.MobileAction{
|
||||||
Method: uixt.ACTION_AppTerminate,
|
Method: uixt.ACTION_AppTerminate,
|
||||||
Params: bundleId,
|
Params: bundleId,
|
||||||
|
Options: option.NewActionOptions(opts...),
|
||||||
})
|
})
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,13 +145,13 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
|
|||||||
}
|
}
|
||||||
case ACTION_AppClear:
|
case ACTION_AppClear:
|
||||||
if packageName, ok := action.Params.(string); ok {
|
if packageName, ok := action.Params.(string); ok {
|
||||||
if err = dExt.AppClear(packageName); err != nil {
|
if err = dExt.AppClear(packageName, action.GetOptions()...); err != nil {
|
||||||
return errors.Wrap(err, "failed to clear app")
|
return errors.Wrap(err, "failed to clear app")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ACTION_AppLaunch:
|
case ACTION_AppLaunch:
|
||||||
if bundleId, ok := action.Params.(string); ok {
|
if bundleId, ok := action.Params.(string); ok {
|
||||||
return dExt.AppLaunch(bundleId)
|
return dExt.AppLaunch(bundleId, action.GetOptions()...)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params, should be bundleId(string), got %v",
|
return fmt.Errorf("invalid %s params, should be bundleId(string), got %v",
|
||||||
ACTION_AppLaunch, action.Params)
|
ACTION_AppLaunch, action.Params)
|
||||||
@@ -177,7 +177,7 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
|
|||||||
return fmt.Errorf("invalid %s params: %v", ACTION_SwipeToTapTexts, action.Params)
|
return fmt.Errorf("invalid %s params: %v", ACTION_SwipeToTapTexts, action.Params)
|
||||||
case ACTION_AppTerminate:
|
case ACTION_AppTerminate:
|
||||||
if bundleId, ok := action.Params.(string); ok {
|
if bundleId, ok := action.Params.(string); ok {
|
||||||
success, err := dExt.AppTerminate(bundleId)
|
success, err := dExt.AppTerminate(bundleId, action.GetOptions()...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to terminate app")
|
return errors.Wrap(err, "failed to terminate app")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ func (o *ActionOptions) Options() []ActionOption {
|
|||||||
options = append(options, o.GetScreenShotOptions()...)
|
options = append(options, o.GetScreenShotOptions()...)
|
||||||
options = append(options, o.GetScreenRecordOptions()...)
|
options = append(options, o.GetScreenRecordOptions()...)
|
||||||
options = append(options, o.GetMarkOperationOptions()...)
|
options = append(options, o.GetMarkOperationOptions()...)
|
||||||
|
options = append(options, o.GetHookOptions()...)
|
||||||
|
|
||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,22 @@ type HookOptions struct {
|
|||||||
PostHook func()
|
PostHook func()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *HookOptions) GetHookOptions() []ActionOption {
|
||||||
|
options := make([]ActionOption, 0)
|
||||||
|
if o == nil {
|
||||||
|
return options
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.PreHook != nil {
|
||||||
|
options = append(options, WithPreHook(o.PreHook))
|
||||||
|
}
|
||||||
|
if o.PostHook != nil {
|
||||||
|
options = append(options, WithPostHook(o.PostHook))
|
||||||
|
}
|
||||||
|
|
||||||
|
return options
|
||||||
|
}
|
||||||
|
|
||||||
// WithPreHook sets the pre hook before action
|
// WithPreHook sets the pre hook before action
|
||||||
func WithPreHook(preHook func()) ActionOption {
|
func WithPreHook(preHook func()) ActionOption {
|
||||||
return func(o *ActionOptions) {
|
return func(o *ActionOptions) {
|
||||||
|
|||||||
Reference in New Issue
Block a user