From cc53411ba021e4d7bc5d50e8695aaf611892798a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E6=B3=93=E9=93=AE?= Date: Thu, 20 Jun 2024 12:04:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E4=B8=8A=E6=8A=A5dur?= =?UTF-8?q?ation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hrp/internal/version/VERSION | 6 +++++- hrp/pkg/uixt/android_adb_driver.go | 4 ++++ hrp/pkg/uixt/android_uia2_driver.go | 7 +++++++ hrp/pkg/uixt/client.go | 26 +++++++++++++++++++++----- hrp/pkg/uixt/ext.go | 3 +-- hrp/pkg/uixt/interface.go | 1 + hrp/pkg/uixt/ios_driver.go | 7 +++++++ hrp/step_mobile_ui.go | 12 ++++++------ 8 files changed, 52 insertions(+), 14 deletions(-) diff --git a/hrp/internal/version/VERSION b/hrp/internal/version/VERSION index dfe33e04..7405ae5e 100644 --- a/hrp/internal/version/VERSION +++ b/hrp/internal/version/VERSION @@ -1 +1,5 @@ -v4.5.1 \ No newline at end of file +<<<<<<< Updated upstream +v4.5.1 +======= +v4.5.8 +>>>>>>> Stashed changes diff --git a/hrp/pkg/uixt/android_adb_driver.go b/hrp/pkg/uixt/android_adb_driver.go index c642a245..23dfc33b 100644 --- a/hrp/pkg/uixt/android_adb_driver.go +++ b/hrp/pkg/uixt/android_adb_driver.go @@ -680,6 +680,10 @@ func (ad *adbDriver) StopCaptureLog() (result interface{}, err error) { return pointRes, nil } +func (ad *adbDriver) GetDriverResults() []*DriverResult { + return nil +} + func (ad *adbDriver) GetForegroundApp() (app AppInfo, err error) { // adb shell dumpsys activity activities output, err := ad.adbClient.RunShellCommand("dumpsys", "activity", "activities") diff --git a/hrp/pkg/uixt/android_uia2_driver.go b/hrp/pkg/uixt/android_uia2_driver.go index 6606cd78..25b2d1c2 100644 --- a/hrp/pkg/uixt/android_uia2_driver.go +++ b/hrp/pkg/uixt/android_uia2_driver.go @@ -618,3 +618,10 @@ func (ud *uiaDriver) TapByTexts(actions ...TapTextAction) error { } return nil } + +func (ud *uiaDriver) GetDriverResults() []*DriverResult { + defer func() { + ud.Driver.driverResults = nil + }() + return ud.Driver.driverResults +} diff --git a/hrp/pkg/uixt/client.go b/hrp/pkg/uixt/client.go index e680f6f9..5f1feeae 100644 --- a/hrp/pkg/uixt/client.go +++ b/hrp/pkg/uixt/client.go @@ -17,10 +17,18 @@ import ( ) type Driver struct { - urlPrefix *url.URL - sessionId string - client *http.Client - scale float64 + urlPrefix *url.URL + sessionId string + client *http.Client + scale float64 + driverResults []*DriverResult +} + +type DriverResult struct { + RequestUrl string `json:"request_driver_url"` + RequestBody string `json:"request_driver_body,omitempty"` + RequestDuration time.Duration `json:"request_driver_duration"` + RequestTime time.Time `json:"request_driver_time"` } func (wd *Driver) concatURL(u *url.URL, elem ...string) string { @@ -73,7 +81,15 @@ func (wd *Driver) httpRequest(method string, rawURL string, rawBody []byte) (raw }() rawResp, err = io.ReadAll(resp.Body) - logger := log.Debug().Int("statusCode", resp.StatusCode).Str("duration", time.Since(start).String()) + duration := time.Since(start) + driverResult := &DriverResult{ + RequestUrl: rawURL, + RequestBody: string(rawBody), + RequestDuration: duration, + RequestTime: time.Now(), + } + wd.driverResults = append(wd.driverResults, driverResult) + logger := log.Debug().Int("statusCode", resp.StatusCode).Str("duration", duration.String()) if !strings.HasSuffix(rawURL, "screenshot") { // avoid printing screenshot data logger.Str("response", string(rawResp)) diff --git a/hrp/pkg/uixt/ext.go b/hrp/pkg/uixt/ext.go index 28eea07c..cab6bbde 100644 --- a/hrp/pkg/uixt/ext.go +++ b/hrp/pkg/uixt/ext.go @@ -247,7 +247,6 @@ func compressImageBuffer(raw *bytes.Buffer) (compressed *bytes.Buffer, err error // 返回压缩后的图像数据 return &buf, nil - } // saveScreenShot saves image file with file name @@ -298,7 +297,7 @@ func (dExt *DriverExt) GetStepCacheData() map[string]interface{} { dExt.cacheStepData.screenResults.updatePopupCloseStatus() cacheData["screen_results"] = dExt.cacheStepData.screenResults cacheData["e2e_results"] = dExt.cacheStepData.e2eDelay - + cacheData["driver_request_results"] = dExt.Driver.GetDriverResults() // clear cache dExt.cacheStepData.reset() return cacheData diff --git a/hrp/pkg/uixt/interface.go b/hrp/pkg/uixt/interface.go index 3fccf5ba..406a7074 100644 --- a/hrp/pkg/uixt/interface.go +++ b/hrp/pkg/uixt/interface.go @@ -610,4 +610,5 @@ type WebDriver interface { // triggers the log capture and returns the log entries StartCaptureLog(identifier ...string) (err error) StopCaptureLog() (result interface{}, err error) + GetDriverResults() []*DriverResult } diff --git a/hrp/pkg/uixt/ios_driver.go b/hrp/pkg/uixt/ios_driver.go index 9acc164c..5d262b31 100644 --- a/hrp/pkg/uixt/ios_driver.go +++ b/hrp/pkg/uixt/ios_driver.go @@ -877,6 +877,13 @@ func (wd *wdaDriver) StopCaptureLog() (result interface{}, err error) { return reply.Value, nil } +func (wd *wdaDriver) GetDriverResults() []*DriverResult { + defer func() { + wd.Driver.driverResults = nil + }() + return wd.Driver.driverResults +} + type rawResponse []byte func (r rawResponse) checkErr() (err error) { diff --git a/hrp/step_mobile_ui.go b/hrp/step_mobile_ui.go index 12b49ee7..061b4123 100644 --- a/hrp/step_mobile_ui.go +++ b/hrp/step_mobile_ui.go @@ -599,14 +599,14 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err "osType": osType, }) - identifer := mobileStep.Identifier - if mobileStep.Options != nil && identifer == "" { - identifer = mobileStep.Options.Identifier + identifier := mobileStep.Identifier + if mobileStep.Options != nil && identifier == "" { + identifier = mobileStep.Options.Identifier } - if len(mobileStep.Actions) != 0 && identifer == "" { + if len(mobileStep.Actions) != 0 && identifier == "" { for _, action := range mobileStep.Actions { if action.Identifier != "" { - identifer = action.Identifier + identifier = action.Identifier break } } @@ -614,7 +614,7 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err stepResult = &StepResult{ Name: step.Name, - Identifier: identifer, + Identifier: identifier, StepType: StepType(osType), Success: false, ContentSize: 0,