mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-07 08:12:41 +08:00
refactor: simplify APIs, remove GetUIResultMap
This commit is contained in:
@@ -54,11 +54,13 @@ type ScreenResult struct {
|
||||
bufSource *bytes.Buffer // raw image buffer bytes
|
||||
imagePath string // image file path
|
||||
|
||||
Texts OCRTexts `json:"texts"` // dumped raw OCRTexts
|
||||
Tags []string `json:"tags"` // tags for image, e.g. ["feed", "ad", "live"]
|
||||
VideoType string `json:"video_type,omitempty"` // video type: feed, live-preview or live
|
||||
Feed *FeedVideo `json:"feed,omitempty"`
|
||||
Live *LiveRoom `json:"live,omitempty"`
|
||||
UploadedURL string `json:"uploaded_url"` // uploaded image url
|
||||
Texts OCRTexts `json:"texts"` // dumped raw OCRTexts
|
||||
Icons UIResultMap `json:"icons"` // CV 识别的图标
|
||||
Tags []string `json:"tags"` // tags for image, e.g. ["feed", "ad", "live"]
|
||||
VideoType string `json:"video_type,omitempty"` // video type: feed, live-preview or live
|
||||
Feed *FeedVideo `json:"feed,omitempty"`
|
||||
Live *LiveRoom `json:"live,omitempty"`
|
||||
|
||||
SwipeStartTime int64 `json:"swipe_start_time"` // 滑动开始时间戳
|
||||
SwipeFinishTime int64 `json:"swipe_finish_time"` // 滑动结束时间戳
|
||||
@@ -72,8 +74,7 @@ type ScreenResult struct {
|
||||
|
||||
type cacheStepData struct {
|
||||
// cache step screenshot paths
|
||||
screenShots []string
|
||||
screenShotsUrls map[string]string // map screenshot file path to uploaded url
|
||||
screenShots []string
|
||||
// cache step screenshot ocr results, key is image path, value is ScreenResult
|
||||
screenResults map[string]*ScreenResult
|
||||
// cache feed/live video stat
|
||||
@@ -82,7 +83,6 @@ type cacheStepData struct {
|
||||
|
||||
func (d *cacheStepData) reset() {
|
||||
d.screenShots = make([]string, 0)
|
||||
d.screenShotsUrls = make(map[string]string)
|
||||
d.screenResults = make(map[string]*ScreenResult)
|
||||
d.videoCrawler = nil
|
||||
}
|
||||
@@ -222,7 +222,15 @@ func (dExt *DriverExt) GetStepCacheData() map[string]interface{} {
|
||||
cacheData := make(map[string]interface{})
|
||||
cacheData["video_stat"] = dExt.cacheStepData.videoCrawler
|
||||
cacheData["screenshots"] = dExt.cacheStepData.screenShots
|
||||
cacheData["screenshots_urls"] = dExt.cacheStepData.screenShotsUrls
|
||||
|
||||
screenShotsUrls := make(map[string]string)
|
||||
for imagePath, screenResult := range dExt.cacheStepData.screenResults {
|
||||
if screenResult.UploadedURL == "" {
|
||||
continue
|
||||
}
|
||||
screenShotsUrls[imagePath] = screenResult.UploadedURL
|
||||
}
|
||||
cacheData["screenshots_urls"] = screenShotsUrls
|
||||
|
||||
screenSize, err := dExt.Driver.WindowSize()
|
||||
if err != nil {
|
||||
|
||||
@@ -353,7 +353,6 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S
|
||||
ScreenshotTakeElapsed: screenshotTakeElapsed,
|
||||
}
|
||||
|
||||
var imageUrl string
|
||||
imageResult, err := dExt.ImageService.GetImage(bufSource, options...)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("GetImage from ImageService failed")
|
||||
@@ -362,11 +361,8 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S
|
||||
if imageResult != nil {
|
||||
screenResult.ScreenshotCVElapsed = time.Since(startTime).Milliseconds() - screenshotTakeElapsed
|
||||
screenResult.Texts = imageResult.OCRResult.ToOCRTexts()
|
||||
|
||||
imageUrl = imageResult.URL
|
||||
if imageUrl != "" {
|
||||
dExt.cacheStepData.screenShotsUrls[imagePath] = imageUrl
|
||||
}
|
||||
screenResult.UploadedURL = imageResult.URL
|
||||
screenResult.Icons = imageResult.UIResult
|
||||
|
||||
if imageResult.LiveType != "" && imageResult.LiveType != "NoLive" {
|
||||
screenResult.Live = &LiveRoom{
|
||||
@@ -379,7 +375,7 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S
|
||||
|
||||
log.Debug().
|
||||
Str("imagePath", imagePath).
|
||||
Str("imageUrl", imageUrl).
|
||||
Str("imageUrl", screenResult.UploadedURL).
|
||||
Int64("screenshot_take_elapsed(ms)", screenResult.ScreenshotTakeElapsed).
|
||||
Int64("screenshot_cv_elapsed(ms)", screenResult.ScreenshotCVElapsed).
|
||||
Msg("log screenshot")
|
||||
@@ -506,36 +502,13 @@ func (u UIResults) GetUIResult(options ...ActionOption) (UIResult, error) {
|
||||
return uiResults[idx], nil
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) GetUIResultMap(uiTypes []string) (uiResultMap UIResultMap, err error) {
|
||||
screenResult, err := dExt.GetScreenResult()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bufSource := screenResult.bufSource
|
||||
imagePath := screenResult.imagePath
|
||||
|
||||
imageResult, err := dExt.ImageService.GetImage(bufSource,
|
||||
WithScreenShotUITypes(uiTypes...)) // turn on UI type detection
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("GetImage from ImageService failed")
|
||||
return
|
||||
}
|
||||
|
||||
imageUrl := imageResult.URL
|
||||
if imageUrl != "" {
|
||||
dExt.cacheStepData.screenShotsUrls[imagePath] = imageUrl
|
||||
log.Debug().Str("imagePath", imagePath).Str("imageUrl", imageUrl).Msg("log screenshot")
|
||||
}
|
||||
uiResultMap = imageResult.UIResult
|
||||
return
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) FindUIResult(uiTypes []string, options ...ActionOption) (point PointF, err error) {
|
||||
uiResultMap, err := dExt.GetUIResultMap(uiTypes)
|
||||
screenResult, err := dExt.GetScreenResult(WithScreenShotUITypes(uiTypes...))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uiResults, err := uiResultMap.FilterUIResults(uiTypes)
|
||||
|
||||
uiResults, err := screenResult.Icons.FilterUIResults(uiTypes)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user