refactor & fix: stub driver and server

This commit is contained in:
lilong.129
2025-03-04 17:26:55 +08:00
parent b195760ed9
commit 7f837c9e36
16 changed files with 75 additions and 88 deletions

View File

@@ -16,6 +16,7 @@ var (
_ IDriver = (*UIA2Driver)(nil)
_ IDriver = (*WDADriver)(nil)
_ IDriver = (*HDCDriver)(nil)
_ IDriver = (*BrowserDriver)(nil)
)
// current implemeted driver: ADBDriver, UIA2Driver, WDADriver, HDCDriver
@@ -96,28 +97,3 @@ type XTDriver struct {
// cache screenshot results
screenResults []*ScreenResult
}
func (dExt *XTDriver) GetIDriver() IDriver {
return dExt.IDriver
}
func (dExt *XTDriver) GetWebDriver() IBrowserWebDriver {
return dExt.GetIDriver().(*BrowserDriver)
}
type IXTDriver interface {
IDriver
GetIDriver() IDriver
GetWebDriver() IBrowserWebDriver
GetScreenResult(opts ...option.ActionOption) (screenResult *ScreenResult, err error)
DoAction(action MobileAction) (err error)
}
type IBrowserWebDriver interface {
IDriver
Hover(x, y float64) (err error)
RightClick(x, y float64) (err error)
Scroll(delta int) (err error)
// TODO: move x,y parameters to option
UploadFile(x, y float64, FileUrl, FileFormat string) (err error)
}

View File

@@ -53,6 +53,10 @@ func NewStubAndroidDriver(dev *uixt.AndroidDevice) (*StubAndroidDriver, error) {
return driver, nil
}
func (sad *StubAndroidDriver) GetDriver() uixt.IDriver {
return sad.ADBDriver
}
func (sad *StubAndroidDriver) Setup() error {
socketLocalPort, err := sad.Device.Forward(StubSocketName)
if err != nil {

View File

@@ -27,6 +27,10 @@ func NewStubBrowserDriver(device *uixt.BrowserDevice) (driver *StubBrowserDriver
return driver, nil
}
func (wd *StubBrowserDriver) GetDriver() uixt.IDriver {
return wd.BrowserDriver
}
// Source Return application elements tree
func (wd *StubBrowserDriver) Source(srcOpt ...option.SourceOption) (string, error) {
resp, err := wd.BrowserDriver.HttpGet(http.MethodGet, wd.sessionId, "stub/source")

View File

@@ -1,40 +1,46 @@
package driver_ext
import (
"github.com/rs/zerolog/log"
"time"
"github.com/rs/zerolog/log"
"github.com/httprunner/httprunner/v5/pkg/uixt"
"github.com/httprunner/httprunner/v5/pkg/uixt/ai"
"github.com/httprunner/httprunner/v5/pkg/uixt/option"
)
type IStubDriver interface {
uixt.IDriver
var (
_ IStubDriver = (*StubAndroidDriver)(nil)
_ IStubDriver = (*StubIOSDriver)(nil)
_ IStubDriver = (*StubBrowserDriver)(nil)
)
type IStubDriver interface {
GetDriver() uixt.IDriver
LoginNoneUI(packageName, phoneNumber, captcha, password string) (info AppLoginInfo, err error)
LogoutNoneUI(packageName string) error
}
func NewXTDriver(driver IStubDriver, opts ...ai.AIServiceOption) *XTDriver {
func NewStubXTDriver(stubDriver IStubDriver, opts ...ai.AIServiceOption) *StubXTDriver {
services := ai.NewAIService(opts...)
driverExt := &XTDriver{
driverExt := &StubXTDriver{
XTDriver: &uixt.XTDriver{
IDriver: driver,
IDriver: stubDriver.GetDriver(),
CVService: services.ICVService,
LLMService: services.ILLMService,
},
IStubDriver: driver,
IStubDriver: stubDriver,
}
return driverExt
}
type XTDriver struct {
IStubDriver
type StubXTDriver struct {
*uixt.XTDriver
IStubDriver
}
func (dExt *XTDriver) InstallByUrl(url string, opts ...option.InstallOption) error {
func (dExt *StubXTDriver) InstallByUrl(url string, opts ...option.InstallOption) error {
appPath, err := uixt.DownloadFileByUrl(url)
if err != nil {
return err
@@ -46,7 +52,7 @@ func (dExt *XTDriver) InstallByUrl(url string, opts ...option.InstallOption) err
return nil
}
func (dExt *XTDriver) Install(filePath string, opts ...option.InstallOption) error {
func (dExt *StubXTDriver) Install(filePath string, opts ...option.InstallOption) error {
if _, ok := dExt.GetDevice().(*uixt.AndroidDevice); ok {
stopChan := make(chan struct{})
go func() {
@@ -73,7 +79,3 @@ func (dExt *XTDriver) Install(filePath string, opts ...option.InstallOption) err
return dExt.GetDevice().Install(filePath, opts...)
}
func (dExt *XTDriver) GetWebDriver() uixt.IBrowserWebDriver {
return dExt.GetIDriver().(*StubBrowserDriver)
}

View File

@@ -56,6 +56,10 @@ func (s *StubIOSDriver) SetupWda() (err error) {
return err
}
func (s *StubIOSDriver) GetDriver() uixt.IDriver {
return s.WDADriver
}
func (s *StubIOSDriver) Setup() error {
localPort, err := s.getLocalPort()
if err != nil {