mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
refactor: move andorid/ios uiClients from HRPRunner to CaseRunner
This commit is contained in:
@@ -84,9 +84,8 @@ type HRPRunner struct {
|
|||||||
httpClient *http.Client
|
httpClient *http.Client
|
||||||
http2Client *http.Client
|
http2Client *http.Client
|
||||||
wsDialer *websocket.Dialer
|
wsDialer *websocket.Dialer
|
||||||
uiClients map[string]*uixt.DriverExt // UI automation clients for iOS and Android, key is udid/serial
|
caseTimeoutTimer *time.Timer // case timeout timer
|
||||||
caseTimeoutTimer *time.Timer // case timeout timer
|
interruptSignal chan os.Signal // interrupt signal channel
|
||||||
interruptSignal chan os.Signal // interrupt signal channel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetClientTransport configures transport of http client for high concurrency load testing
|
// SetClientTransport configures transport of http client for high concurrency load testing
|
||||||
@@ -236,7 +235,7 @@ func (r *HRPRunner) Run(testcases ...ITestCase) (err error) {
|
|||||||
|
|
||||||
// release UI driver session
|
// release UI driver session
|
||||||
defer func() {
|
defer func() {
|
||||||
for _, client := range r.uiClients {
|
for _, client := range caseRunner.uiClients {
|
||||||
client.Driver.DeleteSession()
|
client.Driver.DeleteSession()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@@ -339,13 +338,15 @@ func (r *HRPRunner) NewCaseRunner(testcase *TestCase) (*CaseRunner, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CaseRunner struct {
|
type CaseRunner struct {
|
||||||
testCase *TestCase
|
hrpRunner *HRPRunner // all case runners share one HRPRunner
|
||||||
hrpRunner *HRPRunner
|
|
||||||
parser *Parser
|
testCase *TestCase // each testcase init its own CaseRunner
|
||||||
|
parser *Parser // each CaseRunner init its own Parser
|
||||||
|
|
||||||
parsedConfig *TConfig
|
parsedConfig *TConfig
|
||||||
parametersIterator *ParametersIterator
|
parametersIterator *ParametersIterator
|
||||||
rootDir string // project root dir
|
rootDir string // project root dir
|
||||||
|
uiClients map[string]*uixt.DriverExt // UI automation clients for iOS and Android, key is udid/serial
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseConfig parses testcase config, stores to parsedConfig.
|
// parseConfig parses testcase config, stores to parsedConfig.
|
||||||
@@ -418,8 +419,8 @@ func (r *CaseRunner) parseConfig() error {
|
|||||||
r.parametersIterator = parametersIterator
|
r.parametersIterator = parametersIterator
|
||||||
|
|
||||||
// init iOS/Android clients
|
// init iOS/Android clients
|
||||||
if r.hrpRunner.uiClients == nil {
|
if r.uiClients == nil {
|
||||||
r.hrpRunner.uiClients = make(map[string]*uixt.DriverExt)
|
r.uiClients = make(map[string]*uixt.DriverExt)
|
||||||
}
|
}
|
||||||
for _, iosDeviceConfig := range r.parsedConfig.IOS {
|
for _, iosDeviceConfig := range r.parsedConfig.IOS {
|
||||||
if iosDeviceConfig.UDID != "" {
|
if iosDeviceConfig.UDID != "" {
|
||||||
@@ -438,7 +439,7 @@ func (r *CaseRunner) parseConfig() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "init iOS WDA client failed")
|
return errors.Wrap(err, "init iOS WDA client failed")
|
||||||
}
|
}
|
||||||
r.hrpRunner.uiClients[device.UDID] = client
|
r.uiClients[device.UDID] = client
|
||||||
}
|
}
|
||||||
for _, androidDeviceConfig := range r.parsedConfig.Android {
|
for _, androidDeviceConfig := range r.parsedConfig.Android {
|
||||||
if androidDeviceConfig.SerialNumber != "" {
|
if androidDeviceConfig.SerialNumber != "" {
|
||||||
@@ -457,7 +458,7 @@ func (r *CaseRunner) parseConfig() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "init Android client failed")
|
return errors.Wrap(err, "init Android client failed")
|
||||||
}
|
}
|
||||||
r.hrpRunner.uiClients[device.SerialNumber] = client
|
r.uiClients[device.SerialNumber] = client
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -476,7 +477,8 @@ func (r *CaseRunner) NewSession() *SessionRunner {
|
|||||||
// SessionRunner is used to run testcase and its steps.
|
// SessionRunner is used to run testcase and its steps.
|
||||||
// each testcase has its own SessionRunner instance and share session variables.
|
// each testcase has its own SessionRunner instance and share session variables.
|
||||||
type SessionRunner struct {
|
type SessionRunner struct {
|
||||||
caseRunner *CaseRunner
|
caseRunner *CaseRunner // all session runners share one CaseRunner
|
||||||
|
|
||||||
sessionVariables map[string]interface{}
|
sessionVariables map[string]interface{}
|
||||||
// transactions stores transaction timing info.
|
// transactions stores transaction timing info.
|
||||||
// key is transaction name, value is map of transaction type and time, e.g. start time and end time.
|
// key is transaction name, value is map of transaction type and time, e.g. start time and end time.
|
||||||
@@ -661,7 +663,7 @@ func (r *SessionRunner) GetSummary() (*TestCaseSummary, error) {
|
|||||||
caseSummary.InOut.ExportVars = exportVars
|
caseSummary.InOut.ExportVars = exportVars
|
||||||
caseSummary.InOut.ConfigVars = r.caseRunner.parsedConfig.Variables
|
caseSummary.InOut.ConfigVars = r.caseRunner.parsedConfig.Variables
|
||||||
|
|
||||||
for uuid, client := range r.caseRunner.hrpRunner.uiClients {
|
for uuid, client := range r.caseRunner.uiClients {
|
||||||
// add WDA/UIA logs to summary
|
// add WDA/UIA logs to summary
|
||||||
logs := map[string]interface{}{
|
logs := map[string]interface{}{
|
||||||
"uuid": uuid,
|
"uuid": uuid,
|
||||||
|
|||||||
@@ -513,7 +513,7 @@ func (s *StepMobileUIValidation) Run(r *SessionRunner) (*StepResult, error) {
|
|||||||
return runStepMobileUI(r, s.step)
|
return runStepMobileUI(r, s.step)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *HRPRunner) initUIClient(uuid string, osType string) (client *uixt.DriverExt, err error) {
|
func (r *CaseRunner) initUIClient(uuid string, osType string) (client *uixt.DriverExt, err error) {
|
||||||
// avoid duplicate init
|
// avoid duplicate init
|
||||||
if uuid == "" && len(r.uiClients) > 0 {
|
if uuid == "" && len(r.uiClients) > 0 {
|
||||||
for _, v := range r.uiClients {
|
for _, v := range r.uiClients {
|
||||||
@@ -585,7 +585,7 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// init wda/uia driver
|
// init wda/uia driver
|
||||||
uiDriver, err := s.caseRunner.hrpRunner.initUIClient(mobileStep.Serial, osType)
|
uiDriver, err := s.caseRunner.initUIClient(mobileStep.Serial, osType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user