feat: 优化ext getDriver和GetDevice策略
This commit is contained in:
parent
ebdd676e61
commit
1094d1d95e
|
@ -16,7 +16,7 @@ type IStubDriver interface {
|
|||
LogoutNoneUI(packageName string) error
|
||||
}
|
||||
|
||||
func NewXTDriver(driver uixt.IDriver, opts ...ai.AIServiceOption) *XTDriver {
|
||||
func NewXTDriver(driver IStubDriver, opts ...ai.AIServiceOption) *XTDriver {
|
||||
services := ai.NewAIService(opts...)
|
||||
driverExt := &XTDriver{
|
||||
XTDriver: &uixt.XTDriver{
|
||||
|
@ -24,11 +24,13 @@ func NewXTDriver(driver uixt.IDriver, opts ...ai.AIServiceOption) *XTDriver {
|
|||
CVService: services.ICVService,
|
||||
LLMService: services.ILLMService,
|
||||
},
|
||||
IStubDriver: driver,
|
||||
}
|
||||
return driverExt
|
||||
}
|
||||
|
||||
type XTDriver struct {
|
||||
IStubDriver
|
||||
*uixt.XTDriver
|
||||
}
|
||||
|
||||
|
@ -48,7 +50,7 @@ func (dExt *XTDriver) Install(filePath string, opts ...option.InstallOption) err
|
|||
if _, ok := dExt.GetDevice().(*uixt.AndroidDevice); ok {
|
||||
stopChan := make(chan struct{})
|
||||
go func() {
|
||||
ticker := time.NewTicker(3 * time.Second)
|
||||
ticker := time.NewTicker(5 * time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
|
@ -56,6 +58,7 @@ func (dExt *XTDriver) Install(filePath string, opts ...option.InstallOption) err
|
|||
case <-ticker.C:
|
||||
go func() {
|
||||
_ = dExt.TapByOCR("^(.*无视风险安装|正在扫描.*|我知道了|稍后继续|稍后提醒|继续安装|知道了|确定|继续|完成|点击继续安装|继续安装旧版本|替换|.*正在安装|安装|授权本次安装|重新安装|仍要安装|更多详情|我知道了|已了解此应用未经检测.)$", option.WithRegex(true), option.WithIgnoreNotFoundError(true))
|
||||
//_ = dExt.IDriver.TapByHierarchy("^(.*无视风险安装|正在扫描.*|我知道了|稍后继续|稍后提醒|继续安装|知道了|确定|继续|完成|点击继续安装|继续安装旧版本|替换|.*正在安装|安装|授权本次安装|重新安装|仍要安装|更多详情|我知道了|已了解此应用未经检测.)$", option.WithRegex(true), option.WithIgnoreNotFoundError(true))
|
||||
}()
|
||||
case <-stopChan:
|
||||
log.Info().Msg("install complete")
|
||||
|
|
|
@ -25,7 +25,7 @@ func (r *Router) appInfoHandler(c *gin.Context) {
|
|||
RenderErrorValidateRequest(c, err)
|
||||
return
|
||||
}
|
||||
device, err := GetDevice(c)
|
||||
device, err := r.GetDevice(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ func (p RouterBaseMethod) GetDriver(c *gin.Context) (driverExt uixt.IXTDriver, e
|
|||
var device uixt.IDevice
|
||||
var driver uixt.IDriver
|
||||
if !exists {
|
||||
device, err = GetDevice(c)
|
||||
device, err = p.GetDevice(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ func (p RouterBaseMethod) GetDriver(c *gin.Context) (driverExt uixt.IXTDriver, e
|
|||
return driverExt, nil
|
||||
}
|
||||
|
||||
func GetDevice(c *gin.Context) (device uixt.IDevice, err error) {
|
||||
func (p RouterBaseMethod) GetDevice(c *gin.Context) (device uixt.IDevice, err error) {
|
||||
platform := c.Param("platform")
|
||||
serial := c.Param("serial")
|
||||
if serial == "" {
|
||||
|
@ -96,7 +96,7 @@ func RenderError(c *gin.Context, err error) {
|
|||
c.JSON(http.StatusInternalServerError,
|
||||
HttpResponse{
|
||||
Code: code.GetErrorCode(err),
|
||||
Message: err.Error(),
|
||||
Message: "grey " + err.Error(),
|
||||
},
|
||||
)
|
||||
c.Abort()
|
||||
|
@ -111,7 +111,7 @@ func RenderErrorInitDriver(c *gin.Context, err error) {
|
|||
c.JSON(http.StatusInternalServerError,
|
||||
HttpResponse{
|
||||
Code: errCode,
|
||||
Message: "init driver failed",
|
||||
Message: "grey init driver failed",
|
||||
},
|
||||
)
|
||||
c.Abort()
|
||||
|
@ -121,7 +121,7 @@ func RenderErrorValidateRequest(c *gin.Context, err error) {
|
|||
log.Error().Err(err).Msg("validate request failed")
|
||||
c.JSON(http.StatusBadRequest, HttpResponse{
|
||||
Code: code.GetErrorCode(code.InvalidParamError),
|
||||
Message: fmt.Sprintf("validate request param failed: %s", err.Error()),
|
||||
Message: fmt.Sprintf("grey validate request param failed: %s", err.Error()),
|
||||
})
|
||||
c.Abort()
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package server_ext
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"strings"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/pkg/uixt"
|
||||
"github.com/httprunner/httprunner/v5/pkg/uixt/ai"
|
||||
|
@ -16,9 +15,9 @@ func (p RouterBaseMethodExt) GetDriver(c *gin.Context) (driverExt uixt.IXTDriver
|
|||
serial := c.Param("serial")
|
||||
deviceObj, exists := c.Get("device")
|
||||
var device uixt.IDevice
|
||||
var driver uixt.IDriver
|
||||
var driver driver_ext.IStubDriver
|
||||
if !exists {
|
||||
device, err = server.GetDevice(c)
|
||||
device, err = p.GetDevice(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ type RouterBaseMethod struct {
|
|||
|
||||
type IRouterBaseMethod interface {
|
||||
GetDriver(c *gin.Context) (driver uixt.IXTDriver, err error)
|
||||
GetDevice(c *gin.Context) (driver uixt.IDevice, err error)
|
||||
}
|
||||
|
||||
func (r *Router) Init() {
|
||||
|
|
Loading…
Reference in New Issue