mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-28 02:51:42 +08:00
refactor: IDriver
This commit is contained in:
@@ -15,7 +15,7 @@ func foregroundAppHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
appInfo, err := dExt.GetForegroundApp()
|
||||
appInfo, err := dExt.ForegroundInfo()
|
||||
if err != nil {
|
||||
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to unlick screen", c.HandlerName()))
|
||||
c.JSON(http.StatusInternalServerError,
|
||||
|
||||
@@ -38,7 +38,7 @@ func sourceHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
app, err := dExt.GetForegroundApp()
|
||||
app, err := dExt.ForegroundInfo()
|
||||
if err != nil {
|
||||
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to get foreground app", c.HandlerName()))
|
||||
c.JSON(http.StatusInternalServerError,
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/httprunner/httprunner/v5/code"
|
||||
"github.com/httprunner/httprunner/v5/pkg/uixt"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/code"
|
||||
)
|
||||
|
||||
func unlockHandler(c *gin.Context) {
|
||||
@@ -37,7 +37,7 @@ func homeHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err = dExt.Homescreen()
|
||||
err = dExt.Home()
|
||||
if err != nil {
|
||||
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to enter homescreen", c.HandlerName()))
|
||||
c.JSON(http.StatusInternalServerError,
|
||||
@@ -51,30 +51,3 @@ func homeHandler(c *gin.Context) {
|
||||
}
|
||||
c.JSON(http.StatusOK, HttpResponse{Code: 0, Message: "success"})
|
||||
}
|
||||
|
||||
func keycodeHandler(c *gin.Context) {
|
||||
dExt, err := GetContextDriver(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var keycodeReq KeycodeRequest
|
||||
if err := c.ShouldBindJSON(&keycodeReq); err != nil {
|
||||
handlerValidateRequestFailedContext(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = dExt.PressKeyCode(uixt.KeyCode(keycodeReq.Keycode))
|
||||
if err != nil {
|
||||
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to input keycode %d", c.HandlerName(), keycodeReq.Keycode))
|
||||
c.JSON(http.StatusInternalServerError,
|
||||
HttpResponse{
|
||||
Code: code.GetErrorCode(err),
|
||||
Message: err.Error(),
|
||||
},
|
||||
)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, HttpResponse{Code: 0, Message: "success"})
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ func (r *Router) Init() {
|
||||
// Key operations
|
||||
apiV1PlatformSerial.POST("/key/unlock", r.HandleDeviceContext(), unlockHandler)
|
||||
apiV1PlatformSerial.POST("/key/home", r.HandleDeviceContext(), homeHandler)
|
||||
apiV1PlatformSerial.POST("/key", r.HandleDeviceContext(), keycodeHandler)
|
||||
// App operations
|
||||
apiV1PlatformSerial.GET("/app/foreground", r.HandleDeviceContext(), foregroundAppHandler)
|
||||
apiV1PlatformSerial.POST("/app/clear", r.HandleDeviceContext(), clearAppHandler)
|
||||
|
||||
@@ -140,7 +140,7 @@ func inputHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err = dExt.SendKeys(inputReq.Text,
|
||||
err = dExt.Input(inputReq.Text,
|
||||
option.WithFrequency(inputReq.Frequency))
|
||||
if err != nil {
|
||||
log.Err(err).Msg(fmt.Sprintf("[%s]: failed to input text %s", c.HandlerName(), inputReq.Text))
|
||||
|
||||
Reference in New Issue
Block a user