feat: add function call for XTDriver

This commit is contained in:
lilong.129
2025-05-10 09:50:00 +08:00
parent 9bafea53af
commit f6ad6c9eff
4 changed files with 20 additions and 6 deletions

View File

@@ -1 +1 @@
v5.0.0-beta-2505100001
v5.0.0-beta-2505100950

View File

@@ -335,9 +335,10 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
case ACTION_ClosePopups:
return dExt.ClosePopupsHandler()
case ACTION_CallFunction:
fn := action.Fn
fn()
return nil
if funcDesc, ok := action.Params.(string); ok {
return dExt.Call(funcDesc, action.Fn)
}
return fmt.Errorf("invalid function description: %v", action.Params)
case ACTION_AIAction:
if prompt, ok := action.Params.(string); ok {
return dExt.AIAction(prompt, action.GetOptions()...)

View File

@@ -29,7 +29,7 @@ func (dExt *XTDriver) TapByOCR(text string, opts ...option.ActionOption) error {
point = textRect.Center()
}
log.Info().Str("text", text).Interface("rawTextRect", textRect).
Interface("tapPoint", point).Msg("TapByOCR success")
Interface("tapPoint", point).Msg("TapByOCR")
return dExt.TapAbsXY(point.X, point.Y, opts...)
}
@@ -52,7 +52,7 @@ func (dExt *XTDriver) TapByCV(opts ...option.ActionOption) error {
point = uiResult.Center()
}
log.Info().Interface("rawUIResult", uiResult).
Interface("tapPoint", point).Msg("TapByCV success")
Interface("tapPoint", point).Msg("TapByCV")
return dExt.TapAbsXY(point.X, point.Y, opts...)
}

View File

@@ -1,10 +1,23 @@
package uixt
import (
"time"
"github.com/httprunner/httprunner/v5/uixt/option"
"github.com/rs/zerolog/log"
)
// Call custom function, used for pre/post hook for actions
func (dExt *XTDriver) Call(desc string, fn func()) error {
startTime := time.Now()
fn()
log.Info().Str("desc", desc).
Int64("duration(ms)", time.Since(startTime).Milliseconds()).
Msg("function called")
return nil
}
func preHandler_TapAbsXY(driver IDriver, options *option.ActionOptions, rawX, rawY float64) (
x, y float64, err error) {