From 17292cb112560868f193717e53a67d7695885cae Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Wed, 12 Feb 2025 15:16:01 +0800 Subject: [PATCH] refactor: add tests --- internal/version/VERSION | 2 +- pkg/uixt/android_device.go | 20 --------- pkg/uixt/device.go | 2 +- pkg/uixt/driver_screenshot.go | 2 +- pkg/uixt/driver_screenshot_test.go | 2 +- pkg/uixt/driver_test.go | 54 +++++++++++++++++------ step_mobile_ui.go => step_ui.go | 0 step_mobile_ui_test.go => step_ui_test.go | 0 8 files changed, 45 insertions(+), 37 deletions(-) rename step_mobile_ui.go => step_ui.go (100%) rename step_mobile_ui_test.go => step_ui_test.go (100%) diff --git a/internal/version/VERSION b/internal/version/VERSION index 9af952b2..c2e2a76b 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0+2502112230 +v5.0.0+2502121516 diff --git a/pkg/uixt/android_device.go b/pkg/uixt/android_device.go index 7e38caf9..1dbc749a 100644 --- a/pkg/uixt/android_device.go +++ b/pkg/uixt/android_device.go @@ -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() diff --git a/pkg/uixt/device.go b/pkg/uixt/device.go index f30029c7..652e5453 100644 --- a/pkg/uixt/device.go +++ b/pkg/uixt/device.go @@ -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 diff --git a/pkg/uixt/driver_screenshot.go b/pkg/uixt/driver_screenshot.go index 2011ddca..d1ec9894 100644 --- a/pkg/uixt/driver_screenshot.go +++ b/pkg/uixt/driver_screenshot.go @@ -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) diff --git a/pkg/uixt/driver_screenshot_test.go b/pkg/uixt/driver_screenshot_test.go index 12939e5b..8bf776d4 100644 --- a/pkg/uixt/driver_screenshot_test.go +++ b/pkg/uixt/driver_screenshot_test.go @@ -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) } diff --git a/pkg/uixt/driver_test.go b/pkg/uixt/driver_test.go index 10fd788d..d489204c 100644 --- a/pkg/uixt/driver_test.go +++ b/pkg/uixt/driver_test.go @@ -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") } diff --git a/step_mobile_ui.go b/step_ui.go similarity index 100% rename from step_mobile_ui.go rename to step_ui.go diff --git a/step_mobile_ui_test.go b/step_ui_test.go similarity index 100% rename from step_mobile_ui_test.go rename to step_ui_test.go