feat: parse ios action params with variables

This commit is contained in:
debugtalk
2022-09-27 20:32:02 +08:00
parent 8710213ff8
commit 9b71617c3a
6 changed files with 24 additions and 5 deletions
+4 -1
View File
@@ -1,6 +1,9 @@
{ {
"config": { "config": {
"name": "通过 feed 卡片进入抖音直播间", "name": "通过 feed 卡片进入抖音直播间",
"variables": {
"app_name": "抖音"
},
"ios": [ "ios": [
{ {
"port": 8700, "port": 8700,
@@ -23,7 +26,7 @@
}, },
{ {
"method": "swipe_to_tap_app", "method": "swipe_to_tap_app",
"params": "抖音", "params": "$app_name",
"max_retry_times": 5 "max_retry_times": 5
}, },
{ {
+3 -1
View File
@@ -1,5 +1,7 @@
config: config:
name: 通过 feed 卡片进入抖音直播间 name: 通过 feed 卡片进入抖音直播间
variables:
app_name: 抖音
ios: ios:
- port: 8700 - port: 8700
mjpeg_port: 8800 mjpeg_port: 8800
@@ -12,7 +14,7 @@ teststeps:
- method: app_terminate - method: app_terminate
params: com.ss.iphone.ugc.Aweme params: com.ss.iphone.ugc.Aweme
- method: swipe_to_tap_app - method: swipe_to_tap_app
params: 抖音 params: $app_name
max_retry_times: 5 max_retry_times: 5
- method: sleep - method: sleep
params: 5 params: 5
+4 -1
View File
@@ -10,13 +10,16 @@ import (
func TestIOSDouyinLive(t *testing.T) { func TestIOSDouyinLive(t *testing.T) {
testCase := &hrp.TestCase{ testCase := &hrp.TestCase{
Config: hrp.NewConfig("通过 feed 卡片进入抖音直播间"). Config: hrp.NewConfig("通过 feed 卡片进入抖音直播间").
WithVariables(map[string]interface{}{
"app_name": "抖音",
}).
SetIOS(hrp.WithLogOn(true), hrp.WithPort(8700), hrp.WithMjpegPort(8800)), SetIOS(hrp.WithLogOn(true), hrp.WithPort(8700), hrp.WithMjpegPort(8800)),
TestSteps: []hrp.IStep{ TestSteps: []hrp.IStep{
hrp.NewStep("启动抖音"). hrp.NewStep("启动抖音").
IOS(). IOS().
Home(). Home().
AppTerminate("com.ss.iphone.ugc.Aweme"). // 关闭已运行的抖音 AppTerminate("com.ss.iphone.ugc.Aweme"). // 关闭已运行的抖音
SwipeToTapApp("抖音", hrp.WithMaxRetryTimes(5)).Sleep(5). SwipeToTapApp("$app_name", hrp.WithMaxRetryTimes(5)).Sleep(5).
Validate(). Validate().
AssertOCRExists("推荐", "抖音启动失败,「推荐」不存在"), AssertOCRExists("推荐", "抖音启动失败,「推荐」不存在"),
// hrp.NewStep("处理青少年弹窗"). // hrp.NewStep("处理青少年弹窗").
+1 -1
View File
@@ -10,7 +10,6 @@ require (
github.com/electricbubble/opencv-helper v0.0.3 github.com/electricbubble/opencv-helper v0.0.3
github.com/fatih/color v1.13.0 github.com/fatih/color v1.13.0
github.com/getsentry/sentry-go v0.13.0 github.com/getsentry/sentry-go v0.13.0
github.com/go-errors/errors v1.4.2
github.com/go-openapi/spec v0.20.7 github.com/go-openapi/spec v0.20.7
github.com/go-ping/ping v1.1.0 github.com/go-ping/ping v1.1.0
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
@@ -43,6 +42,7 @@ require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect github.com/go-openapi/jsonreference v0.20.0 // indirect
+1 -1
View File
@@ -10,9 +10,9 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/go-errors/errors"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"github.com/olekukonko/tablewriter" "github.com/olekukonko/tablewriter"
"github.com/pkg/errors"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/httprunner/httprunner/v4/hrp/internal/boomer/grpc/messager" "github.com/httprunner/httprunner/v4/hrp/internal/boomer/grpc/messager"
+11
View File
@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/pkg/errors"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/httprunner/httprunner/v4/hrp/internal/uixt" "github.com/httprunner/httprunner/v4/hrp/internal/uixt"
@@ -512,6 +513,13 @@ func runStepIOS(s *SessionRunner, step *TStep) (stepResult *StepResult, err erro
} }
screenshots := make([]string, 0) screenshots := make([]string, 0)
// override step variables
stepVariables, err := s.MergeStepVariables(step.Variables)
if err != nil {
return
}
parser := s.GetParser()
// init wdaClient driver // init wdaClient driver
wdaClient, err := s.hrpRunner.initUIClient(&step.IOS.IOSDevice) wdaClient, err := s.hrpRunner.initUIClient(&step.IOS.IOSDevice)
if err != nil { if err != nil {
@@ -557,6 +565,9 @@ func runStepIOS(s *SessionRunner, step *TStep) (stepResult *StepResult, err erro
// run actions // run actions
for _, action := range 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 := wdaClient.DoAction(action); err != nil { if err := wdaClient.DoAction(action); err != nil {
return stepResult, err return stepResult, err
} }