From 3094c3369bc6917620b389178bbc96357e1cb75c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E6=B3=93=E9=93=AE?= Date: Fri, 21 Jun 2024 11:57:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9Eoppo=E6=89=8B?= =?UTF-8?q?=E5=8A=A8=E5=90=AF=E5=8A=A8=E4=B8=80=E6=AC=A1settings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hrp/pkg/uixt/android_device.go | 15 +++++++++++++++ hrp/pkg/uixt/interface.go | 1 + hrp/pkg/uixt/ios_device.go | 4 ++++ hrp/runner.go | 15 ++++++++------- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/hrp/pkg/uixt/android_device.go b/hrp/pkg/uixt/android_device.go index 64fb030a..4d1ca432 100644 --- a/hrp/pkg/uixt/android_device.go +++ b/hrp/pkg/uixt/android_device.go @@ -13,6 +13,7 @@ import ( "github.com/rs/zerolog/log" "github.com/httprunner/httprunner/v4/hrp/internal/code" + "github.com/httprunner/httprunner/v4/hrp/internal/env" "github.com/httprunner/httprunner/v4/hrp/internal/json" "github.com/httprunner/httprunner/v4/hrp/pkg/gadb" ) @@ -157,6 +158,20 @@ type AndroidDevice struct { IgnorePopup bool `json:"ignore_popup,omitempty" yaml:"ignore_popup,omitempty"` } +func (dev *AndroidDevice) Init() error { + brand, err := dev.d.Brand() + if err != nil { + return fmt.Errorf("failed to init android device. brand is null %v", err) + } + if strings.ToLower(brand) == "huawei" { + // 启动一次io.appium.settings。防止oppo设备上切换输入法失败 + myexec.RunCommand("adb", "-s", dev.SerialNumber, "shell", + "monkey", "-p", "io.appium.settings", "-c", "android.intent.category.LAUNCHER", "1") + } + myexec.RunCommand("adb", "-s", dev.SerialNumber, "shell", "rm", "-r", env.DeviceActionLogFilePath) + return nil +} + func (dev *AndroidDevice) UUID() string { return dev.SerialNumber } diff --git a/hrp/pkg/uixt/interface.go b/hrp/pkg/uixt/interface.go index 3fccf5ba..5a93b5bf 100644 --- a/hrp/pkg/uixt/interface.go +++ b/hrp/pkg/uixt/interface.go @@ -468,6 +468,7 @@ func WithDriverPlugin(plugin funplugin.IPlugin) DriverOption { // current implemeted device: IOSDevice, AndroidDevice type Device interface { + Init() error // init android device UUID() string // ios udid or android serial LogEnabled() bool NewDriver(...DriverOption) (driverExt *DriverExt, err error) diff --git a/hrp/pkg/uixt/ios_device.go b/hrp/pkg/uixt/ios_device.go index 8057f8a1..6a0f1fbb 100644 --- a/hrp/pkg/uixt/ios_device.go +++ b/hrp/pkg/uixt/ios_device.go @@ -295,6 +295,10 @@ type IOSDevice struct { pcapFile string // saved pcap file path } +func (dev *IOSDevice) Init() error { + return nil +} + func (dev *IOSDevice) UUID() string { return dev.UDID } diff --git a/hrp/runner.go b/hrp/runner.go index 86f32885..3fe6d4bb 100644 --- a/hrp/runner.go +++ b/hrp/runner.go @@ -18,7 +18,6 @@ import ( "github.com/gorilla/websocket" "github.com/httprunner/funplugin" - "github.com/httprunner/funplugin/myexec" "github.com/jinzhu/copier" "github.com/pkg/errors" "github.com/rs/zerolog/log" @@ -26,7 +25,6 @@ import ( "github.com/httprunner/httprunner/v4/hrp/internal/builtin" "github.com/httprunner/httprunner/v4/hrp/internal/code" - "github.com/httprunner/httprunner/v4/hrp/internal/env" "github.com/httprunner/httprunner/v4/hrp/internal/sdk" "github.com/httprunner/httprunner/v4/hrp/internal/version" "github.com/httprunner/httprunner/v4/hrp/pkg/uixt" @@ -437,11 +435,15 @@ func (r *CaseRunner) parseConfig() error { if err != nil { return errors.Wrap(err, "init iOS device failed") } + if err := device.Init(); err != nil { + return err + } client, err := device.NewDriver(uixt.WithDriverPlugin(r.parser.plugin)) if err != nil { return errors.Wrap(err, "init iOS WDA client failed") } r.uiClients[device.UDID] = client + } for _, androidDeviceConfig := range r.parsedConfig.Android { if androidDeviceConfig.SerialNumber != "" { @@ -456,11 +458,15 @@ func (r *CaseRunner) parseConfig() error { if err != nil { return errors.Wrap(err, "init Android device failed") } + if err := device.Init(); err != nil { + return err + } client, err := device.NewDriver(uixt.WithDriverPlugin(r.parser.plugin)) if err != nil { return errors.Wrap(err, "init Android client failed") } r.uiClients[device.SerialNumber] = client + } return nil @@ -525,11 +531,6 @@ func (r *SessionRunner) Start(givenVars map[string]interface{}) error { config := r.caseRunner.testCase.Config log.Info().Str("testcase", config.Name).Msg("run testcase start") - // 安卓系统删除打点日志文件 - if r.caseRunner.testCase.Config.Android != nil { - myexec.RunCommand("adb", "-s", r.caseRunner.testCase.Config.Android[0].SerialNumber, "shell", "rm", "-r", env.DeviceActionLogFilePath) - } - // update config variables with given variables r.InitWithParameters(givenVars)