From dd247815bdfdc316ef5e2c5c66851a10d04418fa Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Mon, 4 Nov 2024 19:21:23 +0800 Subject: [PATCH] feat: tap with options for hrp ui server --- hrp/internal/version/VERSION | 2 +- hrp/pkg/server/model.go | 12 ++++++++---- hrp/pkg/server/server.go | 27 ++++++++++++++++++++++----- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/hrp/internal/version/VERSION b/hrp/internal/version/VERSION index 80bd4acb..0aeec38a 100644 --- a/hrp/internal/version/VERSION +++ b/hrp/internal/version/VERSION @@ -1 +1 @@ -v5.0.0+2411041802 +v5.0.0+2411041921 diff --git a/hrp/pkg/server/model.go b/hrp/pkg/server/model.go index 3a1abfc5..003c2ddd 100644 --- a/hrp/pkg/server/model.go +++ b/hrp/pkg/server/model.go @@ -1,5 +1,7 @@ package server +import "github.com/httprunner/httprunner/v4/hrp/pkg/uixt" + type HttpResponse struct { Result interface{} `json:"result,omitempty"` ErrorCode int `json:"errorCode"` @@ -7,10 +9,12 @@ type HttpResponse struct { } type TapRequest struct { - X float64 `json:"x"` - Y float64 `json:"y"` - Duration float64 `json:"duration"` - Text string `json:"text"` + X float64 `json:"x"` + Y float64 `json:"y"` + Text string `json:"text"` + + Duration float64 `json:"duration"` // move to options + Options *uixt.ActionOptions `json:"options,omitempty"` } type DragRequest struct { diff --git a/hrp/pkg/server/server.go b/hrp/pkg/server/server.go index ac8db0ea..e9b67670 100644 --- a/hrp/pkg/server/server.go +++ b/hrp/pkg/server/server.go @@ -9,6 +9,7 @@ import ( "github.com/gin-gonic/gin" "github.com/rs/zerolog/log" + "github.com/httprunner/httprunner/v4/hrp/code" "github.com/httprunner/httprunner/v4/hrp/pkg/gadb" "github.com/httprunner/httprunner/v4/hrp/pkg/uixt" ) @@ -125,14 +126,18 @@ func tapHandler(c *gin.Context) { dExt := driverObj.(*uixt.DriverExt) if tapReq.Text != "" { - err := dExt.TapByOCR(tapReq.Text, uixt.WithPressDuration(tapReq.Duration)) + var actionOptions []uixt.ActionOption + if tapReq.Options != nil { + actionOptions = tapReq.Options.Options() + } + err := dExt.TapByOCR(tapReq.Text, actionOptions...) if err != nil { log.Err(err).Msg(fmt.Sprintf("[%s]: failed to tap text %s", c.HandlerName(), tapReq.Text)) c.JSON(http.StatusInternalServerError, HttpResponse{ Result: false, - ErrorCode: InternalServerErrorCode, - ErrorMsg: InternalServerErrorMsg, + ErrorCode: code.GetErrorCode(err), + ErrorMsg: err.Error(), }, ) c.Abort() @@ -142,7 +147,13 @@ func tapHandler(c *gin.Context) { err := dExt.TapXY(tapReq.X, tapReq.Y, uixt.WithPressDuration(tapReq.Duration)) if err != nil { log.Err(err).Msg(fmt.Sprintf("[%s]: failed to tap %f, %f", c.HandlerName(), tapReq.X, tapReq.Y)) - c.JSON(http.StatusInternalServerError, HttpResponse{Result: false, ErrorCode: InternalServerErrorCode, ErrorMsg: InternalServerErrorMsg}) + c.JSON(http.StatusInternalServerError, + HttpResponse{ + Result: false, + ErrorCode: code.GetErrorCode(err), + ErrorMsg: err.Error(), + }, + ) c.Abort() return } @@ -150,7 +161,13 @@ func tapHandler(c *gin.Context) { err := dExt.TapAbsXY(tapReq.X, tapReq.Y, uixt.WithPressDuration(tapReq.Duration)) if err != nil { log.Err(err).Msg(fmt.Sprintf("[%s]: failed to tap %f, %f", c.HandlerName(), tapReq.X, tapReq.Y)) - c.JSON(http.StatusInternalServerError, HttpResponse{Result: false, ErrorCode: InternalServerErrorCode, ErrorMsg: InternalServerErrorMsg}) + c.JSON(http.StatusInternalServerError, + HttpResponse{ + Result: false, + ErrorCode: code.GetErrorCode(err), + ErrorMsg: err.Error(), + }, + ) c.Abort() return }