mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-06 16:07:45 +08:00
change: simulate play for preview live
This commit is contained in:
@@ -113,12 +113,17 @@ func (vc *VideoCrawler) isTargetAchieved() bool {
|
|||||||
|
|
||||||
// run live video crawler
|
// run live video crawler
|
||||||
func (vc *VideoCrawler) startLiveCrawler(enterPoint PointF) error {
|
func (vc *VideoCrawler) startLiveCrawler(enterPoint PointF) error {
|
||||||
log.Info().Msg("enter live room")
|
log.Info().Msg("tap screen center to enter live room")
|
||||||
if err := vc.driverExt.TapAbsXY(enterPoint.X, enterPoint.Y); err != nil {
|
if err := vc.driverExt.TapAbsXY(enterPoint.X, enterPoint.Y); err != nil {
|
||||||
log.Error().Err(err).Msg("tap live video failed")
|
log.Error().Err(err).Msg("tap live video failed")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
time.Sleep(5 * time.Second)
|
liveRoom, err := vc.getCurrentVideo()
|
||||||
|
if err != nil || (liveRoom.Type != VideoType_Live || liveRoom.Type != VideoType_PreviewLive) {
|
||||||
|
return errors.New("enter live room failed")
|
||||||
|
}
|
||||||
|
log.Info().Interface("liveRoom", liveRoom).Msg("enter live room success")
|
||||||
|
|
||||||
for !vc.isLiveTargetAchieved() {
|
for !vc.isLiveTargetAchieved() {
|
||||||
select {
|
select {
|
||||||
case <-vc.timer.C:
|
case <-vc.timer.C:
|
||||||
@@ -170,6 +175,10 @@ func (vc *VideoCrawler) startLiveCrawler(enterPoint PointF) error {
|
|||||||
liveRoom.LiveType = screenResult.imageResult.LiveType
|
liveRoom.LiveType = screenResult.imageResult.LiveType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get simulation watch duration
|
||||||
|
liveRoom.PlayDuration = getPlayDuration(
|
||||||
|
liveRoom, vc.configs.Live.SleepRandom)
|
||||||
|
|
||||||
// incr live count
|
// incr live count
|
||||||
screenResult.Video = liveRoom
|
screenResult.Video = liveRoom
|
||||||
vc.LiveCount++
|
vc.LiveCount++
|
||||||
@@ -177,13 +186,6 @@ func (vc *VideoCrawler) startLiveCrawler(enterPoint PointF) error {
|
|||||||
Interface("live", screenResult.Video).
|
Interface("live", screenResult.Video).
|
||||||
Msg("found live success")
|
Msg("found live success")
|
||||||
|
|
||||||
// get simulation watch duration
|
|
||||||
if screenResult.Video.SimulationPlayDuration != 0 {
|
|
||||||
screenResult.Video.PlayDuration = screenResult.Video.SimulationPlayDuration
|
|
||||||
} else {
|
|
||||||
screenResult.Video.RandomPlayDuration = getSimulationDuration(vc.configs.Live.SleepRandom)
|
|
||||||
screenResult.Video.PlayDuration = screenResult.Video.RandomPlayDuration
|
|
||||||
}
|
|
||||||
// simulation watch live video
|
// simulation watch live video
|
||||||
sleepStrict(swipeFinishTime, screenResult.Video.PlayDuration)
|
sleepStrict(swipeFinishTime, screenResult.Video.PlayDuration)
|
||||||
|
|
||||||
@@ -296,13 +298,23 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
switch feedVideo.Type {
|
switch feedVideo.Type {
|
||||||
case VideoType_PreviewLive, VideoType_Live:
|
case VideoType_PreviewLive, VideoType_Live:
|
||||||
// 直播预览流 || 直播
|
// 直播预览流 || 直播
|
||||||
log.Info().
|
crawler.LiveCount++
|
||||||
Interface("live", screenResult.Video).
|
|
||||||
Msg("found live success")
|
|
||||||
|
|
||||||
if crawler.isLiveTargetAchieved() {
|
if crawler.isLiveTargetAchieved() {
|
||||||
log.Info().Msg("live count achieved, skip")
|
log.Info().Interface("live", screenResult.Video).
|
||||||
|
Msg("live count achieved, skip")
|
||||||
} else {
|
} else {
|
||||||
|
// simulation
|
||||||
|
// get simulation play duration
|
||||||
|
screenResult.Video.PlayDuration = getPlayDuration(
|
||||||
|
screenResult.Video, crawler.configs.Live.SleepRandom)
|
||||||
|
|
||||||
|
log.Info().Interface("feed", screenResult.Video).
|
||||||
|
Strs("tags", screenResult.Tags).
|
||||||
|
Msg("found live success")
|
||||||
|
|
||||||
|
// simulation watch feed video
|
||||||
|
sleepStrict(swipeFinishTime, screenResult.Video.PlayDuration)
|
||||||
|
|
||||||
// live target not achieved, enter live
|
// live target not achieved, enter live
|
||||||
entryPoint := PointF{
|
entryPoint := PointF{
|
||||||
X: float64(dExt.windowSize.Width / 2),
|
X: float64(dExt.windowSize.Width / 2),
|
||||||
@@ -322,15 +334,10 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
// 点播 || 图文 || 广告 || etc.
|
// 点播 || 图文 || 广告 || etc.
|
||||||
// get simulation play duration
|
|
||||||
if screenResult.Video.SimulationPlayDuration != 0 {
|
|
||||||
screenResult.Video.PlayDuration = screenResult.Video.SimulationPlayDuration
|
|
||||||
} else {
|
|
||||||
screenResult.Video.RandomPlayDuration = getSimulationDuration(crawler.configs.Feed.SleepRandom)
|
|
||||||
screenResult.Video.PlayDuration = screenResult.Video.RandomPlayDuration
|
|
||||||
}
|
|
||||||
|
|
||||||
crawler.FeedCount++
|
crawler.FeedCount++
|
||||||
|
|
||||||
|
screenResult.Video.PlayDuration = getPlayDuration(
|
||||||
|
screenResult.Video, crawler.configs.Feed.SleepRandom)
|
||||||
log.Info().Interface("feed", screenResult.Video).
|
log.Info().Interface("feed", screenResult.Video).
|
||||||
Strs("tags", screenResult.Tags).
|
Strs("tags", screenResult.Tags).
|
||||||
Msg("found feed success")
|
Msg("found feed success")
|
||||||
@@ -352,6 +359,17 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getPlayDuration(video *Video, params []interface{}) int64 {
|
||||||
|
// get simulation play duration
|
||||||
|
if video.SimulationPlayDuration != 0 {
|
||||||
|
video.PlayDuration = video.SimulationPlayDuration
|
||||||
|
} else {
|
||||||
|
video.RandomPlayDuration = getSimulationDuration(params)
|
||||||
|
video.PlayDuration = video.RandomPlayDuration
|
||||||
|
}
|
||||||
|
return video.PlayDuration
|
||||||
|
}
|
||||||
|
|
||||||
type VideoType string
|
type VideoType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
Reference in New Issue
Block a user