mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-25 17:44:02 +08:00
fix: screen record with scrcpy
This commit is contained in:
@@ -1 +1 @@
|
||||
v5.0.0-beta-2503061657
|
||||
v5.0.0-beta-2503061750
|
||||
|
||||
@@ -791,7 +791,7 @@ func (ad *ADBDriver) ScreenRecord(opts ...option.ActionOption) (videoPath string
|
||||
filePath = filepath.Join(config.GetConfig().ScreenShotsPath, fmt.Sprintf("%s.mp4", timestamp))
|
||||
}
|
||||
|
||||
duration := options.Duration
|
||||
duration := options.ScreenRecordDuration
|
||||
audioOn := options.ScreenRecordWithAudio
|
||||
|
||||
// get android system version
|
||||
@@ -806,7 +806,9 @@ func (ad *ADBDriver) ScreenRecord(opts ...option.ActionOption) (videoPath string
|
||||
}
|
||||
|
||||
var useAdbScreenRecord bool
|
||||
if !audioOn {
|
||||
if options.ScreenRecordWithScrcpy {
|
||||
useAdbScreenRecord = false
|
||||
} else if !audioOn {
|
||||
log.Info().Bool("audioOn", audioOn).Msg("screen record with adb screenrecord by default")
|
||||
useAdbScreenRecord = true
|
||||
} else if sysVersion != 0 && sysVersion < 11 {
|
||||
@@ -817,6 +819,17 @@ func (ad *ADBDriver) ScreenRecord(opts ...option.ActionOption) (videoPath string
|
||||
useAdbScreenRecord = true
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err == nil {
|
||||
filePath, err = filepath.Abs(filePath)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "get absolute path failed")
|
||||
} else {
|
||||
log.Info().Str("path", filePath).Msg("screen record success")
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if useAdbScreenRecord {
|
||||
res, err := ad.Device.ScreenRecord(duration)
|
||||
if err != nil {
|
||||
@@ -829,7 +842,7 @@ func (ad *ADBDriver) ScreenRecord(opts ...option.ActionOption) (videoPath string
|
||||
}
|
||||
|
||||
// screen record with audio
|
||||
log.Info().Msg("screen record with audio, use scrcpy")
|
||||
log.Info().Float64("duration(s)", duration).Msg("screen record with audio, use scrcpy")
|
||||
|
||||
file, err := os.Create(filePath)
|
||||
if err != nil {
|
||||
@@ -878,7 +891,7 @@ func (ad *ADBDriver) ScreenRecord(opts ...option.ActionOption) (videoPath string
|
||||
}
|
||||
}
|
||||
|
||||
return filepath.Abs(filePath)
|
||||
return filePath, nil
|
||||
}
|
||||
|
||||
func (ad *ADBDriver) Setup() error {
|
||||
|
||||
@@ -195,10 +195,26 @@ func TestDriver_ADB_ForegroundInfo(t *testing.T) {
|
||||
|
||||
func TestDriver_ADB_ScreenRecord(t *testing.T) {
|
||||
driver := setupADBDriverExt(t)
|
||||
path, err := driver.ScreenRecord(option.WithScreenRecordDuation(5))
|
||||
path1, err := driver.ScreenRecord(option.WithScreenRecordDuation(182))
|
||||
assert.Nil(t, err)
|
||||
defer os.Remove(path)
|
||||
t.Log(path)
|
||||
defer os.Remove(path1)
|
||||
t.Log(path1)
|
||||
|
||||
path2, err := driver.ScreenRecord(
|
||||
option.WithScreenRecordDuation(5),
|
||||
option.WithScreenRecordAudio(true),
|
||||
)
|
||||
assert.Nil(t, err)
|
||||
defer os.Remove(path2)
|
||||
t.Log(path2)
|
||||
|
||||
path3, err := driver.ScreenRecord(
|
||||
option.WithScreenRecordDuation(5),
|
||||
option.WithScreenRecordScrcpy(true),
|
||||
)
|
||||
assert.Nil(t, err)
|
||||
defer os.Remove(path3)
|
||||
t.Log(path3)
|
||||
}
|
||||
|
||||
func TestDriver_ADB_Backspace(t *testing.T) {
|
||||
|
||||
@@ -127,9 +127,10 @@ func WithScreenShotFileName(fileName string) ActionOption {
|
||||
}
|
||||
|
||||
type ScreenRecordOptions struct {
|
||||
ScreenRecordDuration float64 `json:"screenrecord_duration,omitempty" yaml:"screenrecord_duration,omitempty"`
|
||||
ScreenRecordWithAudio bool `json:"screenrecord_with_audio,omitempty" yaml:"screenrecord_with_audio,omitempty"`
|
||||
ScreenRecordPath string `json:"screenrecord_path,omitempty" yaml:"screenrecord_path,omitempty"`
|
||||
ScreenRecordDuration float64 `json:"screenrecord_duration,omitempty" yaml:"screenrecord_duration,omitempty"`
|
||||
ScreenRecordWithAudio bool `json:"screenrecord_with_audio,omitempty" yaml:"screenrecord_with_audio,omitempty"`
|
||||
ScreenRecordWithScrcpy bool `json:"screenrecord_with_scrcpy,omitempty" yaml:"screenrecord_with_scrcpy,omitempty"`
|
||||
ScreenRecordPath string `json:"screenrecord_path,omitempty" yaml:"screenrecord_path,omitempty"`
|
||||
}
|
||||
|
||||
func (o *ScreenRecordOptions) GetScreenRecordOptions() []ActionOption {
|
||||
@@ -145,6 +146,9 @@ func (o *ScreenRecordOptions) GetScreenRecordOptions() []ActionOption {
|
||||
if o.ScreenRecordWithAudio {
|
||||
options = append(options, WithScreenRecordAudio(true))
|
||||
}
|
||||
if o.ScreenRecordWithScrcpy {
|
||||
options = append(options, WithScreenRecordScrcpy(true))
|
||||
}
|
||||
if o.ScreenRecordPath != "" {
|
||||
options = append(options, WithScreenRecordPath(o.ScreenRecordPath))
|
||||
}
|
||||
@@ -163,6 +167,12 @@ func WithScreenRecordAudio(audioOn bool) ActionOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithScreenRecordScrcpy(scrcpyOn bool) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.ScreenRecordWithScrcpy = scrcpyOn
|
||||
}
|
||||
}
|
||||
|
||||
func WithScreenRecordPath(path string) ActionOption {
|
||||
return func(o *ActionOptions) {
|
||||
o.ScreenRecordPath = path
|
||||
|
||||
Reference in New Issue
Block a user