refactor: add tests

This commit is contained in:
lilong.129
2025-02-12 15:16:01 +08:00
parent 43cb610c4c
commit 17292cb112
8 changed files with 45 additions and 37 deletions

View File

@@ -171,26 +171,6 @@ func (dev *AndroidDevice) NewDriver() (driver IDriver, err error) {
return driver, nil
}
func (dev *AndroidDevice) StartPerf() error {
// TODO
return nil
}
func (dev *AndroidDevice) StopPerf() string {
// TODO
return ""
}
func (dev *AndroidDevice) StartPcap() error {
// TODO
return nil
}
func (dev *AndroidDevice) StopPcap() string {
// TODO
return ""
}
func (dev *AndroidDevice) Install(apkPath string, opts ...option.InstallOption) error {
installOpts := option.NewInstallOptions(opts...)
brand, err := dev.Device.Brand()

View File

@@ -7,7 +7,7 @@ import (
// current implemeted device: IOSDevice, AndroidDevice, HarmonyDevice
type IDevice interface {
UUID() string // ios udid or android serial
UUID() string
NewDriver() (driver IDriver, err error)
Setup() error

View File

@@ -68,7 +68,7 @@ func (dExt *XTDriver) GetScreenResult(opts ...option.ActionOption) (screenResult
// get screenshot info with retry
for i := 0; i < 3; i++ {
imagePath = filepath.Join(config.ScreenShotsPath, fileName)
bufSource, err = dExt.IDriver.ScreenShot(option.WithScreenShotFileName(imagePath))
bufSource, err = dExt.ScreenShot(option.WithScreenShotFileName(imagePath))
if err != nil {
lastErr = err
time.Sleep(time.Second * 1)

View File

@@ -14,7 +14,7 @@ func TestGetScreenShot(t *testing.T) {
setupAndroidAdbDriver(t)
imagePath := filepath.Join(config.ScreenShotsPath, "test_screenshot")
_, err := driverExt.IDriver.ScreenShot(option.WithScreenShotFileName(imagePath))
_, err := driverExt.ScreenShot(option.WithScreenShotFileName(imagePath))
if err != nil {
t.Fatalf("GetScreenShot failed: %v", err)
}

View File

@@ -4,27 +4,55 @@ import (
"testing"
"github.com/httprunner/httprunner/v5/pkg/uixt/ai"
"github.com/httprunner/httprunner/v5/pkg/uixt/option"
)
func TestNewDriverExt(t *testing.T) {
device, _ := NewAndroidDevice()
var driver IDriver
var err error
driver, err = NewADBDriver(device)
if err != nil {
t.Fatal(err)
}
func TestNewDriver1(t *testing.T) {
device, _ := NewAndroidDevice(option.WithUIA2(true))
driver, _ := device.NewDriver()
driverExt := NewXTDriver(driver,
ai.WithCVService(ai.CVServiceTypeVEDEM))
driverExt.TapByOCR("推荐")
}
func TestNewDriver2(t *testing.T) {
device, _ := NewAndroidDevice()
driver, _ := NewUIA2Driver(device)
driverExt := NewXTDriver(driver,
ai.WithCVService(ai.CVServiceTypeVEDEM))
driverExt.TapByOCR("推荐")
}
func TestDriverExt(t *testing.T) {
device, _ := NewAndroidDevice()
driver, _ := NewADBDriver(device)
driverExt := NewXTDriver(driver,
ai.WithCVService(ai.CVServiceTypeVEDEM))
// call IDriver methods
driverExt.TapXY(0.2, 0.5)
driverExt.Swipe(0.2, 0.5, 0.8, 0.5)
driverExt.AppLaunch("com.ss.android.ugc.aweme")
// call AI extended methods
driverExt.TapByOCR("推荐")
texts, _ := driverExt.GetScreenTexts()
t.Log(texts)
point, _ := driverExt.FindScreenText("hello")
t.Log(point)
// get original dirver
driver = driverExt.IDriver.(*ADBDriver)
// call IDriver methods
driverExt.GetDevice().Install("/path/to/app")
driverExt.GetDevice().GetPackageInfo("com.ss.android.ugc.aweme")
// get device
device = driver.GetDevice().(*AndroidDevice)
t.Log(device)
// get original driver and call its methods
adbDriver := driverExt.IDriver.(*ADBDriver)
adbDriver.TapByHierarchy("hello")
wdaDriver := driverExt.IDriver.(*WDADriver)
wdaDriver.GetMjpegClient()
wdaDriver.Scale()
// get original device and call its methods
androidDevice := driver.GetDevice().(*AndroidDevice)
androidDevice.InstallAPK("/path/to/app.apk")
}