mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-28 02:51:42 +08:00
refactor: move uixt ext to EvalTools
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
package server_ext
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/server"
|
||||
"github.com/httprunner/httprunner/v5/uixt"
|
||||
)
|
||||
|
||||
func (r *RouterExt) installAppHandler(c *gin.Context) {
|
||||
var appInstallReq AppInstallRequest
|
||||
if err := c.ShouldBindJSON(&appInstallReq); err != nil {
|
||||
server.RenderErrorValidateRequest(c, err)
|
||||
return
|
||||
}
|
||||
driver, err := r.GetDriver(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = driver.InstallByUrl(appInstallReq.AppUrl)
|
||||
if err != nil {
|
||||
server.RenderError(c, err)
|
||||
return
|
||||
}
|
||||
if androidDevice, ok := driver.GetDevice().(*uixt.AndroidDevice); ok {
|
||||
_ = driver.Home()
|
||||
if appInstallReq.MappingUrl == "" || appInstallReq.ResourceMappingUrl == "" {
|
||||
server.RenderSuccess(c, true)
|
||||
return
|
||||
}
|
||||
localMappingPath, err := uixt.DownloadFileByUrl(appInstallReq.MappingUrl)
|
||||
if err != nil {
|
||||
server.RenderError(c, err)
|
||||
}
|
||||
defer func() {
|
||||
_ = os.Remove(localMappingPath)
|
||||
}()
|
||||
if err = androidDevice.PushFile(
|
||||
localMappingPath,
|
||||
fmt.Sprintf("/data/local/tmp/%s_map.txt", appInstallReq.PackageName)); err != nil {
|
||||
server.RenderError(c, err)
|
||||
return
|
||||
}
|
||||
localResourceMappingPath, err := uixt.DownloadFileByUrl(
|
||||
appInstallReq.ResourceMappingUrl)
|
||||
if err != nil {
|
||||
server.RenderError(c, err)
|
||||
}
|
||||
defer func() {
|
||||
_ = os.Remove(localResourceMappingPath)
|
||||
}()
|
||||
if err = androidDevice.PushFile(localResourceMappingPath,
|
||||
fmt.Sprintf("/data/local/tmp/%s_resmap.txt", appInstallReq.PackageName)); err != nil {
|
||||
server.RenderError(c, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
server.RenderSuccess(c, true)
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package server_ext
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/server"
|
||||
"github.com/httprunner/httprunner/v5/uixt"
|
||||
"github.com/httprunner/httprunner/v5/uixt/ai"
|
||||
"github.com/httprunner/httprunner/v5/uixt/driver_ext"
|
||||
)
|
||||
|
||||
func (r *RouterExt) GetDriver(c *gin.Context) (driverExt *driver_ext.StubXTDriver, err error) {
|
||||
var device uixt.IDevice
|
||||
var driver driver_ext.IStubDriver
|
||||
deviceObj, exists := c.Get("device")
|
||||
if !exists {
|
||||
device, err = r.GetDevice(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
device = deviceObj.(uixt.IDevice)
|
||||
}
|
||||
platform := c.Param("platform")
|
||||
switch strings.ToLower(platform) {
|
||||
case "android":
|
||||
driver, err = driver_ext.NewStubAndroidDriver(device.(*uixt.AndroidDevice))
|
||||
case "ios":
|
||||
driver, err = driver_ext.NewStubIOSDriver(device.(*uixt.IOSDevice))
|
||||
case "browser":
|
||||
driver, err = driver_ext.NewStubBrowserDriver(device.(*uixt.BrowserDevice))
|
||||
}
|
||||
if err != nil {
|
||||
server.RenderErrorInitDriver(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
driverExt = driver_ext.NewStubXTDriver(driver,
|
||||
ai.WithCVService(ai.CVServiceTypeVEDEM))
|
||||
c.Set("driver", driverExt)
|
||||
return driverExt, nil
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package server_ext
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/server"
|
||||
)
|
||||
|
||||
func (r *RouterExt) loginHandler(c *gin.Context) {
|
||||
var loginReq LoginRequest
|
||||
if err := c.ShouldBindJSON(&loginReq); err != nil {
|
||||
server.RenderErrorValidateRequest(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
driver, err := r.GetDriver(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
info, err := driver.LoginNoneUI(
|
||||
loginReq.PackageName, loginReq.PhoneNumber,
|
||||
loginReq.Captcha, loginReq.Password)
|
||||
if err != nil {
|
||||
server.RenderError(c, err)
|
||||
return
|
||||
}
|
||||
server.RenderSuccess(c, info)
|
||||
}
|
||||
|
||||
func (r *RouterExt) logoutHandler(c *gin.Context) {
|
||||
var logoutReq LogoutRequest
|
||||
if err := c.ShouldBindJSON(&logoutReq); err != nil {
|
||||
server.RenderErrorValidateRequest(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
driver, err := r.GetDriver(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = driver.LogoutNoneUI(logoutReq.PackageName)
|
||||
if err != nil {
|
||||
server.RenderError(c, err)
|
||||
return
|
||||
}
|
||||
server.RenderSuccess(c, true)
|
||||
}
|
||||
|
||||
func (r *RouterExt) sourceHandler(c *gin.Context) {
|
||||
driver, err := r.GetDriver(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
source, err := driver.Source()
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("get source failed")
|
||||
}
|
||||
if source == "{}" || source == "" {
|
||||
time.Sleep(1 * time.Second)
|
||||
source, err = driver.Source()
|
||||
}
|
||||
server.RenderSuccess(c, source)
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package server_ext
|
||||
|
||||
import (
|
||||
"github.com/httprunner/httprunner/v5/server"
|
||||
)
|
||||
|
||||
type RouterExt struct {
|
||||
*server.Router
|
||||
}
|
||||
|
||||
func NewExtRouter() *RouterExt {
|
||||
router := &RouterExt{
|
||||
Router: server.NewRouter(),
|
||||
}
|
||||
router.Init()
|
||||
return router
|
||||
}
|
||||
|
||||
func (r *RouterExt) Init() {
|
||||
apiV1PlatformSerial := r.Group("/api/v1").Group("/:platform").Group("/:serial")
|
||||
|
||||
apiV1PlatformSerial.GET("/stub/source", r.sourceHandler)
|
||||
apiV1PlatformSerial.POST("/stub/login", r.loginHandler)
|
||||
apiV1PlatformSerial.POST("/stub/logout", r.logoutHandler)
|
||||
apiV1PlatformSerial.POST("/app/install", r.installAppHandler)
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package server_ext
|
||||
|
||||
type AppInstallRequest struct {
|
||||
AppUrl string `json:"appUrl" binding:"required"`
|
||||
MappingUrl string `json:"mappingUrl"`
|
||||
ResourceMappingUrl string `json:"resourceMappingUrl"`
|
||||
PackageName string `json:"packageName"`
|
||||
}
|
||||
|
||||
type LoginRequest struct {
|
||||
PackageName string `json:"packageName"`
|
||||
PhoneNumber string `json:"phoneNumber"`
|
||||
Captcha string `json:"captcha" binding:"required_without=Password"`
|
||||
Password string `json:"password" binding:"required_without=Captcha"`
|
||||
}
|
||||
|
||||
type LogoutRequest struct {
|
||||
PackageName string `json:"packageName"`
|
||||
}
|
||||
|
||||
type HttpResponse struct {
|
||||
Code int `json:"errorCode"`
|
||||
Message string `json:"errorMsg"`
|
||||
Result interface{} `json:"result,omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user