mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-06 16:07:45 +08:00
feat: GetScreenResult with max retry times option
This commit is contained in:
+27
-10
@@ -42,30 +42,47 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S
|
|||||||
if len(screenshotActions) != 0 {
|
if len(screenshotActions) != 0 {
|
||||||
fileName = builtin.GenNameWithTimestamp("%d_" + strings.Join(screenshotActions, "_"))
|
fileName = builtin.GenNameWithTimestamp("%d_" + strings.Join(screenshotActions, "_"))
|
||||||
}
|
}
|
||||||
bufSource, imagePath, err := dExt.GetScreenShot(fileName)
|
if actionOptions.MaxRetryTimes == 0 {
|
||||||
if err != nil {
|
actionOptions.MaxRetryTimes = 1
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
windowSize, err := dExt.Driver.WindowSize()
|
var bufSource *bytes.Buffer
|
||||||
|
var imageResult *ImageResult
|
||||||
|
var imagePath string
|
||||||
|
var windowSize Size
|
||||||
|
for i := 0; i < actionOptions.MaxRetryTimes; i++ {
|
||||||
|
bufSource, imagePath, err = dExt.GetScreenShot(fileName)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
windowSize, err = dExt.Driver.WindowSize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(code.MobileUIDriverError, err.Error())
|
err = errors.Wrap(code.MobileUIDriverError, err.Error())
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
screenResult = &ScreenResult{
|
screenResult = &ScreenResult{
|
||||||
bufSource: bufSource,
|
bufSource: bufSource,
|
||||||
ImagePath: imagePath,
|
ImagePath: imagePath,
|
||||||
Tags: nil,
|
Tags: nil,
|
||||||
Resolution: windowSize,
|
Resolution: windowSize,
|
||||||
}
|
}
|
||||||
|
imageResult, err = dExt.ImageService.GetImage(bufSource, options...)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("GetImage from ImageService failed")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// success
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// cache screen result
|
// cache screen result
|
||||||
dExt.Driver.GetSession().addScreenResult(screenResult)
|
dExt.Driver.GetSession().addScreenResult(screenResult)
|
||||||
|
|
||||||
imageResult, err := dExt.ImageService.GetImage(bufSource, options...)
|
|
||||||
if err != nil {
|
|
||||||
log.Error().Err(err).Msg("GetImage from ImageService failed")
|
|
||||||
return screenResult, err
|
|
||||||
}
|
|
||||||
if imageResult != nil {
|
if imageResult != nil {
|
||||||
screenResult.ImageResult = imageResult
|
screenResult.ImageResult = imageResult
|
||||||
screenResult.Texts = imageResult.OCRResult.ToOCRTexts()
|
screenResult.Texts = imageResult.OCRResult.ToOCRTexts()
|
||||||
|
|||||||
Reference in New Issue
Block a user