mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-22 00:29:37 +08:00
refactor: complete ActionOptions unification and pointer type optimization
This commit is contained in:
@@ -22,7 +22,7 @@ func (r *Router) foregroundAppHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (r *Router) appInfoHandler(c *gin.Context) {
|
||||
var req option.UnifiedActionRequest
|
||||
var req option.ActionOptions
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
RenderErrorValidateRequest(c, err)
|
||||
return
|
||||
|
||||
@@ -39,7 +39,7 @@ func (r *Router) backspaceHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
count := req.GetCount()
|
||||
count := req.Count
|
||||
if count == 0 {
|
||||
count = 20
|
||||
}
|
||||
@@ -67,7 +67,7 @@ func (r *Router) keycodeHandler(c *gin.Context) {
|
||||
}
|
||||
// TODO FIXME
|
||||
err = driver.IDriver.(*uixt.ADBDriver).
|
||||
PressKeyCode(uixt.KeyCode(req.GetKeycode()), uixt.KMEmpty)
|
||||
PressKeyCode(uixt.KeyCode(req.Keycode), uixt.KMEmpty)
|
||||
if err != nil {
|
||||
RenderError(c, err)
|
||||
return
|
||||
|
||||
31
server/ui.go
31
server/ui.go
@@ -7,8 +7,8 @@ import (
|
||||
)
|
||||
|
||||
// processUnifiedRequest is a helper function to handle common request processing
|
||||
func (r *Router) processUnifiedRequest(c *gin.Context, actionType option.ActionMethod) (*option.UnifiedActionRequest, error) {
|
||||
var req option.UnifiedActionRequest
|
||||
func (r *Router) processUnifiedRequest(c *gin.Context, actionType option.ActionName) (*option.ActionOptions, error) {
|
||||
var req option.ActionOptions
|
||||
|
||||
// Bind JSON request
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -29,7 +29,7 @@ func (r *Router) processUnifiedRequest(c *gin.Context, actionType option.ActionM
|
||||
}
|
||||
|
||||
// setRequestContextFromURL sets platform and serial from URL parameters
|
||||
func setRequestContextFromURL(c *gin.Context, req *option.UnifiedActionRequest) {
|
||||
func setRequestContextFromURL(c *gin.Context, req *option.ActionOptions) {
|
||||
if req.Platform == "" {
|
||||
req.Platform = c.Param("platform")
|
||||
}
|
||||
@@ -49,12 +49,11 @@ func (r *Router) tapHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Use UnifiedActionRequest directly
|
||||
if req.GetDuration() > 0 {
|
||||
err = driver.Drag(req.GetX(), req.GetY(), req.GetX(), req.GetY(),
|
||||
option.WithDuration(req.GetDuration()))
|
||||
if req.Duration > 0 {
|
||||
err = driver.Drag(req.X, req.Y, req.X, req.Y,
|
||||
option.WithDuration(req.Duration))
|
||||
} else {
|
||||
err = driver.TapXY(req.GetX(), req.GetY())
|
||||
err = driver.TapXY(req.X, req.Y)
|
||||
}
|
||||
if err != nil {
|
||||
RenderError(c, err)
|
||||
@@ -74,7 +73,7 @@ func (r *Router) rightClickHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
err = driver.IDriver.(*uixt.BrowserDriver).
|
||||
SecondaryClick(req.GetX(), req.GetY())
|
||||
SecondaryClick(req.X, req.Y)
|
||||
if err != nil {
|
||||
RenderError(c, err)
|
||||
return
|
||||
@@ -117,7 +116,7 @@ func (r *Router) hoverHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
err = driver.IDriver.(*uixt.BrowserDriver).
|
||||
Hover(req.GetX(), req.GetY())
|
||||
Hover(req.X, req.Y)
|
||||
|
||||
if err != nil {
|
||||
RenderError(c, err)
|
||||
@@ -139,7 +138,7 @@ func (r *Router) scrollHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
err = driver.IDriver.(*uixt.BrowserDriver).
|
||||
Scroll(req.GetDelta())
|
||||
Scroll(req.Delta)
|
||||
|
||||
if err != nil {
|
||||
RenderError(c, err)
|
||||
@@ -159,7 +158,7 @@ func (r *Router) doubleTapHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err = driver.DoubleTap(req.GetX(), req.GetY())
|
||||
err = driver.DoubleTap(req.X, req.Y)
|
||||
if err != nil {
|
||||
RenderError(c, err)
|
||||
return
|
||||
@@ -173,7 +172,7 @@ func (r *Router) dragHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
duration := req.GetDuration()
|
||||
duration := req.Duration
|
||||
if duration == 0 {
|
||||
duration = 1
|
||||
}
|
||||
@@ -182,9 +181,9 @@ func (r *Router) dragHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err = driver.Drag(req.GetFromX(), req.GetFromY(), req.GetToX(), req.GetToY(),
|
||||
err = driver.Drag(req.FromX, req.FromY, req.ToX, req.ToY,
|
||||
option.WithDuration(duration),
|
||||
option.WithPressDuration(req.GetPressDuration()))
|
||||
option.WithPressDuration(req.PressDuration))
|
||||
if err != nil {
|
||||
RenderError(c, err)
|
||||
return
|
||||
@@ -202,7 +201,7 @@ func (r *Router) inputHandler(c *gin.Context) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = driver.Input(req.Text, option.WithFrequency(req.GetFrequency()))
|
||||
err = driver.Input(req.Text, option.WithFrequency(req.Frequency))
|
||||
if err != nil {
|
||||
RenderError(c, err)
|
||||
return
|
||||
|
||||
@@ -18,17 +18,17 @@ func TestTapHandler(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
path string
|
||||
req option.UnifiedActionRequest
|
||||
req option.ActionOptions
|
||||
wantStatus int
|
||||
wantResp HttpResponse
|
||||
}{
|
||||
{
|
||||
name: "tap abs xy",
|
||||
path: fmt.Sprintf("/api/v1/android/%s/ui/tap", "4622ca24"),
|
||||
req: option.UnifiedActionRequest{
|
||||
X: &[]float64{500}[0],
|
||||
Y: &[]float64{800}[0],
|
||||
Duration: &[]float64{0}[0],
|
||||
req: option.ActionOptions{
|
||||
X: 500.0,
|
||||
Y: 800.0,
|
||||
Duration: 0,
|
||||
},
|
||||
wantStatus: http.StatusOK,
|
||||
wantResp: HttpResponse{
|
||||
@@ -40,10 +40,10 @@ func TestTapHandler(t *testing.T) {
|
||||
{
|
||||
name: "tap relative xy",
|
||||
path: fmt.Sprintf("/api/v1/android/%s/ui/tap", "4622ca24"),
|
||||
req: option.UnifiedActionRequest{
|
||||
X: &[]float64{0.5}[0],
|
||||
Y: &[]float64{0.6}[0],
|
||||
Duration: &[]float64{0}[0],
|
||||
req: option.ActionOptions{
|
||||
X: 0.5,
|
||||
Y: 0.6,
|
||||
Duration: 0,
|
||||
},
|
||||
wantStatus: http.StatusOK,
|
||||
wantResp: HttpResponse{
|
||||
|
||||
Reference in New Issue
Block a user