mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-06 20:32:44 +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
|
||||
|
||||
14
step_ui.go
14
step_ui.go
@@ -91,18 +91,20 @@ func (s *StepMobile) WebLoginNoneUI(packageName, phoneNumber string, captcha, pa
|
||||
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{
|
||||
Method: uixt.ACTION_AppLaunch,
|
||||
Params: bundleId,
|
||||
Method: uixt.ACTION_AppLaunch,
|
||||
Params: bundleId,
|
||||
Options: option.NewActionOptions(opts...),
|
||||
})
|
||||
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{
|
||||
Method: uixt.ACTION_AppTerminate,
|
||||
Params: bundleId,
|
||||
Method: uixt.ACTION_AppTerminate,
|
||||
Params: bundleId,
|
||||
Options: option.NewActionOptions(opts...),
|
||||
})
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -145,13 +145,13 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
|
||||
}
|
||||
case ACTION_AppClear:
|
||||
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")
|
||||
}
|
||||
}
|
||||
case ACTION_AppLaunch:
|
||||
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",
|
||||
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)
|
||||
case ACTION_AppTerminate:
|
||||
if bundleId, ok := action.Params.(string); ok {
|
||||
success, err := dExt.AppTerminate(bundleId)
|
||||
success, err := dExt.AppTerminate(bundleId, action.GetOptions()...)
|
||||
if err != nil {
|
||||
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.GetScreenRecordOptions()...)
|
||||
options = append(options, o.GetMarkOperationOptions()...)
|
||||
options = append(options, o.GetHookOptions()...)
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
@@ -8,6 +8,22 @@ type HookOptions struct {
|
||||
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
|
||||
func WithPreHook(preHook func()) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
|
||||
Reference in New Issue
Block a user