mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
feat: add screenshot
This commit is contained in:
@@ -34,6 +34,7 @@ const (
|
||||
uiLongClick MobileMethod = "long_click"
|
||||
uiSwipe MobileMethod = "swipe"
|
||||
uiInput MobileMethod = "input"
|
||||
ctlScreenShot MobileMethod = "screenshot"
|
||||
ctlSleep MobileMethod = "sleep"
|
||||
)
|
||||
|
||||
|
||||
@@ -190,6 +190,14 @@ func (s *StepIOS) Sleep(n int) *StepIOS {
|
||||
return &StepIOS{step: s.step}
|
||||
}
|
||||
|
||||
func (s *StepIOS) ScreenShot() *StepIOS {
|
||||
s.step.IOS.Actions = append(s.step.IOS.Actions, MobileAction{
|
||||
Method: ctlScreenShot,
|
||||
Params: nil,
|
||||
})
|
||||
return &StepIOS{step: s.step}
|
||||
}
|
||||
|
||||
// Validate switches to step validation.
|
||||
func (s *StepIOS) Validate() *StepIOSValidation {
|
||||
return &StepIOSValidation{
|
||||
@@ -404,8 +412,8 @@ func runStepIOS(r *SessionRunner, step *TStep) (stepResult *StepResult, err erro
|
||||
}
|
||||
|
||||
// take snapshot
|
||||
log.Info().Str("name", step.Name).Msg("take snapshot")
|
||||
err = wdaClient.screenshot()
|
||||
log.Info().Str("name", step.Name).Msg("take snapshot before validation")
|
||||
err = wdaClient.screenShot()
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Str("step", step.Name).Msg("take screenshot failed")
|
||||
}
|
||||
@@ -429,7 +437,7 @@ type wdaClient struct {
|
||||
WindowSize gwda.Size
|
||||
}
|
||||
|
||||
func (w *wdaClient) screenshot() error {
|
||||
func (w *wdaClient) screenShot() error {
|
||||
raw, err := w.Driver.Screenshot()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "screenshot by WDA failed")
|
||||
@@ -585,6 +593,10 @@ func (w *wdaClient) doAction(action MobileAction) error {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("invalid sleep params: %v", action.Params)
|
||||
case ctlScreenShot:
|
||||
// take snapshot
|
||||
log.Info().Msg("take snapshot for current screen")
|
||||
w.screenShot()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -87,20 +87,27 @@ func TestIOSAppLaunch(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIOSWeixin(t *testing.T) {
|
||||
func TestIOSWeixinLive(t *testing.T) {
|
||||
testCase := &TestCase{
|
||||
Config: NewConfig("ios ui action on 微信"),
|
||||
Config: NewConfig("ios ui action on 微信直播"),
|
||||
TestSteps: []IStep{
|
||||
NewStep("启动微信").
|
||||
IOS().Home().Click("微信").
|
||||
IOS().
|
||||
Home().
|
||||
AppTerminate("com.tencent.xin"). // 关闭已运行的微信,确保启动微信后在「微信」首页
|
||||
Click("微信").
|
||||
Validate().
|
||||
AssertNameExists("通讯录", "微信启动失败,「通讯录」不存在"),
|
||||
NewStep("进入直播页").
|
||||
IOS().Click("发现").Click([]float64{0.5, 0.3}).
|
||||
IOS().
|
||||
Click("发现").Sleep(5). // 进入「发现页」;等待 5 秒确保加载完成
|
||||
Click([]float64{0.5, 0.3}). // 基于坐标位置点击「直播」;TODO:通过 OCR 识别「直播」
|
||||
Validate().
|
||||
AssertNameExists("直播", "「直播」不存在"),
|
||||
NewStep("向上滑动 5 次").
|
||||
IOS().SwipeUp().Times(5),
|
||||
IOS().
|
||||
SwipeUp().Times(3).ScreenShot(). // 上划 3 次,截图保存
|
||||
SwipeUp().Times(2).ScreenShot(), // 再上划 2 次,截图保存
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user