fix: get action log from file

This commit is contained in:
huangbin.beal
2025-08-06 10:46:20 +08:00
parent 11f3330741
commit 256ec4baf3
3 changed files with 8 additions and 7 deletions

View File

@@ -25,7 +25,7 @@ const (
CaseFileName = "case.json" // $PWD/results/20060102150405/case.json CaseFileName = "case.json" // $PWD/results/20060102150405/case.json
// mobile device path // mobile device path
DeviceActionLogFilePath = "/sdcard/Android/data/io.appium.uiautomator2.server/files/hodor" DeviceActionLogFilePath = "/storage/emulated/0/Download/"
) )
type Config struct { type Config struct {

View File

@@ -1 +1 @@
v5.0.0-250728 v5.0.0-250806

View File

@@ -24,6 +24,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/httprunner/funplugin/myexec"
"github.com/httprunner/httprunner/v5/code" "github.com/httprunner/httprunner/v5/code"
"github.com/httprunner/httprunner/v5/internal/config" "github.com/httprunner/httprunner/v5/internal/config"
"github.com/httprunner/httprunner/v5/internal/utf7" "github.com/httprunner/httprunner/v5/internal/utf7"
@@ -706,17 +707,17 @@ func (ad *ADBDriver) StopCaptureLog() (result interface{}, err error) {
log.Error().Err(err).Msg("failed to close adb log writer") log.Error().Err(err).Msg("failed to close adb log writer")
} }
pointRes := ConvertPoints(ad.Device.Logcat.logs) pointRes := ConvertPoints(ad.Device.Logcat.logs)
//将pointRes置为空数组 // 没有解析到打点日志,走兜底逻辑
// 没有解析到打点日志,走兜底逻辑
if len(pointRes) == 0 { if len(pointRes) == 0 {
log.Info().Msg("action log is null, use action file >>>") log.Info().Msg("action log is null, use action file >>>")
actionLogDirPath := config.GetConfig().ActionLogDirPath() actionLogDirPath := config.GetConfig().ActionLogDirPath()
logFilePathPrefix := fmt.Sprintf("%v/data", actionLogDirPath)
files := []string{} files := []string{}
ad.Device.RunShellCommand("pull", config.DeviceActionLogFilePath, actionLogDirPath) actionLogRegStr := `.*data_\d+\.txt`
// ad.Device.RunShellCommand("pull", config.DeviceActionLogFilePath, actionLogDirPath)
myexec.RunCommand("adb", "-s", ad.Device.Serial(), "pull", config.DeviceActionLogFilePath, actionLogDirPath)
err = filepath.Walk(actionLogDirPath, func(path string, info fs.FileInfo, err error) error { err = filepath.Walk(actionLogDirPath, func(path string, info fs.FileInfo, err error) error {
// 只是需要日志文件 // 只是需要日志文件
if ok := strings.Contains(path, logFilePathPrefix); ok { if ok, _ := regexp.MatchString(actionLogRegStr, path); ok {
files = append(files, path) files = append(files, path)
} }
return nil return nil