mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +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))
|
filePath = filepath.Join(config.GetConfig().ScreenShotsPath, fmt.Sprintf("%s.mp4", timestamp))
|
||||||
}
|
}
|
||||||
|
|
||||||
duration := options.Duration
|
duration := options.ScreenRecordDuration
|
||||||
audioOn := options.ScreenRecordWithAudio
|
audioOn := options.ScreenRecordWithAudio
|
||||||
|
|
||||||
// get android system version
|
// get android system version
|
||||||
@@ -806,7 +806,9 @@ func (ad *ADBDriver) ScreenRecord(opts ...option.ActionOption) (videoPath string
|
|||||||
}
|
}
|
||||||
|
|
||||||
var useAdbScreenRecord bool
|
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")
|
log.Info().Bool("audioOn", audioOn).Msg("screen record with adb screenrecord by default")
|
||||||
useAdbScreenRecord = true
|
useAdbScreenRecord = true
|
||||||
} else if sysVersion != 0 && sysVersion < 11 {
|
} else if sysVersion != 0 && sysVersion < 11 {
|
||||||
@@ -817,6 +819,17 @@ func (ad *ADBDriver) ScreenRecord(opts ...option.ActionOption) (videoPath string
|
|||||||
useAdbScreenRecord = true
|
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 {
|
if useAdbScreenRecord {
|
||||||
res, err := ad.Device.ScreenRecord(duration)
|
res, err := ad.Device.ScreenRecord(duration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -829,7 +842,7 @@ func (ad *ADBDriver) ScreenRecord(opts ...option.ActionOption) (videoPath string
|
|||||||
}
|
}
|
||||||
|
|
||||||
// screen record with audio
|
// 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)
|
file, err := os.Create(filePath)
|
||||||
if err != nil {
|
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 {
|
func (ad *ADBDriver) Setup() error {
|
||||||
|
|||||||
+19
-3
@@ -195,10 +195,26 @@ func TestDriver_ADB_ForegroundInfo(t *testing.T) {
|
|||||||
|
|
||||||
func TestDriver_ADB_ScreenRecord(t *testing.T) {
|
func TestDriver_ADB_ScreenRecord(t *testing.T) {
|
||||||
driver := setupADBDriverExt(t)
|
driver := setupADBDriverExt(t)
|
||||||
path, err := driver.ScreenRecord(option.WithScreenRecordDuation(5))
|
path1, err := driver.ScreenRecord(option.WithScreenRecordDuation(182))
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
defer os.Remove(path)
|
defer os.Remove(path1)
|
||||||
t.Log(path)
|
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) {
|
func TestDriver_ADB_Backspace(t *testing.T) {
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ func WithScreenShotFileName(fileName string) ActionOption {
|
|||||||
type ScreenRecordOptions struct {
|
type ScreenRecordOptions struct {
|
||||||
ScreenRecordDuration float64 `json:"screenrecord_duration,omitempty" yaml:"screenrecord_duration,omitempty"`
|
ScreenRecordDuration float64 `json:"screenrecord_duration,omitempty" yaml:"screenrecord_duration,omitempty"`
|
||||||
ScreenRecordWithAudio bool `json:"screenrecord_with_audio,omitempty" yaml:"screenrecord_with_audio,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"`
|
ScreenRecordPath string `json:"screenrecord_path,omitempty" yaml:"screenrecord_path,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,6 +146,9 @@ func (o *ScreenRecordOptions) GetScreenRecordOptions() []ActionOption {
|
|||||||
if o.ScreenRecordWithAudio {
|
if o.ScreenRecordWithAudio {
|
||||||
options = append(options, WithScreenRecordAudio(true))
|
options = append(options, WithScreenRecordAudio(true))
|
||||||
}
|
}
|
||||||
|
if o.ScreenRecordWithScrcpy {
|
||||||
|
options = append(options, WithScreenRecordScrcpy(true))
|
||||||
|
}
|
||||||
if o.ScreenRecordPath != "" {
|
if o.ScreenRecordPath != "" {
|
||||||
options = append(options, WithScreenRecordPath(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 {
|
func WithScreenRecordPath(path string) ActionOption {
|
||||||
return func(o *ActionOptions) {
|
return func(o *ActionOptions) {
|
||||||
o.ScreenRecordPath = path
|
o.ScreenRecordPath = path
|
||||||
|
|||||||
Reference in New Issue
Block a user