mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-09 22:44:05 +08:00
implement TapByUITypes using WithScreenShotUITypes
This commit is contained in:
@@ -547,17 +547,8 @@ func (dExt *DriverExt) DoAction(action MobileAction) (err error) {
|
||||
case ACTION_TapByCV:
|
||||
if imagePath, ok := action.Params.(string); ok {
|
||||
return dExt.TapByCV(imagePath, action.GetOptions()...)
|
||||
}
|
||||
if uiParams, ok := action.Params.([]interface{}); ok {
|
||||
var uiTypes []string
|
||||
for _, uiParam := range uiParams {
|
||||
uiType, ok := uiParam.(string)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
uiTypes = append(uiTypes, uiType)
|
||||
}
|
||||
return dExt.TapByUIDetection(uiTypes, action.Options.Options()...)
|
||||
} else if err := dExt.TapByUIDetection(action.GetOptions()...); err == nil {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("invalid %s params: %v", ACTION_TapByCV, action.Params)
|
||||
case ACTION_DoubleTapXY:
|
||||
|
||||
@@ -478,6 +478,7 @@ func (u UIResults) FilterScope(scope AbsScope) (results UIResults) {
|
||||
|
||||
type UIResultMap map[string]UIResults
|
||||
|
||||
// FilterUIResults filters ui icons, the former the uiTypes, the higher the priority
|
||||
func (u UIResultMap) FilterUIResults(uiTypes []string) (uiResults UIResults, err error) {
|
||||
var ok bool
|
||||
for _, uiType := range uiTypes {
|
||||
@@ -512,20 +513,22 @@ func (u UIResults) GetUIResult(options ...ActionOption) (UIResult, error) {
|
||||
return uiResults[idx], nil
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) FindUIResult(uiTypes []string, options ...ActionOption) (point PointF, err error) {
|
||||
screenResult, err := dExt.GetScreenResult(WithScreenShotUITypes(uiTypes...))
|
||||
func (dExt *DriverExt) FindUIResult(options ...ActionOption) (point PointF, err error) {
|
||||
actionOptions := NewActionOptions(options...)
|
||||
|
||||
screenResult, err := dExt.GetScreenResult(options...)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
uiResults, err := screenResult.Icons.FilterUIResults(uiTypes)
|
||||
uiResults, err := screenResult.Icons.FilterUIResults(actionOptions.ScreenShotWithUITypes)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uiResult, err := uiResults.GetUIResult(dExt.ParseActionOptions(options...)...)
|
||||
point = uiResult.Center()
|
||||
|
||||
log.Info().Interface("text", uiTypes).
|
||||
log.Info().Interface("text", actionOptions.ScreenShotWithUITypes).
|
||||
Interface("point", point).Msg("FindUIResult success")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -49,10 +49,10 @@ func (dExt *DriverExt) TapByCV(imagePath string, options ...ActionOption) error
|
||||
return dExt.TapAbsXY(point.X, point.Y, options...)
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) TapByUIDetection(uiTypes []string, options ...ActionOption) error {
|
||||
func (dExt *DriverExt) TapByUIDetection(options ...ActionOption) error {
|
||||
actionOptions := NewActionOptions(options...)
|
||||
|
||||
point, err := dExt.FindUIResult(uiTypes, options...)
|
||||
point, err := dExt.FindUIResult(options...)
|
||||
if err != nil {
|
||||
if actionOptions.IgnoreNotFoundError {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user