feat: GetScreenResult with ScreenShotFileName option

This commit is contained in:
lilong.129
2024-11-13 20:25:44 +08:00
parent f469ddc1d1
commit d8eb10808f
5 changed files with 34 additions and 8 deletions
+1 -1
View File
@@ -1 +1 @@
v5.0.0+2411131451 v5.0.0+2411132025
+10
View File
@@ -136,6 +136,7 @@ type ActionOptions struct {
ScreenShotWithUITypes []string `json:"screenshot_with_ui_types,omitempty" yaml:"screenshot_with_ui_types,omitempty"` ScreenShotWithUITypes []string `json:"screenshot_with_ui_types,omitempty" yaml:"screenshot_with_ui_types,omitempty"`
ScreenShotWithClosePopups bool `json:"screenshot_with_close_popups,omitempty" yaml:"screenshot_with_close_popups,omitempty"` ScreenShotWithClosePopups bool `json:"screenshot_with_close_popups,omitempty" yaml:"screenshot_with_close_popups,omitempty"`
ScreenShotWithOCRCluster string `json:"screenshot_with_ocr_cluster,omitempty" yaml:"screenshot_with_ocr_cluster,omitempty"` ScreenShotWithOCRCluster string `json:"screenshot_with_ocr_cluster,omitempty" yaml:"screenshot_with_ocr_cluster,omitempty"`
ScreenShotFileName string `json:"screenshot_file_name,omitempty" yaml:"screenshot_file_name,omitempty"`
} }
func (o *ActionOptions) Options() []ActionOption { func (o *ActionOptions) Options() []ActionOption {
@@ -251,6 +252,9 @@ func (o *ActionOptions) Options() []ActionOption {
if o.ScreenShotWithOCRCluster != "" { if o.ScreenShotWithOCRCluster != "" {
options = append(options, WithScreenOCRCluster(o.ScreenShotWithOCRCluster)) options = append(options, WithScreenOCRCluster(o.ScreenShotWithOCRCluster))
} }
if o.ScreenShotFileName != "" {
options = append(options, WithScreenShotFileName(o.ScreenShotFileName))
}
return options return options
} }
@@ -519,6 +523,12 @@ func WithScreenOCRCluster(ocrCluster string) ActionOption {
} }
} }
func WithScreenShotFileName(fileName string) ActionOption {
return func(o *ActionOptions) {
o.ScreenShotFileName = fileName
}
}
func (dExt *DriverExt) ParseActionOptions(options ...ActionOption) []ActionOption { func (dExt *DriverExt) ParseActionOptions(options ...ActionOption) []ActionOption {
actionOptions := NewActionOptions(options...) actionOptions := NewActionOptions(options...)
+5 -1
View File
@@ -63,7 +63,10 @@ func (dExt *DriverExt) AutoPopupHandler() error {
// check popup by screenshot // check popup by screenshot
screenResult, err := dExt.GetScreenResult( screenResult, err := dExt.GetScreenResult(
WithScreenShotOCR(true), WithScreenShotUpload(true)) WithScreenShotOCR(true),
WithScreenShotUpload(true),
WithScreenShotFileName("check_popup"),
)
if err != nil { if err != nil {
return errors.Wrap(err, "get screen result failed for popup handler") return errors.Wrap(err, "get screen result failed for popup handler")
} }
@@ -97,6 +100,7 @@ func (dExt *DriverExt) CheckPopup() (popup *PopupInfo, err error) {
screenResult, err := dExt.GetScreenResult( screenResult, err := dExt.GetScreenResult(
WithScreenShotUpload(true), WithScreenShotUpload(true),
WithScreenShotClosePopups(true), // get popup area and close area WithScreenShotClosePopups(true), // get popup area and close area
WithScreenShotFileName("check_popup"),
) )
if err != nil { if err != nil {
return nil, errors.Wrap(err, "get screen result failed for popup handler") return nil, errors.Wrap(err, "get screen result failed for popup handler")
+14 -6
View File
@@ -36,16 +36,21 @@ type ScreenResultMap map[string]*ScreenResult // key is date time
// GetScreenResult takes a screenshot, returns the image recognition result // GetScreenResult takes a screenshot, returns the image recognition result
func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *ScreenResult, err error) { func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *ScreenResult, err error) {
fileName := builtin.GenNameWithTimestamp("%d_screenshot")
actionOptions := NewActionOptions(options...) actionOptions := NewActionOptions(options...)
screenshotActions := actionOptions.screenshotActions()
if len(screenshotActions) != 0 {
fileName = builtin.GenNameWithTimestamp("%d_" + strings.Join(screenshotActions, "_"))
}
if actionOptions.MaxRetryTimes == 0 { if actionOptions.MaxRetryTimes == 0 {
actionOptions.MaxRetryTimes = 1 actionOptions.MaxRetryTimes = 1
} }
var fileName string
screenshotActions := actionOptions.screenshotActions()
if actionOptions.ScreenShotFileName != "" {
fileName = builtin.GenNameWithTimestamp("%d_" + actionOptions.ScreenShotFileName)
} else if len(screenshotActions) != 0 {
fileName = builtin.GenNameWithTimestamp("%d_" + strings.Join(screenshotActions, "_"))
} else {
fileName = builtin.GenNameWithTimestamp("%d_screenshot")
}
var bufSource *bytes.Buffer var bufSource *bytes.Buffer
var imageResult *ImageResult var imageResult *ImageResult
var imagePath string var imagePath string
@@ -123,7 +128,9 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S
func (dExt *DriverExt) GetScreenTexts() (ocrTexts OCRTexts, err error) { func (dExt *DriverExt) GetScreenTexts() (ocrTexts OCRTexts, err error) {
screenResult, err := dExt.GetScreenResult( screenResult, err := dExt.GetScreenResult(
WithScreenShotOCR(true), WithScreenShotUpload(true)) WithScreenShotOCR(true), WithScreenShotUpload(true),
WithScreenShotFileName("get_screen_texts"),
)
if err != nil { if err != nil {
return return
} }
@@ -159,6 +166,7 @@ func (dExt *DriverExt) FindScreenText(text string, options ...ActionOption) (poi
} }
func (dExt *DriverExt) FindUIResult(options ...ActionOption) (point PointF, err error) { func (dExt *DriverExt) FindUIResult(options ...ActionOption) (point PointF, err error) {
options = append(options, WithScreenShotFileName("find_ui_result"))
actionOptions := NewActionOptions(options...) actionOptions := NewActionOptions(options...)
screenResult, err := dExt.GetScreenResult(options...) screenResult, err := dExt.GetScreenResult(options...)
+4
View File
@@ -2,6 +2,7 @@ package uixt
import ( import (
"fmt" "fmt"
"strings"
"time" "time"
"github.com/pkg/errors" "github.com/pkg/errors"
@@ -151,6 +152,9 @@ func (dExt *DriverExt) swipeToTapTexts(texts []string, options ...ActionOption)
screenResult, err := d.GetScreenResult( screenResult, err := d.GetScreenResult(
WithScreenShotOCR(true), WithScreenShotOCR(true),
WithScreenShotUpload(true), WithScreenShotUpload(true),
WithScreenShotFileName(
fmt.Sprintf("swipe_to_tap_texts_%s", strings.Join(texts, "_")),
),
) )
if err != nil { if err != nil {
return err return err