From 5bd2edac27e93401800316cfec5024ff67babdd7 Mon Sep 17 00:00:00 2001 From: xucong053 Date: Thu, 29 Sep 2022 16:20:53 +0800 Subject: [PATCH 1/2] update: android actions --- hrp/step_android_ui.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/hrp/step_android_ui.go b/hrp/step_android_ui.go index 53168cf2..fb2856b5 100644 --- a/hrp/step_android_ui.go +++ b/hrp/step_android_ui.go @@ -112,6 +112,32 @@ func (s *StepAndroid) StopRecording() *StepAndroid { return &StepAndroid{step: s.step} } +// TapXY taps the point {X,Y}, X & Y is percentage of coordinates +func (s *StepAndroid) TapXY(x, y float64, options ...uixt.ActionOption) *StepAndroid { + action := uixt.MobileAction{ + Method: uixt.ACTION_TapXY, + Params: []float64{x, y}, + } + for _, option := range options { + option(&action) + } + s.step.Android.Actions = append(s.step.Android.Actions, action) + return &StepAndroid{step: s.step} +} + +// TapAbsXY taps the point {X,Y}, X & Y is absolute coordinates +func (s *StepAndroid) TapAbsXY(x, y float64, options ...uixt.ActionOption) *StepAndroid { + action := uixt.MobileAction{ + Method: uixt.ACTION_TapAbsXY, + Params: []float64{x, y}, + } + for _, option := range options { + option(&action) + } + s.step.Android.Actions = append(s.step.Android.Actions, action) + return &StepAndroid{step: s.step} +} + func (s *StepAndroid) Tap(params interface{}) *StepAndroid { s.step.Android.Actions = append(s.step.Android.Actions, uixt.MobileAction{ Method: uixt.ACTION_Tap, From 9c54996d175a0c56aedfaf321d5236a966912129 Mon Sep 17 00:00:00 2001 From: xucong053 Date: Thu, 29 Sep 2022 17:18:26 +0800 Subject: [PATCH 2/2] fix: failed to parse in android ui automation --- hrp/step_android_ui.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hrp/step_android_ui.go b/hrp/step_android_ui.go index fb2856b5..4db318e7 100644 --- a/hrp/step_android_ui.go +++ b/hrp/step_android_ui.go @@ -4,9 +4,9 @@ import ( "fmt" "time" - "github.com/rs/zerolog/log" - "github.com/httprunner/httprunner/v4/hrp/internal/uixt" + "github.com/pkg/errors" + "github.com/rs/zerolog/log" ) var ( @@ -466,6 +466,13 @@ func runStepAndroid(s *SessionRunner, step *TStep) (stepResult *StepResult, err } screenshots := make([]string, 0) + // override step variables + stepVariables, err := s.MergeStepVariables(step.Variables) + if err != nil { + return + } + parser := s.GetParser() + // init uiaClient driver uiaClient, err := s.hrpRunner.initUIClient(&step.Android.AndroidDevice) if err != nil { @@ -511,6 +518,9 @@ func runStepAndroid(s *SessionRunner, step *TStep) (stepResult *StepResult, err // run actions for _, action := range actions { + if action.Params, err = parser.Parse(action.Params, stepVariables); err != nil { + return stepResult, errors.Wrap(err, "parse action params failed") + } if err := uiaClient.DoAction(action); err != nil { return stepResult, err }