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

View File

@@ -1,6 +1,9 @@
{
"config": {
"name": "通过 feed 卡片进入抖音直播间",
"variables": {
"app_name": "抖音"
},
"ios": [
{
"port": 8700,
@@ -23,7 +26,7 @@
},
{
"method": "swipe_to_tap_app",
"params": "抖音",
"params": "$app_name",
"max_retry_times": 5
},
{

View File

@@ -1,5 +1,7 @@
config:
name: 通过 feed 卡片进入抖音直播间
variables:
app_name: 抖音
ios:
- port: 8700
mjpeg_port: 8800
@@ -12,7 +14,7 @@ teststeps:
- method: app_terminate
params: com.ss.iphone.ugc.Aweme
- method: swipe_to_tap_app
params: 抖音
params: $app_name
max_retry_times: 5
- method: sleep
params: 5

View File

@@ -10,13 +10,16 @@ import (
func TestIOSDouyinLive(t *testing.T) {
testCase := &hrp.TestCase{
Config: hrp.NewConfig("通过 feed 卡片进入抖音直播间").
WithVariables(map[string]interface{}{
"app_name": "抖音",
}).
SetIOS(hrp.WithLogOn(true), hrp.WithPort(8700), hrp.WithMjpegPort(8800)),
TestSteps: []hrp.IStep{
hrp.NewStep("启动抖音").
IOS().
Home().
AppTerminate("com.ss.iphone.ugc.Aweme"). // 关闭已运行的抖音
SwipeToTapApp("抖音", hrp.WithMaxRetryTimes(5)).Sleep(5).
SwipeToTapApp("$app_name", hrp.WithMaxRetryTimes(5)).Sleep(5).
Validate().
AssertOCRExists("推荐", "抖音启动失败,「推荐」不存在"),
// hrp.NewStep("处理青少年弹窗").

2
go.mod
View File

@@ -10,7 +10,6 @@ require (
github.com/electricbubble/opencv-helper v0.0.3
github.com/fatih/color v1.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-ping/ping v1.1.0
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/cpuguy83/go-md2man/v2 v2.0.2 // 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-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect

View File

@@ -10,9 +10,9 @@ import (
"sync/atomic"
"time"
"github.com/go-errors/errors"
"github.com/jinzhu/copier"
"github.com/olekukonko/tablewriter"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/httprunner/httprunner/v4/hrp/internal/boomer/grpc/messager"

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"time"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"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)
// override step variables
stepVariables, err := s.MergeStepVariables(step.Variables)
if err != nil {
return
}
parser := s.GetParser()
// init wdaClient driver
wdaClient, err := s.hrpRunner.initUIClient(&step.IOS.IOSDevice)
if err != nil {
@@ -557,6 +565,9 @@ func runStepIOS(s *SessionRunner, step *TStep) (stepResult *StepResult, err erro
// 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 := wdaClient.DoAction(action); err != nil {
return stepResult, err
}