mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-20 12:02:10 +08:00
fix: use log file when not found log content
This commit is contained in:
17
hrp/internal/env/env.go
vendored
17
hrp/internal/env/env.go
vendored
@@ -22,15 +22,18 @@ var (
|
||||
const (
|
||||
ResultsDirName = "results"
|
||||
ScreenshotsDirName = "screenshots"
|
||||
ActionLogDireName = "action_log"
|
||||
)
|
||||
|
||||
var (
|
||||
RootDir string
|
||||
ResultsDir string
|
||||
ResultsPath string
|
||||
ScreenShotsPath string
|
||||
StartTime = time.Now()
|
||||
StartTimeStr = StartTime.Format("20060102150405")
|
||||
RootDir string
|
||||
ResultsDir string
|
||||
ResultsPath string
|
||||
ScreenShotsPath string
|
||||
StartTime = time.Now()
|
||||
StartTimeStr = StartTime.Format("20060102150405")
|
||||
ActionLogFilePath string
|
||||
DeviceActionLogFilePath string
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -43,4 +46,6 @@ func init() {
|
||||
ResultsDir = filepath.Join(ResultsDirName, StartTimeStr)
|
||||
ResultsPath = filepath.Join(RootDir, ResultsDir)
|
||||
ScreenShotsPath = filepath.Join(ResultsPath, ScreenshotsDirName)
|
||||
ActionLogFilePath = filepath.Join(ResultsDir, ActionLogDireName)
|
||||
DeviceActionLogFilePath = "/sdcard/Android/data/io.appium.uiautomator2.server/files/hodor"
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ package uixt
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -10,7 +13,9 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/funplugin/myexec"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/code"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/env"
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/gadb"
|
||||
)
|
||||
|
||||
@@ -448,7 +453,40 @@ func (ad *adbDriver) StopCaptureLog() (result interface{}, err error) {
|
||||
}
|
||||
content := ad.logcat.logBuffer.String()
|
||||
log.Info().Str("logcat content", content).Msg("display logcat content")
|
||||
return ConvertPoints(content), nil
|
||||
pointRes := ConvertPoints(content)
|
||||
// 没有解析到打点日志,走兜底逻辑
|
||||
if len(pointRes) == 0 {
|
||||
logFilePathPrefix := fmt.Sprintf("%v/data", env.ActionLogFilePath)
|
||||
files := []string{}
|
||||
myexec.RunCommand("adb", "pull", env.DeviceActionLogFilePath, env.ActionLogFilePath)
|
||||
err = filepath.Walk(env.ActionLogFilePath, func(path string, info fs.FileInfo, err error) error {
|
||||
// 只是需要日志文件
|
||||
if ok := strings.Contains(path, logFilePathPrefix); ok {
|
||||
files = append(files, path)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
// 先保持原有状态码不变,这里不return error
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("read log file fail")
|
||||
return pointRes, nil
|
||||
}
|
||||
|
||||
if len(files) != 1 {
|
||||
log.Error().Err(err).Msg("log file count error")
|
||||
return pointRes, nil
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadFile(files[0])
|
||||
if err != nil {
|
||||
log.Info().Msg("read File error")
|
||||
return pointRes, nil
|
||||
}
|
||||
|
||||
pointRes = ConvertPoints(string(data))
|
||||
}
|
||||
return pointRes, nil
|
||||
}
|
||||
|
||||
func (ad *adbDriver) GetForegroundApp() (app AppInfo, err error) {
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/httprunner/funplugin"
|
||||
"github.com/httprunner/funplugin/myexec"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
@@ -25,6 +26,7 @@ import (
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/code"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/env"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/sdk"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||
@@ -523,6 +525,11 @@ func (r *SessionRunner) Start(givenVars map[string]interface{}) error {
|
||||
config := r.caseRunner.testCase.Config
|
||||
log.Info().Str("testcase", config.Name).Msg("run testcase start")
|
||||
|
||||
// 安卓系统删除打点日志文件
|
||||
if r.caseRunner.testCase.Config.Android != nil {
|
||||
myexec.RunCommand("adb", "-s", r.caseRunner.testCase.Config.Android[0].SerialNumber, "shell", "rm", "-r", env.DeviceActionLogFilePath)
|
||||
}
|
||||
|
||||
// update config variables with given variables
|
||||
r.InitWithParameters(givenVars)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user