mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
refactor: add tests
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0+2502112230
|
v5.0.0+2502121516
|
||||||
|
|||||||
@@ -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
@@ -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
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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
@@ -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")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user