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
+1 -1
View File
@@ -1 +1 @@
v5.0.0+2502112230 v5.0.0+2502121516
-20
View File
@@ -171,26 +171,6 @@ func (dev *AndroidDevice) NewDriver() (driver IDriver, err error) {
return driver, nil 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 { func (dev *AndroidDevice) Install(apkPath string, opts ...option.InstallOption) error {
installOpts := option.NewInstallOptions(opts...) installOpts := option.NewInstallOptions(opts...)
brand, err := dev.Device.Brand() brand, err := dev.Device.Brand()
+1 -1
View File
@@ -7,7 +7,7 @@ import (
// current implemeted device: IOSDevice, AndroidDevice, HarmonyDevice // current implemeted device: IOSDevice, AndroidDevice, HarmonyDevice
type IDevice interface { type IDevice interface {
UUID() string // ios udid or android serial UUID() string
NewDriver() (driver IDriver, err error) NewDriver() (driver IDriver, err error)
Setup() error Setup() error
+1 -1
View File
@@ -68,7 +68,7 @@ func (dExt *XTDriver) GetScreenResult(opts ...option.ActionOption) (screenResult
// get screenshot info with retry // get screenshot info with retry
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
imagePath = filepath.Join(config.ScreenShotsPath, fileName) imagePath = filepath.Join(config.ScreenShotsPath, fileName)
bufSource, err = dExt.IDriver.ScreenShot(option.WithScreenShotFileName(imagePath)) bufSource, err = dExt.ScreenShot(option.WithScreenShotFileName(imagePath))
if err != nil { if err != nil {
lastErr = err lastErr = err
time.Sleep(time.Second * 1) time.Sleep(time.Second * 1)
+1 -1
View File
@@ -14,7 +14,7 @@ func TestGetScreenShot(t *testing.T) {
setupAndroidAdbDriver(t) setupAndroidAdbDriver(t)
imagePath := filepath.Join(config.ScreenShotsPath, "test_screenshot") imagePath := filepath.Join(config.ScreenShotsPath, "test_screenshot")
_, err := driverExt.IDriver.ScreenShot(option.WithScreenShotFileName(imagePath)) _, err := driverExt.ScreenShot(option.WithScreenShotFileName(imagePath))
if err != nil { if err != nil {
t.Fatalf("GetScreenShot failed: %v", err) t.Fatalf("GetScreenShot failed: %v", err)
} }
+41 -13
View File
@@ -4,27 +4,55 @@ import (
"testing" "testing"
"github.com/httprunner/httprunner/v5/pkg/uixt/ai" "github.com/httprunner/httprunner/v5/pkg/uixt/ai"
"github.com/httprunner/httprunner/v5/pkg/uixt/option"
) )
func TestNewDriverExt(t *testing.T) { func TestNewDriver1(t *testing.T) {
device, _ := NewAndroidDevice() device, _ := NewAndroidDevice(option.WithUIA2(true))
var driver IDriver driver, _ := device.NewDriver()
var err error driverExt := NewXTDriver(driver,
driver, err = NewADBDriver(device) ai.WithCVService(ai.CVServiceTypeVEDEM))
if err != nil { driverExt.TapByOCR("推荐")
t.Fatal(err) }
}
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, driverExt := NewXTDriver(driver,
ai.WithCVService(ai.CVServiceTypeVEDEM)) 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() texts, _ := driverExt.GetScreenTexts()
t.Log(texts) t.Log(texts)
point, _ := driverExt.FindScreenText("hello")
t.Log(point)
// get original dirver // call IDriver methods
driver = driverExt.IDriver.(*ADBDriver) driverExt.GetDevice().Install("/path/to/app")
driverExt.GetDevice().GetPackageInfo("com.ss.android.ugc.aweme")
// get device // get original driver and call its methods
device = driver.GetDevice().(*AndroidDevice) adbDriver := driverExt.IDriver.(*ADBDriver)
t.Log(device) 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")
} }
View File