mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
feat: 新增上报duration
This commit is contained in:
@@ -1 +1,5 @@
|
|||||||
v4.5.1
|
<<<<<<< Updated upstream
|
||||||
|
v4.5.1
|
||||||
|
=======
|
||||||
|
v4.5.8
|
||||||
|
>>>>>>> Stashed changes
|
||||||
|
|||||||
@@ -680,6 +680,10 @@ func (ad *adbDriver) StopCaptureLog() (result interface{}, err error) {
|
|||||||
return pointRes, nil
|
return pointRes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ad *adbDriver) GetDriverResults() []*DriverResult {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (ad *adbDriver) GetForegroundApp() (app AppInfo, err error) {
|
func (ad *adbDriver) GetForegroundApp() (app AppInfo, err error) {
|
||||||
// adb shell dumpsys activity activities
|
// adb shell dumpsys activity activities
|
||||||
output, err := ad.adbClient.RunShellCommand("dumpsys", "activity", "activities")
|
output, err := ad.adbClient.RunShellCommand("dumpsys", "activity", "activities")
|
||||||
|
|||||||
@@ -618,3 +618,10 @@ func (ud *uiaDriver) TapByTexts(actions ...TapTextAction) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ud *uiaDriver) GetDriverResults() []*DriverResult {
|
||||||
|
defer func() {
|
||||||
|
ud.Driver.driverResults = nil
|
||||||
|
}()
|
||||||
|
return ud.Driver.driverResults
|
||||||
|
}
|
||||||
|
|||||||
+21
-5
@@ -17,10 +17,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Driver struct {
|
type Driver struct {
|
||||||
urlPrefix *url.URL
|
urlPrefix *url.URL
|
||||||
sessionId string
|
sessionId string
|
||||||
client *http.Client
|
client *http.Client
|
||||||
scale float64
|
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 {
|
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)
|
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") {
|
if !strings.HasSuffix(rawURL, "screenshot") {
|
||||||
// avoid printing screenshot data
|
// avoid printing screenshot data
|
||||||
logger.Str("response", string(rawResp))
|
logger.Str("response", string(rawResp))
|
||||||
|
|||||||
+1
-2
@@ -247,7 +247,6 @@ func compressImageBuffer(raw *bytes.Buffer) (compressed *bytes.Buffer, err error
|
|||||||
|
|
||||||
// 返回压缩后的图像数据
|
// 返回压缩后的图像数据
|
||||||
return &buf, nil
|
return &buf, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// saveScreenShot saves image file with file name
|
// saveScreenShot saves image file with file name
|
||||||
@@ -298,7 +297,7 @@ func (dExt *DriverExt) GetStepCacheData() map[string]interface{} {
|
|||||||
dExt.cacheStepData.screenResults.updatePopupCloseStatus()
|
dExt.cacheStepData.screenResults.updatePopupCloseStatus()
|
||||||
cacheData["screen_results"] = dExt.cacheStepData.screenResults
|
cacheData["screen_results"] = dExt.cacheStepData.screenResults
|
||||||
cacheData["e2e_results"] = dExt.cacheStepData.e2eDelay
|
cacheData["e2e_results"] = dExt.cacheStepData.e2eDelay
|
||||||
|
cacheData["driver_request_results"] = dExt.Driver.GetDriverResults()
|
||||||
// clear cache
|
// clear cache
|
||||||
dExt.cacheStepData.reset()
|
dExt.cacheStepData.reset()
|
||||||
return cacheData
|
return cacheData
|
||||||
|
|||||||
@@ -610,4 +610,5 @@ type WebDriver interface {
|
|||||||
// triggers the log capture and returns the log entries
|
// triggers the log capture and returns the log entries
|
||||||
StartCaptureLog(identifier ...string) (err error)
|
StartCaptureLog(identifier ...string) (err error)
|
||||||
StopCaptureLog() (result interface{}, err error)
|
StopCaptureLog() (result interface{}, err error)
|
||||||
|
GetDriverResults() []*DriverResult
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -877,6 +877,13 @@ func (wd *wdaDriver) StopCaptureLog() (result interface{}, err error) {
|
|||||||
return reply.Value, nil
|
return reply.Value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (wd *wdaDriver) GetDriverResults() []*DriverResult {
|
||||||
|
defer func() {
|
||||||
|
wd.Driver.driverResults = nil
|
||||||
|
}()
|
||||||
|
return wd.Driver.driverResults
|
||||||
|
}
|
||||||
|
|
||||||
type rawResponse []byte
|
type rawResponse []byte
|
||||||
|
|
||||||
func (r rawResponse) checkErr() (err error) {
|
func (r rawResponse) checkErr() (err error) {
|
||||||
|
|||||||
@@ -599,14 +599,14 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
|
|||||||
"osType": osType,
|
"osType": osType,
|
||||||
})
|
})
|
||||||
|
|
||||||
identifer := mobileStep.Identifier
|
identifier := mobileStep.Identifier
|
||||||
if mobileStep.Options != nil && identifer == "" {
|
if mobileStep.Options != nil && identifier == "" {
|
||||||
identifer = mobileStep.Options.Identifier
|
identifier = mobileStep.Options.Identifier
|
||||||
}
|
}
|
||||||
if len(mobileStep.Actions) != 0 && identifer == "" {
|
if len(mobileStep.Actions) != 0 && identifier == "" {
|
||||||
for _, action := range mobileStep.Actions {
|
for _, action := range mobileStep.Actions {
|
||||||
if action.Identifier != "" {
|
if action.Identifier != "" {
|
||||||
identifer = action.Identifier
|
identifier = action.Identifier
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -614,7 +614,7 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
|
|||||||
|
|
||||||
stepResult = &StepResult{
|
stepResult = &StepResult{
|
||||||
Name: step.Name,
|
Name: step.Name,
|
||||||
Identifier: identifer,
|
Identifier: identifier,
|
||||||
StepType: StepType(osType),
|
StepType: StepType(osType),
|
||||||
Success: false,
|
Success: false,
|
||||||
ContentSize: 0,
|
ContentSize: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user