mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 15:37:35 +08:00
fix: GetStepCacheData
This commit is contained in:
@@ -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
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user