feat: support action options for AppLaunch/AppTerminate

This commit is contained in:
lilong.129
2025-05-10 00:01:30 +08:00
parent 4a2276c7f0
commit 9bafea53af
5 changed files with 29 additions and 10 deletions

View File

@@ -1 +1 @@
v5.0.0-beta-2505092330
v5.0.0-beta-2505100001

View File

@@ -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
}

View File

@@ -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")
}

View File

@@ -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
}

View File

@@ -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) {