diff --git a/internal/config/config.go b/internal/config/config.go index ba98cd95..8c99e7af 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -13,7 +13,7 @@ import ( const ( ResultsDirName = "results" ScreenshotsDirName = "screenshots" - ActionLogDireName = "action_log" + ActionLogDirName = "action_log" ) var ( @@ -37,7 +37,7 @@ func init() { ResultsDir = filepath.Join(ResultsDirName, StartTimeStr) ResultsPath = filepath.Join(RootDir, ResultsDir) ScreenShotsPath = filepath.Join(ResultsPath, ScreenshotsDirName) - ActionLogFilePath = filepath.Join(ResultsDir, ActionLogDireName) + ActionLogFilePath = filepath.Join(ResultsDir, ActionLogDirName) DeviceActionLogFilePath = "/sdcard/Android/data/io.appium.uiautomator2.server/files/hodor" // create results directory diff --git a/internal/version/VERSION b/internal/version/VERSION index c954c36b..d0e60a89 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0+2502111557 +v5.0.0+2502111606 diff --git a/pkg/uixt/android_driver_adb.go b/pkg/uixt/android_driver_adb.go index 7eb59b08..22020049 100644 --- a/pkg/uixt/android_driver_adb.go +++ b/pkg/uixt/android_driver_adb.go @@ -895,17 +895,10 @@ var androidActivities = map[string]map[string][]string{ // TODO: SPH, XHS } -func (ad *ADBDriver) ScreenRecord(folderPath string, duration time.Duration) (videoPath string, err error) { - // 获取当前时间戳 +func (ad *ADBDriver) ScreenRecord(duration time.Duration) (videoPath string, err error) { timestamp := time.Now().Format("20060102_150405") + fmt.Sprintf("_%03d", time.Now().UnixNano()/1e6%1000) - // 创建文件名 - fileName := fmt.Sprintf("%s/%s.mp4", folderPath, timestamp) - err = os.MkdirAll(folderPath, os.ModePerm) - if err != nil { - log.Error().Err(err).Msg("Error creating directory") - } + fileName := filepath.Join(config.ScreenShotsPath, fmt.Sprintf("%s.mp4", timestamp)) - // 创建一个文件 file, err := os.Create(fileName) if err != nil { log.Error().Err(err) diff --git a/pkg/uixt/android_test.go b/pkg/uixt/android_test.go index 5fc732d8..a89bde79 100644 --- a/pkg/uixt/android_test.go +++ b/pkg/uixt/android_test.go @@ -393,7 +393,7 @@ func TestTapTexts(t *testing.T) { func TestRecordVideo(t *testing.T) { setupAndroidAdbDriver(t) - path, err := driverExt.ScreenRecord("", 5*time.Second) + path, err := driverExt.ScreenRecord(5 * time.Second) if err != nil { t.Fatal(err) } diff --git a/pkg/uixt/driver.go b/pkg/uixt/driver.go index c4763b7b..192c131c 100644 --- a/pkg/uixt/driver.go +++ b/pkg/uixt/driver.go @@ -44,7 +44,7 @@ type IDriver interface { WindowSize() (types.Size, error) Scale() (float64, error) ScreenShot() (*bytes.Buffer, error) - ScreenRecord(folderPath string, duration time.Duration) (videoPath string, err error) + ScreenRecord(duration time.Duration) (videoPath string, err error) Source(srcOpt ...option.SourceOption) (string, error) // actions diff --git a/pkg/uixt/harmony_driver_hdc.go b/pkg/uixt/harmony_driver_hdc.go index 3d46ef3d..76f6eadf 100644 --- a/pkg/uixt/harmony_driver_hdc.go +++ b/pkg/uixt/harmony_driver_hdc.go @@ -277,7 +277,7 @@ func (hd *HDCDriver) StopCaptureLog() (result interface{}, err error) { return hd.points, nil } -func (hd *HDCDriver) ScreenRecord(folderPath string, duration time.Duration) (videoPath string, err error) { +func (hd *HDCDriver) ScreenRecord(duration time.Duration) (videoPath string, err error) { return "", nil } diff --git a/pkg/uixt/ios_driver_wda.go b/pkg/uixt/ios_driver_wda.go index 1475f377..0b0f781b 100644 --- a/pkg/uixt/ios_driver_wda.go +++ b/pkg/uixt/ios_driver_wda.go @@ -22,6 +22,7 @@ import ( "github.com/httprunner/httprunner/v5/code" "github.com/httprunner/httprunner/v5/internal/builtin" + "github.com/httprunner/httprunner/v5/internal/config" "github.com/httprunner/httprunner/v5/internal/json" "github.com/httprunner/httprunner/v5/pkg/uixt/ai" "github.com/httprunner/httprunner/v5/pkg/uixt/option" @@ -892,23 +893,16 @@ func (wd *WDADriver) triggerWDALog(data map[string]interface{}) (rawResp []byte, return wd.httpPOST(data, "/gtf/automation/log") } -func (wd *WDADriver) ScreenRecord(folderPath string, duration time.Duration) (videoPath string, err error) { - // 获取当前时间戳 +func (wd *WDADriver) ScreenRecord(duration time.Duration) (videoPath string, err error) { timestamp := time.Now().Format("20060102_150405") + fmt.Sprintf("_%03d", time.Now().UnixNano()/1e6%1000) - // 创建文件名 - fileName := fmt.Sprintf("%s/%s.mp4", folderPath, timestamp) - err = os.MkdirAll(folderPath, os.ModePerm) - if err != nil { - log.Error().Err(err).Msg("Error creating directory") - } - // 创建一个文件 + fileName := filepath.Join(config.ScreenShotsPath, fmt.Sprintf("%s.mp4", timestamp)) + file, err := os.Create(fileName) if err != nil { fmt.Println("Error creating file:", err) return "", err } defer func() { - // 确保文件在程序结束时被删除 _ = file.Close() }() diff --git a/pkg/uixt/ios_test.go b/pkg/uixt/ios_test.go index a772b0f2..bde5a9b3 100644 --- a/pkg/uixt/ios_test.go +++ b/pkg/uixt/ios_test.go @@ -433,7 +433,7 @@ func Test_remoteWD_AccessibleSource(t *testing.T) { func TestRecord(t *testing.T) { setup(t) - path, err := driver.ScreenRecord("", 5*time.Second) + path, err := driver.ScreenRecord(5 * time.Second) if err != nil { t.Fatal(err) }