mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 15:37:35 +08:00
reafctor: move uixtDrivers to caseRunner
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0+2411101049
|
v5.0.0+2411102027
|
||||||
|
|||||||
+10
-5
@@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/httprunner/httprunner/v4/hrp/code"
|
"github.com/httprunner/httprunner/v4/hrp/code"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/sdk"
|
"github.com/httprunner/httprunner/v4/hrp/internal/sdk"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Run starts to run testcase with default configs.
|
// Run starts to run testcase with default configs.
|
||||||
@@ -233,7 +234,7 @@ func (r *HRPRunner) Run(testcases ...ITestCase) (err error) {
|
|||||||
|
|
||||||
// release UI driver session
|
// release UI driver session
|
||||||
defer func() {
|
defer func() {
|
||||||
for _, client := range uiClients {
|
for _, client := range caseRunner.uixtDrivers {
|
||||||
client.Driver.DeleteSession()
|
client.Driver.DeleteSession()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@@ -277,9 +278,10 @@ func (r *HRPRunner) Run(testcases ...ITestCase) (err error) {
|
|||||||
// each testcase has its own case runner
|
// each testcase has its own case runner
|
||||||
func (r *HRPRunner) NewCaseRunner(testcase TestCase) (*CaseRunner, error) {
|
func (r *HRPRunner) NewCaseRunner(testcase TestCase) (*CaseRunner, error) {
|
||||||
caseRunner := &CaseRunner{
|
caseRunner := &CaseRunner{
|
||||||
TestCase: testcase,
|
TestCase: testcase,
|
||||||
hrpRunner: r,
|
hrpRunner: r,
|
||||||
parser: newParser(),
|
parser: newParser(),
|
||||||
|
uixtDrivers: make(map[string]*uixt.DriverExt),
|
||||||
}
|
}
|
||||||
config := testcase.Config.Get()
|
config := testcase.Config.Get()
|
||||||
|
|
||||||
@@ -335,6 +337,9 @@ type CaseRunner struct {
|
|||||||
parser *Parser // each CaseRunner init its own Parser
|
parser *Parser // each CaseRunner init its own Parser
|
||||||
|
|
||||||
parametersIterator *ParametersIterator
|
parametersIterator *ParametersIterator
|
||||||
|
|
||||||
|
// UI automation clients for iOS and Android, key is udid/serial
|
||||||
|
uixtDrivers map[string]*uixt.DriverExt
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseConfig parses testcase config, stores to parsedConfig.
|
// parseConfig parses testcase config, stores to parsedConfig.
|
||||||
@@ -522,7 +527,7 @@ func (r *SessionRunner) Start(givenVars map[string]interface{}) (summary *TestCa
|
|||||||
summary.InOut.ConfigVars = config.Variables
|
summary.InOut.ConfigVars = config.Variables
|
||||||
|
|
||||||
// TODO: move to mobile ui step
|
// TODO: move to mobile ui step
|
||||||
for uuid, client := range uiClients {
|
for uuid, client := range r.caseRunner.uixtDrivers {
|
||||||
// add WDA/UIA logs to summary
|
// add WDA/UIA logs to summary
|
||||||
logs := map[string]interface{}{
|
logs := map[string]interface{}{
|
||||||
"uuid": uuid,
|
"uuid": uuid,
|
||||||
|
|||||||
+8
-10
@@ -13,11 +13,9 @@ import (
|
|||||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||||
)
|
)
|
||||||
|
|
||||||
var uiClients = make(map[string]*uixt.DriverExt) // UI automation clients for iOS and Android, key is udid/serial
|
func (r *SessionRunner) GetUIXTDriver(serial, osType string) (driver *uixt.DriverExt, err error) {
|
||||||
|
|
||||||
func initUIClient(serial, osType string, caseConfig *TConfig) (client *uixt.DriverExt, err error) {
|
|
||||||
// get cached driver
|
// get cached driver
|
||||||
for key, driver := range uiClients {
|
for key, driver := range r.caseRunner.uixtDrivers {
|
||||||
// if serial is empty, return the first driver
|
// if serial is empty, return the first driver
|
||||||
if serial == "" {
|
if serial == "" {
|
||||||
return driver, nil
|
return driver, nil
|
||||||
@@ -28,6 +26,7 @@ func initUIClient(serial, osType string, caseConfig *TConfig) (client *uixt.Driv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
caseConfig := r.caseRunner.TestCase.Config.Get()
|
||||||
// init new driver
|
// init new driver
|
||||||
var device uixt.IDevice
|
var device uixt.IDevice
|
||||||
switch strings.ToLower(osType) {
|
switch strings.ToLower(osType) {
|
||||||
@@ -72,15 +71,15 @@ func initUIClient(serial, osType string, caseConfig *TConfig) (client *uixt.Driv
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err = device.NewDriver()
|
driver, err = device.NewDriver()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// cache wda client
|
// cache driver
|
||||||
uiClients[serial] = client
|
r.caseRunner.uixtDrivers[serial] = driver
|
||||||
|
|
||||||
return client, nil
|
return driver, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type MobileUI struct {
|
type MobileUI struct {
|
||||||
@@ -656,8 +655,7 @@ func runStepMobileUI(s *SessionRunner, step IStep) (stepResult *StepResult, err
|
|||||||
})
|
})
|
||||||
|
|
||||||
// init wda/uia/hdc driver
|
// init wda/uia/hdc driver
|
||||||
caseConfig := s.caseRunner.TestCase.Config.Get()
|
uiDriver, err := s.GetUIXTDriver(mobileStep.Serial, mobileStep.OSType)
|
||||||
uiDriver, err := initUIClient(mobileStep.Serial, mobileStep.OSType, caseConfig)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-10
@@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/json"
|
"github.com/httprunner/httprunner/v4/hrp/internal/json"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/pkg/httpstat"
|
"github.com/httprunner/httprunner/v4/hrp/pkg/httpstat"
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HTTPMethod string
|
type HTTPMethod string
|
||||||
@@ -748,31 +749,52 @@ func (s *StepRequest) WebSocket() *StepWebSocket {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Android creates a new android action
|
// Android creates a new android step session
|
||||||
func (s *StepRequest) Android() *StepMobile {
|
func (s *StepRequest) Android(options ...uixt.AndroidDeviceOption) *StepMobile {
|
||||||
|
androidOptions := &uixt.AndroidDevice{}
|
||||||
|
for _, option := range options {
|
||||||
|
option(androidOptions)
|
||||||
|
}
|
||||||
return &StepMobile{
|
return &StepMobile{
|
||||||
StepConfig: s.StepConfig,
|
StepConfig: s.StepConfig,
|
||||||
Android: &MobileUI{},
|
Android: &MobileUI{
|
||||||
|
OSType: string(stepTypeAndroid),
|
||||||
|
Serial: androidOptions.SerialNumber,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IOS creates a new ios action
|
// IOS creates a new ios step session
|
||||||
func (s *StepRequest) IOS() *StepMobile {
|
func (s *StepRequest) IOS(options ...uixt.IOSDeviceOption) *StepMobile {
|
||||||
|
iosOptions := &uixt.IOSDevice{}
|
||||||
|
for _, option := range options {
|
||||||
|
option(iosOptions)
|
||||||
|
}
|
||||||
return &StepMobile{
|
return &StepMobile{
|
||||||
StepConfig: s.StepConfig,
|
StepConfig: s.StepConfig,
|
||||||
IOS: &MobileUI{},
|
IOS: &MobileUI{
|
||||||
|
OSType: string(stepTypeIOS),
|
||||||
|
Serial: iosOptions.UDID,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Harmony creates a new harmony action
|
// Harmony creates a new harmony step session
|
||||||
func (s *StepRequest) Harmony() *StepMobile {
|
func (s *StepRequest) Harmony(options ...uixt.HarmonyDeviceOption) *StepMobile {
|
||||||
|
harmonyOptions := &uixt.HarmonyDevice{}
|
||||||
|
for _, option := range options {
|
||||||
|
option(harmonyOptions)
|
||||||
|
}
|
||||||
return &StepMobile{
|
return &StepMobile{
|
||||||
StepConfig: s.StepConfig,
|
StepConfig: s.StepConfig,
|
||||||
Harmony: &MobileUI{},
|
Harmony: &MobileUI{
|
||||||
|
OSType: string(stepTypeHarmony),
|
||||||
|
Serial: harmonyOptions.ConnectKey,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shell creates a new shell action
|
// Shell creates a new shell step session
|
||||||
func (s *StepRequest) Shell(content string) *StepShell {
|
func (s *StepRequest) Shell(content string) *StepShell {
|
||||||
return &StepShell{
|
return &StepShell{
|
||||||
StepConfig: s.StepConfig,
|
StepConfig: s.StepConfig,
|
||||||
|
|||||||
Reference in New Issue
Block a user