From 3975c2d265f55bbb3c621d8a2014e169b4b49a34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=81=AA?= Date: Thu, 14 Sep 2023 17:22:27 +0800 Subject: [PATCH 1/5] fix: custom swipe direction --- hrp/cmd/run.go | 2 +- hrp/internal/version/VERSION | 2 +- hrp/pkg/uixt/video_crawler.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hrp/cmd/run.go b/hrp/cmd/run.go index e042a5b7..cb14a8c3 100644 --- a/hrp/cmd/run.go +++ b/hrp/cmd/run.go @@ -42,7 +42,7 @@ func init() { runCmd.Flags().BoolVarP(&continueOnFailure, "continue-on-failure", "c", false, "continue running next step when failure occurs") runCmd.Flags().BoolVar(&requestsLogOff, "log-requests-off", false, "turn off request & response details logging") runCmd.Flags().BoolVar(&httpStatOn, "http-stat", false, "turn on HTTP latency stat (DNSLookup, TCP Connection, etc.)") - runCmd.Flags().BoolVar(&pluginLogOn, "log-plugin", false, "turn on plugin logging") + runCmd.Flags().BoolVar(&pluginLogOn, "log-plugin", true, "turn on plugin logging") runCmd.Flags().StringVarP(&proxyUrl, "proxy-url", "p", "", "set proxy url") runCmd.Flags().BoolVarP(&saveTests, "save-tests", "s", false, "save tests summary") runCmd.Flags().BoolVarP(&genHTMLReport, "gen-html-report", "g", false, "generate html report") diff --git a/hrp/internal/version/VERSION b/hrp/internal/version/VERSION index 471e7432..c4223e22 100644 --- a/hrp/internal/version/VERSION +++ b/hrp/internal/version/VERSION @@ -1 +1 @@ -v4.3.6 \ No newline at end of file +v4.3.6.202309141330 \ No newline at end of file diff --git a/hrp/pkg/uixt/video_crawler.go b/hrp/pkg/uixt/video_crawler.go index 2c8f978e..bdbc39fb 100644 --- a/hrp/pkg/uixt/video_crawler.go +++ b/hrp/pkg/uixt/video_crawler.go @@ -135,7 +135,7 @@ func (vc *VideoCrawler) startLiveCrawler(enterPoint PointF) error { default: // swipe to next live video swipeStartTime := time.Now() - if err := vc.driverExt.SwipeUp(); err != nil { + if err := vc.driverExt.SwipeRelative(0.9, 0.8, 0.9, 0.1); err != nil { log.Error().Err(err).Msg("live swipe up failed") return err } @@ -254,7 +254,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { // swipe to next feed video log.Info().Msg("swipe to next feed video") swipeStartTime := time.Now() - if err = dExt.SwipeUp(); err != nil { + if err = dExt.SwipeRelative(0.9, 0.8, 0.9, 0.1); err != nil { log.Error().Err(err).Msg("feed swipe up failed") return err } From b4d0162e3344b4196d283cce5d9ff7a7bb886510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=81=AA?= Date: Tue, 19 Sep 2023 14:52:52 +0800 Subject: [PATCH 2/5] refactor: video crawler --- hrp/cmd/run.go | 2 +- hrp/internal/version/VERSION | 2 +- hrp/pkg/uixt/video_crawler.go | 93 +++++++++++++++++++++++++---------- 3 files changed, 69 insertions(+), 28 deletions(-) diff --git a/hrp/cmd/run.go b/hrp/cmd/run.go index cb14a8c3..e042a5b7 100644 --- a/hrp/cmd/run.go +++ b/hrp/cmd/run.go @@ -42,7 +42,7 @@ func init() { runCmd.Flags().BoolVarP(&continueOnFailure, "continue-on-failure", "c", false, "continue running next step when failure occurs") runCmd.Flags().BoolVar(&requestsLogOff, "log-requests-off", false, "turn off request & response details logging") runCmd.Flags().BoolVar(&httpStatOn, "http-stat", false, "turn on HTTP latency stat (DNSLookup, TCP Connection, etc.)") - runCmd.Flags().BoolVar(&pluginLogOn, "log-plugin", true, "turn on plugin logging") + runCmd.Flags().BoolVar(&pluginLogOn, "log-plugin", false, "turn on plugin logging") runCmd.Flags().StringVarP(&proxyUrl, "proxy-url", "p", "", "set proxy url") runCmd.Flags().BoolVarP(&saveTests, "save-tests", "s", false, "save tests summary") runCmd.Flags().BoolVarP(&genHTMLReport, "gen-html-report", "g", false, "generate html report") diff --git a/hrp/internal/version/VERSION b/hrp/internal/version/VERSION index c4223e22..471e7432 100644 --- a/hrp/internal/version/VERSION +++ b/hrp/internal/version/VERSION @@ -1 +1 @@ -v4.3.6.202309141330 \ No newline at end of file +v4.3.6 \ No newline at end of file diff --git a/hrp/pkg/uixt/video_crawler.go b/hrp/pkg/uixt/video_crawler.go index bdbc39fb..23be7b1c 100644 --- a/hrp/pkg/uixt/video_crawler.go +++ b/hrp/pkg/uixt/video_crawler.go @@ -1,6 +1,7 @@ package uixt import ( + "fmt" "time" "github.com/pkg/errors" @@ -112,15 +113,10 @@ func (vc *VideoCrawler) isTargetAchieved() bool { } // run live video crawler -func (vc *VideoCrawler) startLiveCrawler(enterPoint PointF) error { - log.Info().Msg("tap screen center to enter live room") - if err := vc.driverExt.TapAbsXY(enterPoint.X, enterPoint.Y); err != nil { - log.Error().Err(err).Msg("tap live video failed") - return err - } +func (vc *VideoCrawler) startLiveCrawler() error { liveRoom, err := vc.getCurrentVideo() - if err != nil || (liveRoom.Type != VideoType_Live && liveRoom.Type != VideoType_PreviewLive) { - return errors.New("enter live room failed") + if err != nil || (liveRoom.Type != VideoType_Live) { + return errors.New(fmt.Sprintf("enter live room failed, err: %v", err)) } log.Info().Interface("liveRoom", liveRoom).Msg("enter live room success") @@ -290,15 +286,36 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { SwipeStartTime: swipeStartTime.UnixMilli(), SwipeFinishTime: swipeFinishTime.UnixMilli(), } - dExt.cacheStepData.screenResults[time.Now().String()] = screenResult switch feedVideo.Type { - case VideoType_PreviewLive, VideoType_Live: - // 直播预览流 || 直播 - crawler.LiveCount++ + case VideoType_PreviewLive: + // 直播预览流 if crawler.isLiveTargetAchieved() { log.Info().Interface("live", screenResult.Video). Msg("live count achieved, skip") + continue + } else { + time.Sleep(1 * time.Second) + // live target not achieved, enter live + entryPoint := PointF{ + X: float64(dExt.windowSize.Width / 2), + Y: float64(dExt.windowSize.Height / 2), + } + + log.Info().Msg("tap screen center to enter live room") + if err := crawler.driverExt.TapAbsXY(entryPoint.X, entryPoint.Y); err != nil { + log.Error().Err(err).Msg("tap live video failed") + continue + } + } + fallthrough + case VideoType_Live: + // 直播 + crawler.LiveCount++ + if crawler.isLiveTargetAchieved() { + log.Info().Interface("live", screenResult.Video). + Msg("live count achieved, exit live house") + err = crawler.exitLiveRoom() } else { // simulation log.Info(). @@ -306,29 +323,53 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { Interface("video", feedVideo). Msg("found live success") + // take screenshot and get screen texts by OCR + screenResultFromOCR, err := crawler.driverExt.GetScreenResult( + WithScreenShotOCR(true), + WithScreenShotUpload(true), + WithScreenShotLiveType(true), + WithScreenShotClosePopups(true), + ) + if err != nil { + log.Error().Err(err).Msg("get screen result failed") + time.Sleep(3 * time.Second) + continue + } + if e := crawler.driverExt.tapPopupHandler(screenResultFromOCR.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 + } + + screenResultFromOCR.Video = screenResult.Video + screenResultFromOCR.Resolution = screenResult.Resolution + screenResultFromOCR.SwipeStartTime = screenResult.SwipeStartTime + screenResultFromOCR.SwipeFinishTime = screenResult.SwipeFinishTime + // simulation watch feed video sleepStrict(swipeFinishTime, screenResult.Video.PlayDuration) - // live target not achieved, enter live - entryPoint := PointF{ - X: float64(dExt.windowSize.Width / 2), - Y: float64(dExt.windowSize.Height / 2), - } - // start live crawler - err = crawler.startLiveCrawler(entryPoint) - if err != nil { - if errors.Is(err, code.TimeoutError) || errors.Is(err, code.InterruptError) { - return err - } - log.Error().Err(err).Msg("run live crawler failed, continue") - } - continue + err = crawler.startLiveCrawler() } + if err != nil { + if errors.Is(err, code.TimeoutError) || errors.Is(err, code.InterruptError) { + return err + } + log.Error().Err(err).Msg("run live crawler failed, continue") + } + continue default: // 点播 || 图文 || 广告 || etc. crawler.FeedCount++ + dExt.cacheStepData.screenResults[time.Now().String()] = screenResult log.Info(). Strs("tags", screenResult.Tags). Interface("video", feedVideo). From 4404603210517011ed21785d62c8dfb991963d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=81=AA?= Date: Tue, 19 Sep 2023 16:08:02 +0800 Subject: [PATCH 3/5] update: remove startLiveCrawler --- hrp/pkg/uixt/video_crawler.go | 179 ++++++++-------------------------- 1 file changed, 43 insertions(+), 136 deletions(-) diff --git a/hrp/pkg/uixt/video_crawler.go b/hrp/pkg/uixt/video_crawler.go index 23be7b1c..f6759392 100644 --- a/hrp/pkg/uixt/video_crawler.go +++ b/hrp/pkg/uixt/video_crawler.go @@ -1,7 +1,6 @@ package uixt import ( - "fmt" "time" "github.com/pkg/errors" @@ -112,95 +111,6 @@ func (vc *VideoCrawler) isTargetAchieved() bool { return vc.isFeedTargetAchieved() && vc.isLiveTargetAchieved() } -// run live video crawler -func (vc *VideoCrawler) startLiveCrawler() error { - liveRoom, err := vc.getCurrentVideo() - if err != nil || (liveRoom.Type != VideoType_Live) { - return errors.New(fmt.Sprintf("enter live room failed, err: %v", err)) - } - log.Info().Interface("liveRoom", liveRoom).Msg("enter live room success") - - for !vc.isLiveTargetAchieved() { - select { - case <-vc.timer.C: - log.Warn().Msg("timeout in live crawler") - return errors.Wrap(code.TimeoutError, "live crawler timeout") - case <-vc.driverExt.interruptSignal: - log.Warn().Msg("interrupted in live crawler") - return errors.Wrap(code.InterruptError, "live crawler interrupted") - default: - // swipe to next live video - swipeStartTime := time.Now() - if err := vc.driverExt.SwipeRelative(0.9, 0.8, 0.9, 0.1); err != nil { - log.Error().Err(err).Msg("live swipe up failed") - return err - } - swipeFinishTime := time.Now() - - // take screenshot and get screen texts by OCR - screenResult, err := vc.driverExt.GetScreenResult( - WithScreenShotOCR(true), - WithScreenShotUpload(true), - WithScreenShotLiveType(true), - WithScreenShotClosePopups(true), - ) - if err != nil { - log.Error().Err(err).Msg("get screen result failed") - time.Sleep(3 * time.Second) - continue - } - if e := vc.driverExt.tapPopupHandler(screenResult.Popup); e != nil { - log.Error().Err(e).Msg("auto handle popup failed") - return e - } - - liveRoom, err := vc.getCurrentVideo() - if err != nil || liveRoom.Type != VideoType_Live { - if vc.failedCount >= 3 { - // failed 3 consecutive times - return errors.Wrap(code.TrackingGetError, - "get current live event trackings failed 3 consecutive times") - } - log.Warn().Int64("failedCount", vc.failedCount). - Msg("get current live room failed") - - // retry - vc.failedCount++ - continue - } - - // add live type - if screenResult.imageResult != nil && - screenResult.imageResult.LiveType != "" && - screenResult.imageResult.LiveType != "NoLive" { - liveRoom.LiveType = screenResult.imageResult.LiveType - } - - // incr live count - screenResult.Video = liveRoom - vc.LiveCount++ - log.Info().Strs("tags", screenResult.Tags). - Interface("video", screenResult.Video). - Msg("found live success") - - // simulation watch live video - sleepStrict(swipeFinishTime, screenResult.Video.PlayDuration) - - // log swipe timelines - screenResult.SwipeStartTime = swipeStartTime.UnixMilli() - screenResult.SwipeFinishTime = swipeFinishTime.UnixMilli() - screenResult.TotalElapsed = time.Since(swipeFinishTime).Milliseconds() - - // reset failed count - vc.failedCount = 0 - } - } - - log.Info().Msg("live count achieved, exit live room") - - return vc.exitLiveRoom() -} - func (vc *VideoCrawler) exitLiveRoom() error { log.Info().Msg("press back to exit live room") return vc.driverExt.Driver.PressBack() @@ -309,62 +219,59 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { } } fallthrough + case VideoType_Live: // 直播 + log.Info(). + Strs("tags", screenResult.Tags). + Interface("video", feedVideo). + Msg("found live success") + + // take screenshot and get screen texts by OCR + screenResultFromOCR, err := crawler.driverExt.GetScreenResult( + WithScreenShotOCR(true), + WithScreenShotUpload(true), + WithScreenShotLiveType(true), + WithScreenShotClosePopups(true), + ) + if err != nil { + log.Error().Err(err).Msg("get screen result failed") + time.Sleep(3 * time.Second) + continue + } + if e := crawler.driverExt.tapPopupHandler(screenResultFromOCR.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 + } + crawler.LiveCount++ + // simulation watch feed video + sleepStrict(swipeFinishTime, screenResult.Video.PlayDuration) + + screenResultFromOCR.Video = screenResult.Video + screenResultFromOCR.Resolution = screenResult.Resolution + screenResultFromOCR.SwipeStartTime = screenResult.SwipeStartTime + screenResultFromOCR.SwipeFinishTime = screenResult.SwipeFinishTime + screenResultFromOCR.TotalElapsed = time.Since(swipeFinishTime).Milliseconds() + if crawler.isLiveTargetAchieved() { log.Info().Interface("live", screenResult.Video). Msg("live count achieved, exit live house") err = crawler.exitLiveRoom() - } else { - // simulation - log.Info(). - Strs("tags", screenResult.Tags). - Interface("video", feedVideo). - Msg("found live success") - - // take screenshot and get screen texts by OCR - screenResultFromOCR, err := crawler.driverExt.GetScreenResult( - WithScreenShotOCR(true), - WithScreenShotUpload(true), - WithScreenShotLiveType(true), - WithScreenShotClosePopups(true), - ) if err != nil { - log.Error().Err(err).Msg("get screen result failed") - time.Sleep(3 * time.Second) - continue + if errors.Is(err, code.TimeoutError) || errors.Is(err, code.InterruptError) { + return err + } + log.Error().Err(err).Msg("run live crawler failed, continue") } - if e := crawler.driverExt.tapPopupHandler(screenResultFromOCR.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 - } - - screenResultFromOCR.Video = screenResult.Video - screenResultFromOCR.Resolution = screenResult.Resolution - screenResultFromOCR.SwipeStartTime = screenResult.SwipeStartTime - screenResultFromOCR.SwipeFinishTime = screenResult.SwipeFinishTime - - // simulation watch feed video - sleepStrict(swipeFinishTime, screenResult.Video.PlayDuration) - - // start live crawler - err = crawler.startLiveCrawler() } - if err != nil { - if errors.Is(err, code.TimeoutError) || errors.Is(err, code.InterruptError) { - return err - } - log.Error().Err(err).Msg("run live crawler failed, continue") - } - continue default: // 点播 || 图文 || 广告 || etc. From 3c86fac5538c4316a355e52d566226cf10a94d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=81=AA?= Date: Tue, 19 Sep 2023 21:09:45 +0800 Subject: [PATCH 4/5] fix: simulation watch video in the preview live when live count achieved --- hrp/pkg/uixt/video_crawler.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/hrp/pkg/uixt/video_crawler.go b/hrp/pkg/uixt/video_crawler.go index f6759392..aa374cca 100644 --- a/hrp/pkg/uixt/video_crawler.go +++ b/hrp/pkg/uixt/video_crawler.go @@ -1,6 +1,7 @@ package uixt import ( + "math" "time" "github.com/pkg/errors" @@ -201,9 +202,19 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { case VideoType_PreviewLive: // 直播预览流 if crawler.isLiveTargetAchieved() { - log.Info().Interface("live", screenResult.Video). - Msg("live count achieved, skip") - continue + // 达标后不再进入直播间 + 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 { time.Sleep(1 * time.Second) // live target not achieved, enter live @@ -375,15 +386,16 @@ func (vc *VideoCrawler) getCurrentVideo() (video *Video, err error) { return nil, errors.Wrap(err, "json unmarshal video info failed") } + if video.Type == VideoType_Live || video.Type == VideoType_PreviewLive { + video.RandomPlayDuration = getSimulationDuration(vc.configs.Live.SleepRandom) + } else { + video.RandomPlayDuration = getSimulationDuration(vc.configs.Live.SleepRandom) + } + // get simulation play duration if video.SimulationPlayDuration != 0 { video.PlayDuration = video.SimulationPlayDuration } else { - if video.Type == VideoType_Live || video.Type == VideoType_PreviewLive { - video.RandomPlayDuration = getSimulationDuration(vc.configs.Live.SleepRandom) - } else { - video.RandomPlayDuration = getSimulationDuration(vc.configs.Live.SleepRandom) - } video.PlayDuration = video.RandomPlayDuration } From 083a2058b232af7c3ce85a669fe2ebd25393df3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=81=AA?= Date: Wed, 20 Sep 2023 14:46:34 +0800 Subject: [PATCH 5/5] fix: invalid sleep random play duration for feed --- hrp/pkg/uixt/video_crawler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hrp/pkg/uixt/video_crawler.go b/hrp/pkg/uixt/video_crawler.go index aa374cca..0cec910c 100644 --- a/hrp/pkg/uixt/video_crawler.go +++ b/hrp/pkg/uixt/video_crawler.go @@ -389,7 +389,7 @@ func (vc *VideoCrawler) getCurrentVideo() (video *Video, err error) { if video.Type == VideoType_Live || video.Type == VideoType_PreviewLive { video.RandomPlayDuration = getSimulationDuration(vc.configs.Live.SleepRandom) } else { - video.RandomPlayDuration = getSimulationDuration(vc.configs.Live.SleepRandom) + video.RandomPlayDuration = getSimulationDuration(vc.configs.Feed.SleepRandom) } // get simulation play duration