From c9279fb4f702bac056ae760f27ee3d7f71779361 Mon Sep 17 00:00:00 2001 From: "xucong.053" Date: Thu, 13 Oct 2022 14:17:24 +0800 Subject: [PATCH] feat: input params by funcion in ui automation --- hrp/internal/builtin/function.go | 5 +++++ hrp/pkg/uixt/ext.go | 8 ++++++++ hrp/step.go | 1 + hrp/step_mobile_ui.go | 7 +++++++ 4 files changed, 21 insertions(+) diff --git a/hrp/internal/builtin/function.go b/hrp/internal/builtin/function.go index a5b3c36f..00d01d97 100644 --- a/hrp/internal/builtin/function.go +++ b/hrp/internal/builtin/function.go @@ -28,6 +28,7 @@ var Functions = map[string]interface{}{ "md5": MD5, // call with one argument "parameterize": loadFromCSV, "P": loadFromCSV, + "split_by_comma": splitByComma, // call with one argument "environ": os.Getenv, "ENV": os.Getenv, "load_ws_message": loadMessage, @@ -225,3 +226,7 @@ func multipartContentType(w *TFormDataWriter) string { } return w.Writer.FormDataContentType() } + +func splitByComma(s string) []string { + return strings.Split(s, ",") +} diff --git a/hrp/pkg/uixt/ext.go b/hrp/pkg/uixt/ext.go index 25a3bb44..276b6946 100644 --- a/hrp/pkg/uixt/ext.go +++ b/hrp/pkg/uixt/ext.go @@ -67,6 +67,7 @@ type MobileAction struct { Identifier string `json:"identifier,omitempty" yaml:"identifier,omitempty"` // used to identify the action in log MaxRetryTimes int `json:"max_retry_times,omitempty" yaml:"max_retry_times,omitempty"` // max retry times Direction interface{} `json:"direction,omitempty" yaml:"direction,omitempty"` // used by swipe to tap text or app + Function string `json:"function,omitempty" yaml:"function,omitempty"` // used to replace params Index int `json:"index,omitempty" yaml:"index,omitempty"` // index of the target element, should start from 1 Timeout int `json:"timeout,omitempty" yaml:"timeout,omitempty"` // TODO: wait timeout in seconds for mobile action IgnoreNotFoundError bool `json:"ignore_NotFoundError,omitempty" yaml:"ignore_NotFoundError,omitempty"` // ignore error if target element not found @@ -89,6 +90,13 @@ func WithIndex(index int) ActionOption { } } +// WithFunction replaces params +func WithFunction(function string) ActionOption { + return func(o *MobileAction) { + o.Function = function + } +} + // WithDirection inputs direction (up, down, left, right) func WithDirection(direction string) ActionOption { return func(o *MobileAction) { diff --git a/hrp/step.go b/hrp/step.go index ac7481f1..f10fc84f 100644 --- a/hrp/step.go +++ b/hrp/step.go @@ -31,6 +31,7 @@ var ( WithDescription = uixt.WithDescription WithDirection = uixt.WithDirection WithCustomDirection = uixt.WithCustomDirection + WithFunction = uixt.WithFunction ) var ( diff --git a/hrp/step_mobile_ui.go b/hrp/step_mobile_ui.go index 64e22f65..fa924edb 100644 --- a/hrp/step_mobile_ui.go +++ b/hrp/step_mobile_ui.go @@ -618,6 +618,13 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err // run actions for _, action := range actions { + if action.Function != "" { + parsedParams, err := parser.ParseString(action.Function, stepVariables) + if err != nil { + return stepResult, err + } + action.Params = parsedParams + } if action.Params, err = parser.Parse(action.Params, stepVariables); err != nil { return stepResult, errors.Wrap(err, "parse action params failed") }