From 7aacb36b2e8408716cb305d50c0ff7bf0bbd2066 Mon Sep 17 00:00:00 2001 From: buyuxiang <347586493@qq.com> Date: Sat, 26 Aug 2023 08:59:47 +0800 Subject: [PATCH] optimize ClosePopupsHandler --- hrp/pkg/uixt/action.go | 5 ++++- hrp/pkg/uixt/popups.go | 14 ++++++++------ hrp/pkg/uixt/service_vedem_test.go | 29 ++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/hrp/pkg/uixt/action.go b/hrp/pkg/uixt/action.go index 334e3fb3..5f803fe7 100644 --- a/hrp/pkg/uixt/action.go +++ b/hrp/pkg/uixt/action.go @@ -232,6 +232,9 @@ func (o *ActionOptions) screenshotActions() []string { if len(o.ScreenShotWithUITypes) > 0 { actions = append(actions, "ui") } + if o.ScreenShotWithClose { + actions = append(actions, "close") + } return actions } @@ -641,7 +644,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) (err error) { } return dExt.VideoCrawler(configs) case ACTION_ClosePopups: - return dExt.ClosePopup(action.GetOptions()...) + return dExt.ClosePopups(action.GetOptions()...) } return nil } diff --git a/hrp/pkg/uixt/popups.go b/hrp/pkg/uixt/popups.go index 6981e69a..ecbebc22 100644 --- a/hrp/pkg/uixt/popups.go +++ b/hrp/pkg/uixt/popups.go @@ -92,7 +92,7 @@ type PopupInfo struct { Point PointF `json:"point"` } -func (dExt *DriverExt) ClosePopup(options ...ActionOption) error { +func (dExt *DriverExt) ClosePopups(options ...ActionOption) error { actionOptions := NewActionOptions(options...) // default to retry 5 times @@ -103,10 +103,10 @@ func (dExt *DriverExt) ClosePopup(options ...ActionOption) error { if builtin.IsZeroFloat64(actionOptions.Interval) { options = append(options, WithInterval(1)) } - return dExt.ClosePopupHandler(options...) + return dExt.ClosePopupsHandler(options...) } -func (dExt *DriverExt) ClosePopupHandler(options ...ActionOption) error { +func (dExt *DriverExt) ClosePopupsHandler(options ...ActionOption) error { actionOptions := NewActionOptions(options...) maxRetryTimes := actionOptions.MaxRetryTimes interval := actionOptions.Interval @@ -115,10 +115,12 @@ func (dExt *DriverExt) ClosePopupHandler(options ...ActionOption) error { screenResult, err := dExt.GetScreenResult( WithScreenShotClose(true), WithScreenShotUpload(true)) if err != nil { - return errors.Wrap(err, "get screen result failed for popup handler") + log.Error().Err(err).Msg("get screen result failed for popup handler") + continue } - - // not popup, fast return + // 1. there are no popups here (fast return normally) + // 2. failed to close popup (maybe tap error, return error) + // 3. successful to close popup (sleep and wait for next retry if existed) if screenResult.Popup == nil { break } diff --git a/hrp/pkg/uixt/service_vedem_test.go b/hrp/pkg/uixt/service_vedem_test.go index 1ded9c0e..df7eb793 100644 --- a/hrp/pkg/uixt/service_vedem_test.go +++ b/hrp/pkg/uixt/service_vedem_test.go @@ -81,7 +81,7 @@ func TestTapUIWithScreenshot(t *testing.T) { t.Fatal(err) } - err = driver.TapByUIDetection([]string{"dyhouse", "shoppingbag"}) + err = driver.TapByUIDetection(WithScreenShotUITypes("dyhouse", "shoppingbag")) if err != nil { t.Fatal(err) } @@ -97,3 +97,30 @@ func TestDriverExtOCR(t *testing.T) { t.Logf("point.X: %v, point.Y: %v", point.X, point.Y) driverExt.Driver.TapFloat(point.X, point.Y-20) } + +func TestClosePopup(t *testing.T) { + setupAndroid(t) + + screenResult, err := driverExt.GetScreenResult( + WithScreenShotClose(true), WithScreenShotUpload(true)) + if err != nil { + t.Logf("get screen result failed for popup handler: %v", err) + return + } + + t.Logf("screen result: %v", screenResult) + + // 1. there are no popups here (fast return normally) + // 2. failed to close popup (maybe tap error, return error) + // 3. successful to close popup (sleep and wait for next retry if existed) + if screenResult.Popup == nil { + t.Log("there are no popups here") + return + } + + t.Logf("popup info: %v", screenResult.Popup) + + if err = driverExt.tapPopupHandler(screenResult.Popup); err != nil { + t.Fatal(err) + } +}