feat: add CallFunc action for MobileUI step

This commit is contained in:
lilong.129
2024-12-23 22:31:05 +08:00
parent 0aed9b5b72
commit 628bf1b40c
3 changed files with 17 additions and 1 deletions
+1 -1
View File
@@ -1 +1 @@
v5.0.0+2412232123 v5.0.0+2412232231
+6
View File
@@ -35,6 +35,7 @@ const (
ACTION_SetIme ActionMethod = "set_ime" ACTION_SetIme ActionMethod = "set_ime"
ACTION_GetSource ActionMethod = "get_source" ACTION_GetSource ActionMethod = "get_source"
ACTION_GetForegroundApp ActionMethod = "get_foreground_app" ACTION_GetForegroundApp ActionMethod = "get_foreground_app"
ACTION_CallFunction ActionMethod = "call_function"
// UI handling // UI handling
ACTION_Home ActionMethod = "home" ACTION_Home ActionMethod = "home"
@@ -79,6 +80,7 @@ const (
type MobileAction struct { 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"`
Fn func() `json:"-" yaml:"-"` // only used for function action, not serialized
Options *ActionOptions `json:"options,omitempty" yaml:"options,omitempty"` Options *ActionOptions `json:"options,omitempty" yaml:"options,omitempty"`
ActionOptions ActionOptions
} }
@@ -778,6 +780,10 @@ func (dExt *DriverExt) DoAction(action MobileAction) (err error) {
case ACTION_EndToEndDelay: case ACTION_EndToEndDelay:
CollectEndToEndDelay(dExt, action.GetOptions()...) CollectEndToEndDelay(dExt, action.GetOptions()...)
return nil return nil
case ACTION_CallFunction:
log.Info().Interface("name", action.Params).Msg("call function")
fn := action.Fn
fn()
} }
return nil return nil
} }
+10
View File
@@ -401,6 +401,16 @@ func (s *StepMobile) ClosePopups(options ...uixt.ActionOption) *StepMobile {
return s return s
} }
func (s *StepMobile) CallFunc(name string, fn func()) *StepMobile {
s.obj().Actions = append(s.obj().Actions, uixt.MobileAction{
Method: uixt.ACTION_CallFunction,
Params: name,
Fn: fn,
Options: nil,
})
return s
}
// Validate switches to step validation. // Validate switches to step validation.
func (s *StepMobile) Validate() *StepMobileUIValidation { func (s *StepMobile) Validate() *StepMobileUIValidation {
return &StepMobileUIValidation{ return &StepMobileUIValidation{