refactor: remove opencv

This commit is contained in:
lilong.129
2024-08-31 01:13:08 +08:00
parent 3186e353a5
commit 3e17d48e5a
9 changed files with 4 additions and 861 deletions

View File

@@ -20,33 +20,10 @@ import (
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/httprunner/httprunner/v4/hrp/code"
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
"github.com/httprunner/httprunner/v4/hrp/internal/env"
)
// TemplateMatchMode is the type of the template matching operation.
type TemplateMatchMode int
type CVArgs struct {
matchMode TemplateMatchMode
threshold float64
}
type CVOption func(*CVArgs)
func WithTemplateMatchMode(mode TemplateMatchMode) CVOption {
return func(args *CVArgs) {
args.matchMode = mode
}
}
func WithThreshold(threshold float64) CVOption {
return func(args *CVArgs) {
args.threshold = threshold
}
}
type cacheStepData struct {
// cache step screenshot paths
screenShots []string
@@ -63,7 +40,6 @@ func (d *cacheStepData) reset() {
}
type DriverExt struct {
CVArgs
Device Device
Driver WebDriver
WindowSize Size
@@ -93,12 +69,6 @@ func newDriverExt(device Device, driver WebDriver, options ...DriverOption) (dEx
interruptSignal: make(chan os.Signal, 1),
}
err = dExt.extendCV()
if err != nil {
return nil, errors.Wrap(code.MobileUIDriverError,
fmt.Sprintf("extend OpenCV failed: %v", err))
}
dExt.cacheStepData.reset()
signal.Notify(dExt.interruptSignal, syscall.SIGTERM, syscall.SIGINT)
dExt.doneMjpegStream = make(chan bool, 1)
@@ -218,8 +188,8 @@ func (dExt *DriverExt) FindUIRectInUIKit(search string, options ...ActionOption)
if !isPathExists(search) {
return dExt.FindScreenText(search, options...)
}
// click on image, using opencv
return dExt.FindImageRectInUIKit(search, options...)
err = errors.New("ocr text not found")
return
}
func (dExt *DriverExt) AssertOCR(text, assert string) bool {
@@ -243,21 +213,6 @@ func (dExt *DriverExt) AssertOCR(text, assert string) bool {
return false
}
func (dExt *DriverExt) AssertImage(imagePath, assert string) bool {
var err error
switch assert {
case AssertionExists:
_, err = dExt.FindImageRectInUIKit(imagePath)
return err == nil
case AssertionNotExists:
_, err = dExt.FindImageRectInUIKit(imagePath)
return err != nil
default:
log.Warn().Str("assert method", assert).Msg("unexpected assert method")
}
return false
}
func (dExt *DriverExt) AssertForegroundApp(appName, assert string) bool {
app, err := dExt.Driver.GetForegroundApp()
if err != nil {
@@ -283,8 +238,6 @@ func (dExt *DriverExt) DoValidation(check, assert, expected string, message ...s
switch check {
case SelectorOCR:
result = dExt.AssertOCR(expected, assert)
case SelectorImage:
result = dExt.AssertImage(expected, assert)
case SelectorForegroundApp:
result = dExt.AssertForegroundApp(expected, assert)
}