feat: 新增上报duration

This commit is contained in:
余泓铮
2024-06-20 12:04:20 +08:00
parent 55bdfc49be
commit cc53411ba0
8 changed files with 52 additions and 14 deletions

View File

@@ -1 +1,5 @@
v4.5.1
<<<<<<< Updated upstream
v4.5.1
=======
v4.5.8
>>>>>>> Stashed changes

View File

@@ -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")

View File

@@ -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
}

View File

@@ -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))

View File

@@ -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

View File

@@ -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
}

View File

@@ -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) {

View File

@@ -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,