From 3cb2eac4426a0ef9e46fb7d2131da10712198714 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Mon, 10 Feb 2025 22:38:12 +0800 Subject: [PATCH] fix: NewHDCDriver --- internal/version/VERSION | 2 +- pkg/uixt/harmony_driver_hdc.go | 49 ++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/internal/version/VERSION b/internal/version/VERSION index eaea81e9..e4fbafc5 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0+2502102232 +v5.0.0+2502102239 diff --git a/pkg/uixt/harmony_driver_hdc.go b/pkg/uixt/harmony_driver_hdc.go index 2f757890..70a8412f 100644 --- a/pkg/uixt/harmony_driver_hdc.go +++ b/pkg/uixt/harmony_driver_hdc.go @@ -15,33 +15,28 @@ import ( "github.com/httprunner/httprunner/v5/pkg/uixt/types" ) -type HDCDriver struct { - *HarmonyDevice - *Session - *DriverExt - points []ExportPoint - uiDriver *ghdc.UIDriver -} +func NewHDCDriver(device *HarmonyDevice) (*HDCDriver, error) { + driver := &HDCDriver{ + Device: device, + } + driver.InitSession(nil) -type PowerStatus string - -const ( - POWER_STATUS_SUSPEND PowerStatus = "POWER_STATUS_SUSPEND" - POWER_STATUS_OFF PowerStatus = "POWER_STATUS_OFF" - POWER_STATUS_ON PowerStatus = "POWER_STATUS_ON" -) - -func NewHDCDriver(device *HarmonyDevice) (driver *HDCDriver, err error) { - driver = new(HDCDriver) - driver.HarmonyDevice = device uiDriver, err := ghdc.NewUIDriver(*device.Device) if err != nil { log.Error().Err(err).Msg("failed to new harmony ui driver") return nil, err } driver.uiDriver = uiDriver - driver.InitSession(nil) - return + + return driver, nil +} + +type HDCDriver struct { + Device *HarmonyDevice + Session *Session + + points []ExportPoint + uiDriver *ghdc.UIDriver } func (hd *HDCDriver) InitSession(capabilities option.Capabilities) error { @@ -64,7 +59,7 @@ func (hd *HDCDriver) Status() (types.DeviceStatus, error) { } func (hd *HDCDriver) GetDevice() IDevice { - return hd.HarmonyDevice + return hd.Device } func (hd *HDCDriver) DeviceInfo() (types.DeviceInfo, error) { @@ -98,9 +93,17 @@ func (hd *HDCDriver) Homescreen() error { return hd.uiDriver.PressKey(ghdc.KEYCODE_HOME) } +type PowerStatus string + +const ( + POWER_STATUS_SUSPEND PowerStatus = "POWER_STATUS_SUSPEND" + POWER_STATUS_OFF PowerStatus = "POWER_STATUS_OFF" + POWER_STATUS_ON PowerStatus = "POWER_STATUS_ON" +) + func (hd *HDCDriver) Unlock() (err error) { // Todo 检查是否锁屏 hdc shell hidumper -s RenderService -a screen - screenInfo, err := hd.RunShellCommand("hidumper", "-s", "RenderService", "-a", "screen") + screenInfo, err := hd.Device.RunShellCommand("hidumper", "-s", "RenderService", "-a", "screen") if err != nil { return err } @@ -126,7 +129,7 @@ func (hd *HDCDriver) AppLaunch(packageName string) error { } func (hd *HDCDriver) AppTerminate(packageName string) (bool, error) { - _, err := hd.RunShellCommand("aa", "force-stop", packageName) + _, err := hd.Device.RunShellCommand("aa", "force-stop", packageName) if err != nil { log.Error().Err(err).Msg("failed to terminal app") return false, err