mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-07 08:27:35 +08:00
feat: tap with options for hrp ui server
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0+2411041802
|
v5.0.0+2411041921
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
|
import "github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||||
|
|
||||||
type HttpResponse struct {
|
type HttpResponse struct {
|
||||||
Result interface{} `json:"result,omitempty"`
|
Result interface{} `json:"result,omitempty"`
|
||||||
ErrorCode int `json:"errorCode"`
|
ErrorCode int `json:"errorCode"`
|
||||||
@@ -7,10 +9,12 @@ type HttpResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TapRequest struct {
|
type TapRequest struct {
|
||||||
X float64 `json:"x"`
|
X float64 `json:"x"`
|
||||||
Y float64 `json:"y"`
|
Y float64 `json:"y"`
|
||||||
Duration float64 `json:"duration"`
|
Text string `json:"text"`
|
||||||
Text string `json:"text"`
|
|
||||||
|
Duration float64 `json:"duration"` // move to options
|
||||||
|
Options *uixt.ActionOptions `json:"options,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DragRequest struct {
|
type DragRequest struct {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/rs/zerolog/log"
|
"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/gadb"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||||
)
|
)
|
||||||
@@ -125,14 +126,18 @@ func tapHandler(c *gin.Context) {
|
|||||||
|
|
||||||
dExt := driverObj.(*uixt.DriverExt)
|
dExt := driverObj.(*uixt.DriverExt)
|
||||||
if tapReq.Text != "" {
|
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 {
|
if err != nil {
|
||||||
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to tap text %s", c.HandlerName(), tapReq.Text))
|
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to tap text %s", c.HandlerName(), tapReq.Text))
|
||||||
c.JSON(http.StatusInternalServerError,
|
c.JSON(http.StatusInternalServerError,
|
||||||
HttpResponse{
|
HttpResponse{
|
||||||
Result: false,
|
Result: false,
|
||||||
ErrorCode: InternalServerErrorCode,
|
ErrorCode: code.GetErrorCode(err),
|
||||||
ErrorMsg: InternalServerErrorMsg,
|
ErrorMsg: err.Error(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
c.Abort()
|
c.Abort()
|
||||||
@@ -142,7 +147,13 @@ func tapHandler(c *gin.Context) {
|
|||||||
err := dExt.TapXY(tapReq.X, tapReq.Y, uixt.WithPressDuration(tapReq.Duration))
|
err := dExt.TapXY(tapReq.X, tapReq.Y, uixt.WithPressDuration(tapReq.Duration))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to tap %f, %f", c.HandlerName(), tapReq.X, tapReq.Y))
|
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()
|
c.Abort()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -150,7 +161,13 @@ func tapHandler(c *gin.Context) {
|
|||||||
err := dExt.TapAbsXY(tapReq.X, tapReq.Y, uixt.WithPressDuration(tapReq.Duration))
|
err := dExt.TapAbsXY(tapReq.X, tapReq.Y, uixt.WithPressDuration(tapReq.Duration))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to tap %f, %f", c.HandlerName(), tapReq.X, tapReq.Y))
|
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()
|
c.Abort()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user