mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-06 08:19:45 +08:00
feat: tap by ocr and cv
This commit is contained in:
@@ -297,9 +297,9 @@ func (dExt *DriverExt) FindUIRectInUIKit(search string) (x, y, width, height flo
|
||||
return dExt.FindImageRectInUIKit(search)
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) FindImageRectInUIKit(search string) (x, y, width, height float64, err error) {
|
||||
func (dExt *DriverExt) FindImageRectInUIKit(imagePath string) (x, y, width, height float64, err error) {
|
||||
var bufSource, bufSearch *bytes.Buffer
|
||||
if bufSearch, err = getBufFromDisk(search); err != nil {
|
||||
if bufSearch, err = getBufFromDisk(imagePath); err != nil {
|
||||
return 0, 0, 0, 0, err
|
||||
}
|
||||
if bufSource, err = dExt.takeScreenShot(); err != nil {
|
||||
|
||||
@@ -118,7 +118,7 @@ type OCRService interface {
|
||||
FindText(text string, imageBuf []byte) (rect image.Rectangle, err error)
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) FindTextByOCR(search string) (x, y, width, height float64, err error) {
|
||||
func (dExt *DriverExt) FindTextByOCR(ocrText string) (x, y, width, height float64, err error) {
|
||||
var bufSource *bytes.Buffer
|
||||
if bufSource, err = dExt.takeScreenShot(); err != nil {
|
||||
err = fmt.Errorf("screenshot error: %v", err)
|
||||
@@ -126,7 +126,7 @@ func (dExt *DriverExt) FindTextByOCR(search string) (x, y, width, height float64
|
||||
}
|
||||
|
||||
service := &veDEMOCRService{}
|
||||
rect, err := service.FindText(search, bufSource.Bytes())
|
||||
rect, err := service.FindText(ocrText, bufSource.Bytes())
|
||||
if err != nil {
|
||||
err = fmt.Errorf("find text failed: %v", err)
|
||||
return
|
||||
|
||||
@@ -17,6 +17,24 @@ func (dExt *DriverExt) TapXY(x, y float64) error {
|
||||
return dExt.WebDriver.TapFloat(x, y)
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) TapByOCR(ocrText string) error {
|
||||
x, y, width, height, err := dExt.FindTextByOCR(ocrText)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return dExt.WebDriver.TapFloat(x+width*0.5, y+height*0.5)
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) TapByCV(imagePath string) error {
|
||||
x, y, width, height, err := dExt.FindImageRectInUIKit(imagePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return dExt.WebDriver.TapFloat(x+width*0.5, y+height*0.5)
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) Tap(param string) error {
|
||||
return dExt.TapOffset(param, 0.5, 0.5)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user