mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-11 18:11:21 +08:00
fix: tap handler
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0+2503042003
|
v5.0.0+2503042040
|
||||||
|
|||||||
@@ -7,9 +7,6 @@ type ILLMService interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewGPT4oLLMService() (*openaiLLMService, error) {
|
func NewGPT4oLLMService() (*openaiLLMService, error) {
|
||||||
if err := checkEnv(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &openaiLLMService{}, nil
|
return &openaiLLMService{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ type IDriver interface {
|
|||||||
Unlock() error
|
Unlock() error
|
||||||
Back() error
|
Back() error
|
||||||
// tap
|
// tap
|
||||||
TapXY(x, y float64, opts ...option.ActionOption) error // by percentage
|
TapXY(x, y float64, opts ...option.ActionOption) error // by percentage or absolute coordinate
|
||||||
TapAbsXY(x, y float64, opts ...option.ActionOption) error // by absolute coordinate
|
TapAbsXY(x, y float64, opts ...option.ActionOption) error // by absolute coordinate
|
||||||
DoubleTap(x, y float64, opts ...option.ActionOption) error // by absolute coordinate
|
DoubleTap(x, y float64, opts ...option.ActionOption) error // by absolute coordinate
|
||||||
TouchAndHold(x, y float64, opts ...option.ActionOption) error
|
TouchAndHold(x, y float64, opts ...option.ActionOption) error
|
||||||
|
|||||||
@@ -15,14 +15,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (r *Router) GetDriver(c *gin.Context) (driverExt *uixt.XTDriver, err error) {
|
func (r *Router) GetDriver(c *gin.Context) (driverExt *uixt.XTDriver, err error) {
|
||||||
driverObj, exists := c.Get("driver")
|
|
||||||
if exists {
|
|
||||||
return driverObj.(*uixt.XTDriver), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
deviceObj, exists := c.Get("device")
|
|
||||||
var device uixt.IDevice
|
var device uixt.IDevice
|
||||||
var driver uixt.IDriver
|
var driver uixt.IDriver
|
||||||
|
deviceObj, exists := c.Get("device")
|
||||||
if !exists {
|
if !exists {
|
||||||
device, err = r.GetDevice(c)
|
device, err = r.GetDevice(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -12,14 +12,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (r *RouterExt) GetDriver(c *gin.Context) (driverExt *driver_ext.StubXTDriver, err error) {
|
func (r *RouterExt) GetDriver(c *gin.Context) (driverExt *driver_ext.StubXTDriver, err error) {
|
||||||
driverObj, exists := c.Get("driver")
|
|
||||||
if exists {
|
|
||||||
return driverObj.(*driver_ext.StubXTDriver), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
deviceObj, exists := c.Get("device")
|
|
||||||
var device uixt.IDevice
|
var device uixt.IDevice
|
||||||
var driver driver_ext.IStubDriver
|
var driver driver_ext.IStubDriver
|
||||||
|
deviceObj, exists := c.Get("device")
|
||||||
if !exists {
|
if !exists {
|
||||||
device, err = r.GetDevice(c)
|
device, err = r.GetDevice(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func (r *Router) tapHandler(c *gin.Context) {
|
|||||||
err = driver.Drag(tapReq.X, tapReq.Y, tapReq.X, tapReq.Y,
|
err = driver.Drag(tapReq.X, tapReq.Y, tapReq.X, tapReq.Y,
|
||||||
option.WithDuration(tapReq.Duration))
|
option.WithDuration(tapReq.Duration))
|
||||||
} else {
|
} else {
|
||||||
err = driver.TapAbsXY(tapReq.X, tapReq.Y)
|
err = driver.TapXY(tapReq.X, tapReq.Y)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
RenderError(c, err)
|
RenderError(c, err)
|
||||||
|
|||||||
73
server/ui_test.go
Normal file
73
server/ui_test.go
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTapHandler(t *testing.T) {
|
||||||
|
router := NewRouter()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
path string
|
||||||
|
tapReq TapRequest
|
||||||
|
wantStatus int
|
||||||
|
wantResp HttpResponse
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "tap abs xy",
|
||||||
|
path: fmt.Sprintf("/api/v1/android/%s/ui/tap", "4622ca24"),
|
||||||
|
tapReq: TapRequest{
|
||||||
|
X: 500,
|
||||||
|
Y: 800,
|
||||||
|
Duration: 0,
|
||||||
|
},
|
||||||
|
wantStatus: http.StatusOK,
|
||||||
|
wantResp: HttpResponse{
|
||||||
|
Code: 0,
|
||||||
|
Message: "success",
|
||||||
|
Result: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "tap relative xy",
|
||||||
|
path: fmt.Sprintf("/api/v1/android/%s/ui/tap", "4622ca24"),
|
||||||
|
tapReq: TapRequest{
|
||||||
|
X: 0.5,
|
||||||
|
Y: 0.6,
|
||||||
|
Duration: 0,
|
||||||
|
},
|
||||||
|
wantStatus: http.StatusOK,
|
||||||
|
wantResp: HttpResponse{
|
||||||
|
Code: 0,
|
||||||
|
Message: "success",
|
||||||
|
Result: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
reqBody, _ := json.Marshal(tt.tapReq)
|
||||||
|
req := httptest.NewRequest(http.MethodPost, tt.path, bytes.NewBuffer(reqBody))
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
router.ServeHTTP(w, req)
|
||||||
|
|
||||||
|
assert.Equal(t, tt.wantStatus, w.Code)
|
||||||
|
|
||||||
|
var got HttpResponse
|
||||||
|
err := json.Unmarshal(w.Body.Bytes(), &got)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, tt.wantResp, got)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user