mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-07 08:27:35 +08:00
refactor: GetUIXTDriver for case runner
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0+2411111344
|
v5.0.0+2411112135
|
||||||
|
|||||||
@@ -418,6 +418,18 @@ func (r *CaseRunner) parseConfig() (parsedConfig *TConfig, err error) {
|
|||||||
return nil, errors.Wrap(code.InvalidCaseError,
|
return nil, errors.Wrap(code.InvalidCaseError,
|
||||||
fmt.Sprintf("parse android config failed: %v", err))
|
fmt.Sprintf("parse android config failed: %v", err))
|
||||||
}
|
}
|
||||||
|
device, err := uixt.NewAndroidDevice(androidDevice.Options()...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "init android device failed")
|
||||||
|
}
|
||||||
|
if err := device.Init(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
driver, err := device.NewDriver()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
r.uixtDrivers[device.SerialNumber] = driver
|
||||||
}
|
}
|
||||||
// parse iOS devices config
|
// parse iOS devices config
|
||||||
for _, iosDevice := range parsedConfig.IOS {
|
for _, iosDevice := range parsedConfig.IOS {
|
||||||
@@ -426,6 +438,18 @@ func (r *CaseRunner) parseConfig() (parsedConfig *TConfig, err error) {
|
|||||||
return nil, errors.Wrap(code.InvalidCaseError,
|
return nil, errors.Wrap(code.InvalidCaseError,
|
||||||
fmt.Sprintf("parse ios config failed: %v", err))
|
fmt.Sprintf("parse ios config failed: %v", err))
|
||||||
}
|
}
|
||||||
|
device, err := uixt.NewIOSDevice(iosDevice.Options()...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "init ios device failed")
|
||||||
|
}
|
||||||
|
if err := device.Init(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
driver, err := device.NewDriver()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
r.uixtDrivers[device.UDID] = driver
|
||||||
}
|
}
|
||||||
// parse harmony devices config
|
// parse harmony devices config
|
||||||
for _, harmonyDevice := range parsedConfig.Harmony {
|
for _, harmonyDevice := range parsedConfig.Harmony {
|
||||||
@@ -434,6 +458,18 @@ func (r *CaseRunner) parseConfig() (parsedConfig *TConfig, err error) {
|
|||||||
return nil, errors.Wrap(code.InvalidCaseError,
|
return nil, errors.Wrap(code.InvalidCaseError,
|
||||||
fmt.Sprintf("parse harmony config failed: %v", err))
|
fmt.Sprintf("parse harmony config failed: %v", err))
|
||||||
}
|
}
|
||||||
|
device, err := uixt.NewHarmonyDevice(harmonyDevice.Options()...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "init harmony device failed")
|
||||||
|
}
|
||||||
|
if err := device.Init(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
driver, err := device.NewDriver()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
r.uixtDrivers[device.ConnectKey] = driver
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsedConfig, nil
|
return parsedConfig, nil
|
||||||
@@ -469,6 +505,21 @@ func (r *CaseRunner) parseDeviceConfig(device interface{}, configVariables map[s
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *CaseRunner) GetUIXTDriver(serial string) (driver *uixt.DriverExt, err error) {
|
||||||
|
for key, driver := range r.uixtDrivers {
|
||||||
|
// return the driver with the same serial
|
||||||
|
if key == serial {
|
||||||
|
return driver, nil
|
||||||
|
}
|
||||||
|
// or return the first driver if serial is empty
|
||||||
|
if serial == "" {
|
||||||
|
r.uixtDrivers[serial] = driver
|
||||||
|
return driver, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, errors.New("no driver found")
|
||||||
|
}
|
||||||
|
|
||||||
// each boomer task initiates a new session
|
// each boomer task initiates a new session
|
||||||
// in order to avoid data racing
|
// in order to avoid data racing
|
||||||
func (r *CaseRunner) NewSession() *SessionRunner {
|
func (r *CaseRunner) NewSession() *SessionRunner {
|
||||||
@@ -651,6 +702,7 @@ func (r *SessionRunner) RunStep(step IStep) (stepResult *StepResult, err error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *SessionRunner) GetSummary() *TestCaseSummary {
|
func (r *SessionRunner) GetSummary() *TestCaseSummary {
|
||||||
|
r.summary.Time.Duration = time.Since(r.summary.Time.StartAt).Seconds()
|
||||||
return r.summary
|
return r.summary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-75
@@ -13,75 +13,6 @@ import (
|
|||||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *SessionRunner) GetUIXTDriver(serial, osType string) (driver *uixt.DriverExt, err error) {
|
|
||||||
// get cached driver
|
|
||||||
for key, driver := range r.caseRunner.uixtDrivers {
|
|
||||||
// if serial is empty, return the first driver
|
|
||||||
if serial == "" {
|
|
||||||
return driver, nil
|
|
||||||
}
|
|
||||||
// or return the driver with the same serial
|
|
||||||
if key == serial {
|
|
||||||
return driver, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
caseConfig := r.caseRunner.TestCase.Config.Get()
|
|
||||||
// init new driver
|
|
||||||
var device uixt.IDevice
|
|
||||||
switch strings.ToLower(osType) {
|
|
||||||
case "ios":
|
|
||||||
for _, ios := range caseConfig.IOS {
|
|
||||||
if serial == "" || ios.UDID == serial {
|
|
||||||
device, err = uixt.NewIOSDevice(ios.Options()...)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if device == nil {
|
|
||||||
device, err = uixt.NewIOSDevice(uixt.WithUDID(serial))
|
|
||||||
}
|
|
||||||
case "harmony":
|
|
||||||
for _, harmony := range caseConfig.Harmony {
|
|
||||||
if serial == "" || harmony.ConnectKey == serial {
|
|
||||||
device, err = uixt.NewHarmonyDevice(harmony.Options()...)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if device == nil {
|
|
||||||
device, err = uixt.NewHarmonyDevice(uixt.WithConnectKey(serial))
|
|
||||||
}
|
|
||||||
case "android":
|
|
||||||
for _, android := range caseConfig.Android {
|
|
||||||
if serial == "" || android.SerialNumber == serial {
|
|
||||||
device, err = uixt.NewAndroidDevice(android.Options()...)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if device == nil {
|
|
||||||
device, err = uixt.NewAndroidDevice(uixt.WithSerialNumber(serial))
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return nil, errors.Errorf("unsupported os type: %s", osType)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrapf(err, "init %s device failed", osType)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := device.Init(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
driver, err = device.NewDriver()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// cache driver
|
|
||||||
r.caseRunner.uixtDrivers[serial] = driver
|
|
||||||
|
|
||||||
return driver, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type MobileUI struct {
|
type MobileUI struct {
|
||||||
OSType string `json:"os_type,omitempty" yaml:"os_type,omitempty"` // ios or harmony or android
|
OSType string `json:"os_type,omitempty" yaml:"os_type,omitempty"` // ios or harmony or android
|
||||||
Serial string `json:"serial,omitempty" yaml:"serial,omitempty"` // android serial or ios udid
|
Serial string `json:"serial,omitempty" yaml:"serial,omitempty"` // android serial or ios udid
|
||||||
@@ -689,18 +620,13 @@ func runStepMobileUI(s *SessionRunner, step IStep) (stepResult *StepResult, err
|
|||||||
return nil, errors.New("invalid mobile UI step type")
|
return nil, errors.New("invalid mobile UI step type")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fix this
|
|
||||||
if mobileStep.OSType == "" {
|
|
||||||
mobileStep.OSType = string(stepTypeAndroid)
|
|
||||||
}
|
|
||||||
|
|
||||||
// report GA event
|
// report GA event
|
||||||
go sdk.SendGA4Event("hrp_run_ui", map[string]interface{}{
|
go sdk.SendGA4Event("hrp_run_ui", map[string]interface{}{
|
||||||
"osType": mobileStep.OSType,
|
"osType": mobileStep.OSType,
|
||||||
})
|
})
|
||||||
|
|
||||||
// init wda/uia/hdc driver
|
// init wda/uia/hdc driver
|
||||||
uiDriver, err := s.GetUIXTDriver(mobileStep.Serial, mobileStep.OSType)
|
uiDriver, err := s.caseRunner.GetUIXTDriver(mobileStep.Serial)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user