change: add logs for loop index

This commit is contained in:
debugtalk
2022-12-13 22:34:11 +08:00
parent dcc2f651d4
commit 11abdf07af
3 changed files with 27 additions and 39 deletions

View File

@@ -3,7 +3,6 @@
package main
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
@@ -48,18 +47,14 @@ func TestMainAndroid(t *testing.T) {
wc.Start()
}
func init() {
os.Setenv("UDID", "00008030-00194DA421C1802E")
}
func TestIOSDouyinWorldCupLive(t *testing.T) {
testCase := &hrp.TestCase{
Config: hrp.NewConfig("直播_抖音_世界杯_ios").
WithVariables(map[string]interface{}{
"device": "${ENV(UDID)}",
"appBundleID": "com.ss.iphone.ugc.Aweme",
}).
SetIOS(
hrp.WithUDID("$device"),
hrp.WithUDID(uuid),
hrp.WithLogOn(true),
hrp.WithWDAPort(8700),
hrp.WithWDAMjpegPort(8800),
@@ -69,8 +64,8 @@ func TestIOSDouyinWorldCupLive(t *testing.T) {
hrp.NewStep("启动抖音").
IOS().
Home().
AppTerminate("com.ss.iphone.ugc.Aweme"). // 关闭已运行的抖音
AppLaunch("com.ss.iphone.ugc.Aweme").
AppTerminate("$appBundleID"). // 关闭已运行的抖音
AppLaunch("$appBundleID").
Validate().
AssertOCRExists("首页", "抖音启动失败,「首页」不存在"),
hrp.NewStep("处理青少年弹窗").
@@ -86,28 +81,18 @@ func TestIOSDouyinWorldCupLive(t *testing.T) {
hrp.WithCustomDirection(0.4, 0.07, 0.6, 0.07), // 滑动 tab从左到右解决「世界杯」被遮挡的问题
hrp.WithScope(0, 0, 1, 0.15), // 限定 tab 区域
hrp.WithWaitTime(1),
).
Swipe(0.5, 0.3, 0.5, 0.2), // 少量上划,解决「直播中」未展示的问题
),
hrp.NewStep("点击进入直播间").
IOS().
LoopTimes(30). // 重复执行 30
Loop(5). // 重复执行 5
TapByOCR("直播中", hrp.WithIdentifier("click_live"), hrp.WithIndex(-1)).
Sleep(30).Back().Sleep(30),
Sleep(3).Back().Sleep(3),
hrp.NewStep("关闭抖音").
IOS().
AppTerminate("com.ss.iphone.ugc.Aweme"),
hrp.NewStep("返回主界面,并打开本地时间戳").
IOS().
Home().SwipeToTapApp("local", hrp.WithMaxRetryTimes(5)).Sleep(10).
Validate().
AssertOCRExists("16", "打开本地时间戳失败"),
AppTerminate("$appBundleID"),
},
}
if err := testCase.Dump2JSON("ios_worldcup_live_douyin_test.json"); err != nil {
t.Fatal(err)
}
runner := hrp.NewRunner(t).SetSaveTests(true)
err := runner.Run(testCase)
if err != nil {

View File

@@ -35,7 +35,7 @@ var (
type MobileStep struct {
Serial string `json:"serial,omitempty" yaml:"serial,omitempty"`
Times int `json:"times,omitempty" yaml:"times,omitempty"`
Loops int `json:"loops,omitempty" yaml:"loops,omitempty"`
uixt.MobileAction `yaml:",inline"`
Actions []uixt.MobileAction `json:"actions,omitempty" yaml:"actions,omitempty"`
}
@@ -303,9 +303,9 @@ func (s *StepMobile) Input(text string, options ...uixt.ActionOption) *StepMobil
return &StepMobile{step: s.step}
}
// LoopTimes specify running times for the current step
func (s *StepMobile) LoopTimes(n int) *StepMobile {
s.mobileStep().Times = n
// Loop specify running times for the current step
func (s *StepMobile) Loop(times int) *StepMobile {
s.mobileStep().Loops = times
return &StepMobile{step: s.step}
}
@@ -608,19 +608,22 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
actions = mobileStep.Actions
}
// run times
times := mobileStep.Times
if times < 0 {
log.Warn().Int("times", times).Msg("times should be positive, set to 1")
times = 1
} else if times == 0 {
times = 1
} else if times > 1 {
log.Info().Int("times", times).Msg("run actions with specified times")
// run times of actions
loopTimes := mobileStep.Loops
if loopTimes < 0 {
log.Warn().Int("loopTimes", loopTimes).Msg("times should be positive, set to 1")
loopTimes = 1
} else if loopTimes == 0 {
loopTimes = 1
} else if loopTimes > 1 {
log.Info().Int("loopTimes", loopTimes).Msg("run actions with specified loop times")
}
// run actions with specified times
for i := 0; i < times; i++ {
for i := 0; i < loopTimes; i++ {
if i > 0 {
log.Info().Int("index", i+1).Msg("start running actions in loop")
}
for _, action := range actions {
if action.Params, err = s.caseRunner.parser.Parse(action.Params, stepVariables); err != nil {
if !code.IsErrorPredefined(err) {

View File

@@ -86,7 +86,7 @@ func TestIOSWeixinLive(t *testing.T) {
AssertLabelExists("直播"),
NewStep("向上滑动 3 次,截图保存").
IOS().
LoopTimes(3). // 整体循环 3 次
Loop(3). // 整体循环 3 次
SwipeUp().SwipeUp().ScreenShot(), // 上划 2 次,截图保存
},
}
@@ -155,7 +155,7 @@ func TestIOSDouyinAction(t *testing.T) {
AssertLabelExists("消息", "消息 tab 不存在"),
NewStep("swipe up and down").
IOS().
LoopTimes(3).
Loop(3).
SwipeUp().SwipeDown(),
},
}