feat: describe screenshot file name with params

This commit is contained in:
lilong.129
2024-11-13 21:51:43 +08:00
parent 6d514589a0
commit 2a84335910
4 changed files with 30 additions and 12 deletions

View File

@@ -1 +1 @@
v5.0.0+2411132058
v5.0.0+2411132151

View File

@@ -2,6 +2,7 @@ package uixt
import (
"context"
"fmt"
_ "image/gif"
_ "image/png"
@@ -53,19 +54,24 @@ func newDriverExt(device IDevice, driver IWebDriver, options ...DriverOption) (d
}
func (dExt *DriverExt) AssertOCR(text, assert string) bool {
var options []ActionOption
options = append(options, WithScreenShotFileName(fmt.Sprintf("assert_ocr_%s", text)))
var err error
switch assert {
case AssertionEqual:
_, err = dExt.FindScreenText(text)
_, err = dExt.FindScreenText(text, options...)
return err == nil
case AssertionNotEqual:
_, err = dExt.FindScreenText(text)
_, err = dExt.FindScreenText(text, options...)
return err != nil
case AssertionExists:
_, err = dExt.FindScreenText(text, WithRegex(true))
options = append(options, WithRegex(true))
_, err = dExt.FindScreenText(text, options...)
return err == nil
case AssertionNotExists:
_, err = dExt.FindScreenText(text, WithRegex(true))
options = append(options, WithRegex(true))
_, err = dExt.FindScreenText(text, options...)
return err != nil
default:
log.Warn().Str("assert method", assert).Msg("unexpected assert method")

View File

@@ -126,11 +126,13 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S
return screenResult, nil
}
func (dExt *DriverExt) GetScreenTexts() (ocrTexts OCRTexts, err error) {
screenResult, err := dExt.GetScreenResult(
WithScreenShotOCR(true), WithScreenShotUpload(true),
WithScreenShotFileName("get_screen_texts"),
)
func (dExt *DriverExt) GetScreenTexts(options ...ActionOption) (ocrTexts OCRTexts, err error) {
actionOptions := NewActionOptions(options...)
if actionOptions.ScreenShotFileName == "" {
options = append(options, WithScreenShotFileName("get_screen_texts"))
}
options = append(options, WithScreenShotOCR(true), WithScreenShotUpload(true))
screenResult, err := dExt.GetScreenResult(options...)
if err != nil {
return
}
@@ -148,7 +150,11 @@ func (dExt *DriverExt) FindUIRectInUIKit(search string, options ...ActionOption)
}
func (dExt *DriverExt) FindScreenText(text string, options ...ActionOption) (point PointF, err error) {
ocrTexts, err := dExt.GetScreenTexts()
actionOptions := NewActionOptions(options...)
if actionOptions.ScreenShotFileName == "" {
options = append(options, WithScreenShotFileName(fmt.Sprintf("find_screen_text_%s", text)))
}
ocrTexts, err := dExt.GetScreenTexts(options...)
if err != nil {
return
}
@@ -166,8 +172,11 @@ func (dExt *DriverExt) FindScreenText(text string, options ...ActionOption) (poi
}
func (dExt *DriverExt) FindUIResult(options ...ActionOption) (point PointF, err error) {
options = append(options, WithScreenShotFileName("find_ui_result"))
actionOptions := NewActionOptions(options...)
if actionOptions.ScreenShotFileName == "" {
options = append(options, WithScreenShotFileName(
fmt.Sprintf("find_ui_result_%s", strings.Join(actionOptions.ScreenShotWithUITypes, "_"))))
}
screenResult, err := dExt.GetScreenResult(options...)
if err != nil {

View File

@@ -34,6 +34,9 @@ func (dExt *DriverExt) TapXY(x, y float64, options ...ActionOption) error {
func (dExt *DriverExt) TapByOCR(ocrText string, options ...ActionOption) error {
actionOptions := NewActionOptions(options...)
if actionOptions.ScreenShotFileName == "" {
options = append(options, WithScreenShotFileName(fmt.Sprintf("tap_by_ocr_%s", ocrText)))
}
point, err := dExt.FindScreenText(ocrText, options...)
if err != nil {