fix: GetStepCacheData

This commit is contained in:
lilong.129
2023-05-04 13:06:57 +08:00
parent 70d0f666ea
commit ab8b5b133f
4 changed files with 36 additions and 17 deletions
@@ -38,7 +38,7 @@
1, 1,
1 1
], ],
"target": 2, "target": 1,
"text": "^广告$" "text": "^广告$"
}, },
{ {
@@ -49,6 +49,7 @@
1, 1,
1 1
], ],
"target": 1,
"text": "^图文$" "text": "^图文$"
}, },
{ {
@@ -25,8 +25,8 @@ func TestAndroidVideoCrawlerTest(t *testing.T) {
"feed": map[string]interface{}{ "feed": map[string]interface{}{
"target_count": 5, "target_count": 5,
"target_labels": []map[string]interface{}{ "target_labels": []map[string]interface{}{
{"text": "^广告$", "scope": []float64{0, 0.5, 1, 1}, "regex": true, "target": 2}, {"text": "^广告$", "scope": []float64{0, 0.5, 1, 1}, "regex": true, "target": 1},
{"text": "^图文$", "scope": []float64{0, 0.5, 1, 1}, "regex": true}, {"text": "^图文$", "scope": []float64{0, 0.5, 1, 1}, "regex": true, "target": 1},
{"text": `^特效\|`, "scope": []float64{0, 0.5, 1, 1}, "regex": true}, {"text": `^特效\|`, "scope": []float64{0, 0.5, 1, 1}, "regex": true},
{"text": `^模板\|`, "scope": []float64{0, 0.5, 1, 1}, "regex": true}, {"text": `^模板\|`, "scope": []float64{0, 0.5, 1, 1}, "regex": true},
{"text": `^购物\|`, "scope": []float64{0, 0.5, 1, 1}, "regex": true}, {"text": `^购物\|`, "scope": []float64{0, 0.5, 1, 1}, "regex": true},
+25 -7
View File
@@ -2,6 +2,7 @@ package uixt
import ( import (
"bytes" "bytes"
"encoding/json"
"fmt" "fmt"
"image" "image"
"image/gif" "image/gif"
@@ -61,6 +62,12 @@ type cacheStepData struct {
VideoStat *VideoStat VideoStat *VideoStat
} }
func (d *cacheStepData) reset() {
d.ScreenShots = make([]string, 0)
d.OcrResults = make(map[string]*OcrResult)
d.VideoStat = nil
}
type DriverExt struct { type DriverExt struct {
CVArgs CVArgs
Device Device Device Device
@@ -188,14 +195,25 @@ func (dExt *DriverExt) saveScreenShot(raw *bytes.Buffer, fileName string) (strin
return screenshotPath, nil return screenshotPath, nil
} }
func (dExt *DriverExt) GetStepCacheData() cacheStepData { func (dExt *DriverExt) GetStepCacheData() map[string]interface{} {
copied := dExt.cacheStepData cacheData := make(map[string]interface{})
// clear cache cacheData["video_stat"] = dExt.cacheStepData.VideoStat
dExt.cacheStepData = cacheStepData{ cacheData["screenshots"] = dExt.cacheStepData.ScreenShots
ScreenShots: []string{},
OcrResults: make(map[string]*OcrResult), 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 // isPathExists returns true if path exists, whether path is file or dir
+7 -7
View File
@@ -592,10 +592,10 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
// check if app is in foreground // check if app is in foreground
packageName := uiDriver.Driver.GetLastLaunchedApp() packageName := uiDriver.Driver.GetLastLaunchedApp()
err := uiDriver.Driver.AssertAppForeground(packageName) err2 := uiDriver.Driver.AssertAppForeground(packageName)
if packageName != "" && err != nil { if packageName != "" && err2 != nil {
log.Error().Err(err).Str("packageName", packageName).Msg("app is not in foreground") log.Error().Err(err2).Str("packageName", packageName).Msg("app is not in foreground")
err = errors.Wrap(code.MobileUIAppNotInForegroundError, err.Error()) err = errors.Wrap(code.MobileUIAppNotInForegroundError, err2.Error())
} }
} }
@@ -608,9 +608,9 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
// save attachments // save attachments
cacheData := uiDriver.GetStepCacheData() cacheData := uiDriver.GetStepCacheData()
attachments["screenshots"] = cacheData.ScreenShots for key, value := range cacheData {
attachments["ocr_results"] = cacheData.OcrResults attachments[key] = value
attachments["video_stat"] = cacheData.VideoStat }
stepResult.Attachments = attachments stepResult.Attachments = attachments
}() }()