mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
feat: run last action with given times
This commit is contained in:
@@ -121,6 +121,27 @@ func (s *StepIOS) StartAppByClick(name string) *StepIOS {
|
||||
return &StepIOS{step: s.step}
|
||||
}
|
||||
|
||||
// run last action with given times
|
||||
func (s *StepIOS) Times(n int) *StepIOS {
|
||||
if n <= 0 {
|
||||
log.Warn().Int("n", n).Msg("times should be positive, set to 1")
|
||||
n = 1
|
||||
}
|
||||
|
||||
actionsTotal := len(s.step.IOS.Actions)
|
||||
if actionsTotal == 0 {
|
||||
return s
|
||||
}
|
||||
|
||||
// actionsTotal >=1 && n >= 1
|
||||
lastAction := s.step.IOS.Actions[actionsTotal-1 : actionsTotal][0]
|
||||
for i := 0; i < n-1; i++ {
|
||||
// duplicate last action n-1 times
|
||||
s.step.IOS.Actions = append(s.step.IOS.Actions, lastAction)
|
||||
}
|
||||
return &StepIOS{step: s.step}
|
||||
}
|
||||
|
||||
// Validate switches to step validation.
|
||||
func (s *StepIOS) Validate() *StepIOSValidation {
|
||||
return &StepIOSValidation{
|
||||
|
||||
@@ -52,7 +52,7 @@ func TestIOSSearchApp(t *testing.T) {
|
||||
Config: NewConfig("ios ui action on Search App 资源库"),
|
||||
TestSteps: []IStep{
|
||||
NewStep("进入 App 资源库 搜索框").
|
||||
IOS().Home().SwipeLeft().SwipeLeft().Click("dewey-search-field").
|
||||
IOS().Home().SwipeLeft().Times(2).Click("dewey-search-field").
|
||||
Validate().
|
||||
AssertNameExists("取消", "「取消」不存在"),
|
||||
NewStep("搜索抖音").
|
||||
@@ -66,6 +66,29 @@ func TestIOSSearchApp(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIOSWeixin(t *testing.T) {
|
||||
testCase := &TestCase{
|
||||
Config: NewConfig("ios ui action on 微信"),
|
||||
TestSteps: []IStep{
|
||||
NewStep("启动微信").
|
||||
IOS().Home().Click("微信").
|
||||
Validate().
|
||||
AssertNameExists("通讯录", "微信启动失败,「通讯录」不存在"),
|
||||
NewStep("进入直播页").
|
||||
IOS().Click("发现").Click([]float64{0.5, 0.3}).
|
||||
Validate().
|
||||
AssertNameExists("直播", "「直播」不存在"),
|
||||
NewStep("向上滑动 5 次").
|
||||
IOS().SwipeUp().Times(5),
|
||||
},
|
||||
}
|
||||
|
||||
err := NewRunner(t).Run(testCase)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIOSDouyinAction(t *testing.T) {
|
||||
testCase := &TestCase{
|
||||
Config: NewConfig("ios ui action on 抖音"),
|
||||
@@ -76,7 +99,7 @@ func TestIOSDouyinAction(t *testing.T) {
|
||||
AssertNameExists("首页", "首页 tab 不存在").
|
||||
AssertNameExists("消息", "消息 tab 不存在"),
|
||||
NewStep("swipe up and down").
|
||||
IOS().SwipeUp().SwipeUp().SwipeDown(),
|
||||
IOS().SwipeUp().Times(3).SwipeDown(),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user