mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-31 21:39:41 +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}
|
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.
|
// Validate switches to step validation.
|
||||||
func (s *StepIOS) Validate() *StepIOSValidation {
|
func (s *StepIOS) Validate() *StepIOSValidation {
|
||||||
return &StepIOSValidation{
|
return &StepIOSValidation{
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func TestIOSSearchApp(t *testing.T) {
|
|||||||
Config: NewConfig("ios ui action on Search App 资源库"),
|
Config: NewConfig("ios ui action on Search App 资源库"),
|
||||||
TestSteps: []IStep{
|
TestSteps: []IStep{
|
||||||
NewStep("进入 App 资源库 搜索框").
|
NewStep("进入 App 资源库 搜索框").
|
||||||
IOS().Home().SwipeLeft().SwipeLeft().Click("dewey-search-field").
|
IOS().Home().SwipeLeft().Times(2).Click("dewey-search-field").
|
||||||
Validate().
|
Validate().
|
||||||
AssertNameExists("取消", "「取消」不存在"),
|
AssertNameExists("取消", "「取消」不存在"),
|
||||||
NewStep("搜索抖音").
|
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) {
|
func TestIOSDouyinAction(t *testing.T) {
|
||||||
testCase := &TestCase{
|
testCase := &TestCase{
|
||||||
Config: NewConfig("ios ui action on 抖音"),
|
Config: NewConfig("ios ui action on 抖音"),
|
||||||
@@ -76,7 +99,7 @@ func TestIOSDouyinAction(t *testing.T) {
|
|||||||
AssertNameExists("首页", "首页 tab 不存在").
|
AssertNameExists("首页", "首页 tab 不存在").
|
||||||
AssertNameExists("消息", "消息 tab 不存在"),
|
AssertNameExists("消息", "消息 tab 不存在"),
|
||||||
NewStep("swipe up and down").
|
NewStep("swipe up and down").
|
||||||
IOS().SwipeUp().SwipeUp().SwipeDown(),
|
IOS().SwipeUp().Times(3).SwipeDown(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user