mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-03 06:49:38 +08:00
fix: GetStepCacheData
This commit is contained in:
@@ -2,6 +2,7 @@ package uixt
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/gif"
|
||||
@@ -61,6 +62,12 @@ type cacheStepData struct {
|
||||
VideoStat *VideoStat
|
||||
}
|
||||
|
||||
func (d *cacheStepData) reset() {
|
||||
d.ScreenShots = make([]string, 0)
|
||||
d.OcrResults = make(map[string]*OcrResult)
|
||||
d.VideoStat = nil
|
||||
}
|
||||
|
||||
type DriverExt struct {
|
||||
CVArgs
|
||||
Device Device
|
||||
@@ -188,14 +195,25 @@ func (dExt *DriverExt) saveScreenShot(raw *bytes.Buffer, fileName string) (strin
|
||||
return screenshotPath, nil
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) GetStepCacheData() cacheStepData {
|
||||
copied := dExt.cacheStepData
|
||||
// clear cache
|
||||
dExt.cacheStepData = cacheStepData{
|
||||
ScreenShots: []string{},
|
||||
OcrResults: make(map[string]*OcrResult),
|
||||
func (dExt *DriverExt) GetStepCacheData() map[string]interface{} {
|
||||
cacheData := make(map[string]interface{})
|
||||
cacheData["video_stat"] = dExt.cacheStepData.VideoStat
|
||||
cacheData["screenshots"] = dExt.cacheStepData.ScreenShots
|
||||
|
||||
ocrResults := make(map[string]interface{})
|
||||
for imagePath, ocrResult := range dExt.cacheStepData.OcrResults {
|
||||
o, _ := json.Marshal(ocrResult.Texts)
|
||||
data := map[string]interface{}{
|
||||
"tags": ocrResult.Tags,
|
||||
"texts": string(o),
|
||||
}
|
||||
ocrResults[imagePath] = data
|
||||
}
|
||||
return copied
|
||||
cacheData["ocr_results"] = ocrResults
|
||||
|
||||
// clear cache
|
||||
dExt.cacheStepData.reset()
|
||||
return cacheData
|
||||
}
|
||||
|
||||
// isPathExists returns true if path exists, whether path is file or dir
|
||||
|
||||
@@ -592,10 +592,10 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
|
||||
|
||||
// check if app is in foreground
|
||||
packageName := uiDriver.Driver.GetLastLaunchedApp()
|
||||
err := uiDriver.Driver.AssertAppForeground(packageName)
|
||||
if packageName != "" && err != nil {
|
||||
log.Error().Err(err).Str("packageName", packageName).Msg("app is not in foreground")
|
||||
err = errors.Wrap(code.MobileUIAppNotInForegroundError, err.Error())
|
||||
err2 := uiDriver.Driver.AssertAppForeground(packageName)
|
||||
if packageName != "" && err2 != nil {
|
||||
log.Error().Err(err2).Str("packageName", packageName).Msg("app is not in foreground")
|
||||
err = errors.Wrap(code.MobileUIAppNotInForegroundError, err2.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -608,9 +608,9 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
|
||||
|
||||
// save attachments
|
||||
cacheData := uiDriver.GetStepCacheData()
|
||||
attachments["screenshots"] = cacheData.ScreenShots
|
||||
attachments["ocr_results"] = cacheData.OcrResults
|
||||
attachments["video_stat"] = cacheData.VideoStat
|
||||
for key, value := range cacheData {
|
||||
attachments[key] = value
|
||||
}
|
||||
stepResult.Attachments = attachments
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user