Files
httprunner/internal/config/config.go
2025-02-19 20:26:20 +08:00

54 lines
1.4 KiB
Go

package config
import (
"os"
"path/filepath"
"time"
"github.com/rs/zerolog/log"
"github.com/httprunner/httprunner/v5/internal/builtin"
)
const (
ResultsDirName = "results"
DownloadsDirName = "downloads"
ScreenshotsDirName = "screenshots"
ActionLogDirName = "action_log"
)
var (
RootDir string
ResultsDir string
ResultsPath string
DownloadsPath string
ScreenShotsPath string
StartTime = time.Now()
StartTimeStr = StartTime.Format("20060102150405")
ActionLogFilePath string
DeviceActionLogFilePath string
)
func init() {
var err error
RootDir, err = os.Getwd()
if err != nil {
panic(err)
}
ResultsDir = filepath.Join(ResultsDirName, StartTimeStr)
ResultsPath = filepath.Join(RootDir, ResultsDir)
DownloadsPath = filepath.Join(RootDir, filepath.Join(DownloadsDirName, StartTimeStr))
ScreenShotsPath = filepath.Join(ResultsPath, ScreenshotsDirName)
ActionLogFilePath = filepath.Join(ResultsDir, ActionLogDirName)
DeviceActionLogFilePath = "/sdcard/Android/data/io.appium.uiautomator2.server/files/hodor"
// create results directory
if err := builtin.EnsureFolderExists(ResultsPath); err != nil {
log.Fatal().Err(err).Msg("create results directory failed")
}
if err := builtin.EnsureFolderExists(ScreenShotsPath); err != nil {
log.Fatal().Err(err).Msg("create screenshots directory failed")
}
}