mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-25 10:20:11 +08:00
refactor: ScreenRecord
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}()
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user