mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-11 18:11:21 +08:00
Merge branch 'video-crawler-preview-live' into 'master'
feat: get preview live type See merge request iesqa/httprunner!8
This commit is contained in:
@@ -407,7 +407,7 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S
|
||||
screenResult.UploadedURL = imageResult.URL
|
||||
screenResult.Icons = imageResult.UIResult
|
||||
|
||||
if actionOptions.ScreenShotWithClosePopups {
|
||||
if actionOptions.ScreenShotWithClosePopups && imageResult.CPResult != nil {
|
||||
screenResult.Popup = &PopupInfo{
|
||||
Type: imageResult.CPResult.Type,
|
||||
Text: imageResult.CPResult.Text,
|
||||
|
||||
@@ -176,8 +176,8 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
||||
|
||||
// get app event trackings
|
||||
// retry 10 times if get feed failed, abort if fail 10 consecutive times
|
||||
feedVideo, err := crawler.getCurrentVideo()
|
||||
if err != nil || feedVideo.Type == "" {
|
||||
currentVideo, err := crawler.getCurrentVideo()
|
||||
if err != nil || currentVideo.Type == "" {
|
||||
if crawler.failedCount >= 10 {
|
||||
// failed 10 consecutive times
|
||||
return errors.Wrap(code.TrackingGetError,
|
||||
@@ -186,7 +186,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
||||
log.Warn().Msg("get current feed video failed")
|
||||
|
||||
// check and handle popups
|
||||
if err := crawler.driverExt.ClosePopupsHandler(WithMaxRetryTimes(3)); err != nil {
|
||||
if err := crawler.driverExt.ClosePopupsHandler(WithMaxRetryTimes(1)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -195,21 +195,12 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
||||
continue
|
||||
}
|
||||
|
||||
screenResult := &ScreenResult{
|
||||
Resolution: dExt.windowSize,
|
||||
Video: feedVideo,
|
||||
|
||||
// log swipe timelines
|
||||
SwipeStartTime: swipeStartTime.UnixMilli(),
|
||||
SwipeFinishTime: swipeFinishTime.UnixMilli(),
|
||||
}
|
||||
|
||||
switch feedVideo.Type {
|
||||
switch currentVideo.Type {
|
||||
case VideoType_PreviewLive:
|
||||
// 直播预览流
|
||||
var skipEnterLive bool
|
||||
if crawler.isLiveTargetAchieved() {
|
||||
log.Info().Interface("live", screenResult.Video).
|
||||
log.Info().Interface("video", currentVideo).
|
||||
Msg("live count achieved, skip entering live room")
|
||||
skipEnterLive = true
|
||||
} else if rand.Float64() <= 0.25 {
|
||||
@@ -218,23 +209,9 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
||||
skipEnterLive = true
|
||||
}
|
||||
|
||||
if skipEnterLive {
|
||||
// 达标后不再进入直播间
|
||||
crawler.LiveCount++
|
||||
dExt.cacheStepData.screenResults[time.Now().String()] = screenResult
|
||||
// 观播时长取随机时长与仿真时长的最小值
|
||||
sleepTime := math.Min(float64(feedVideo.SimulationPlayDuration), float64(feedVideo.RandomPlayDuration))
|
||||
feedVideo.PlayDuration = int64(sleepTime)
|
||||
log.Info().
|
||||
Strs("tags", screenResult.Tags).
|
||||
Interface("video", feedVideo).
|
||||
Msg(FOUND_LIVE_SUCCESS)
|
||||
// simulation watch feed video
|
||||
sleepStrict(swipeFinishTime, feedVideo.PlayDuration)
|
||||
break
|
||||
} else {
|
||||
if !skipEnterLive {
|
||||
time.Sleep(1 * time.Second)
|
||||
// live target not achieved, enter live
|
||||
// enter live room
|
||||
entryPoint := PointF{
|
||||
X: float64(dExt.windowSize.Width / 2),
|
||||
Y: float64(dExt.windowSize.Height / 2),
|
||||
@@ -246,18 +223,23 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
||||
log.Error().Err(err).Msg("tap live video failed")
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
// skip entering live room
|
||||
// only mock simulation play duration
|
||||
sleepTime := math.Min(float64(currentVideo.SimulationPlayDuration), float64(currentVideo.RandomPlayDuration))
|
||||
currentVideo.PlayDuration = int64(sleepTime)
|
||||
}
|
||||
|
||||
fallthrough
|
||||
|
||||
case VideoType_Live:
|
||||
// 直播
|
||||
log.Info().
|
||||
Strs("tags", screenResult.Tags).
|
||||
Interface("video", feedVideo).
|
||||
Interface("video", currentVideo).
|
||||
Msg(FOUND_LIVE_SUCCESS)
|
||||
|
||||
// take screenshot and get screen texts by OCR
|
||||
screenResultFromOCR, err := crawler.driverExt.GetScreenResult(
|
||||
screenResult, err := crawler.driverExt.GetScreenResult(
|
||||
WithScreenShotOCR(true),
|
||||
WithScreenShotUpload(true),
|
||||
WithScreenShotLiveType(true),
|
||||
@@ -268,31 +250,31 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
||||
time.Sleep(3 * time.Second)
|
||||
continue
|
||||
}
|
||||
if e := crawler.driverExt.tapPopupHandler(screenResultFromOCR.Popup); e != nil {
|
||||
if e := crawler.driverExt.tapPopupHandler(screenResult.Popup); e != nil {
|
||||
log.Error().Err(e).Msg("auto handle popup failed")
|
||||
continue
|
||||
}
|
||||
|
||||
// add live type
|
||||
if screenResultFromOCR.imageResult != nil &&
|
||||
screenResultFromOCR.imageResult.LiveType != "" &&
|
||||
screenResultFromOCR.imageResult.LiveType != "NoLive" {
|
||||
screenResult.Video.LiveType = screenResultFromOCR.imageResult.LiveType
|
||||
if screenResult.imageResult != nil &&
|
||||
screenResult.imageResult.LiveType != "" &&
|
||||
screenResult.imageResult.LiveType != "NoLive" {
|
||||
currentVideo.LiveType = screenResult.imageResult.LiveType
|
||||
}
|
||||
|
||||
crawler.LiveCount++
|
||||
// simulation watch feed video
|
||||
sleepStrict(swipeFinishTime, screenResult.Video.PlayDuration)
|
||||
sleepStrict(swipeFinishTime, currentVideo.PlayDuration)
|
||||
|
||||
screenResultFromOCR.Video = screenResult.Video
|
||||
screenResultFromOCR.Resolution = screenResult.Resolution
|
||||
screenResultFromOCR.SwipeStartTime = screenResult.SwipeStartTime
|
||||
screenResultFromOCR.SwipeFinishTime = screenResult.SwipeFinishTime
|
||||
screenResultFromOCR.TotalElapsed = time.Since(swipeFinishTime).Milliseconds()
|
||||
screenResult.Video = currentVideo
|
||||
screenResult.Resolution = dExt.windowSize
|
||||
screenResult.SwipeStartTime = swipeStartTime.UnixMilli()
|
||||
screenResult.SwipeFinishTime = swipeFinishTime.UnixMilli()
|
||||
screenResult.TotalElapsed = time.Since(swipeFinishTime).Milliseconds()
|
||||
|
||||
var exitLive bool
|
||||
if crawler.isLiveTargetAchieved() {
|
||||
log.Info().Interface("live", screenResult.Video).
|
||||
log.Info().Interface("live", currentVideo).
|
||||
Msg("live count achieved, exit live room")
|
||||
exitLive = true
|
||||
} else if rand.Float64() <= 0.25 {
|
||||
@@ -300,7 +282,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
||||
log.Info().Msg("exit live room by 25% chance")
|
||||
exitLive = true
|
||||
}
|
||||
if exitLive {
|
||||
if exitLive && currentVideo.Type == VideoType_Live {
|
||||
err = crawler.exitLiveRoom()
|
||||
if err != nil {
|
||||
if errors.Is(err, code.TimeoutError) || errors.Is(err, code.InterruptError) {
|
||||
@@ -313,16 +295,25 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
||||
default:
|
||||
// 点播 || 图文 || 广告 || etc.
|
||||
crawler.FeedCount++
|
||||
|
||||
screenResult := &ScreenResult{
|
||||
Resolution: dExt.windowSize,
|
||||
Video: currentVideo,
|
||||
|
||||
// log swipe timelines
|
||||
SwipeStartTime: swipeStartTime.UnixMilli(),
|
||||
SwipeFinishTime: swipeFinishTime.UnixMilli(),
|
||||
}
|
||||
|
||||
dExt.cacheStepData.screenResults[time.Now().String()] = screenResult
|
||||
log.Info().
|
||||
Strs("tags", screenResult.Tags).
|
||||
Interface("video", feedVideo).
|
||||
Interface("video", currentVideo).
|
||||
Msg(FOUND_FEED_SUCCESS)
|
||||
|
||||
// simulation watch feed video
|
||||
sleepStrict(swipeFinishTime, screenResult.Video.PlayDuration)
|
||||
sleepStrict(swipeFinishTime, currentVideo.PlayDuration)
|
||||
screenResult.TotalElapsed = time.Since(swipeFinishTime).Milliseconds()
|
||||
}
|
||||
screenResult.TotalElapsed = time.Since(swipeFinishTime).Milliseconds()
|
||||
|
||||
// check if target count achieved
|
||||
if crawler.isTargetAchieved() {
|
||||
|
||||
Reference in New Issue
Block a user