optimize ClosePopupsHandler

This commit is contained in:
buyuxiang
2023-08-28 17:59:22 +08:00
parent c6507447e2
commit 7aacb36b2e
3 changed files with 40 additions and 8 deletions
+4 -1
View File
@@ -232,6 +232,9 @@ func (o *ActionOptions) screenshotActions() []string {
if len(o.ScreenShotWithUITypes) > 0 { if len(o.ScreenShotWithUITypes) > 0 {
actions = append(actions, "ui") actions = append(actions, "ui")
} }
if o.ScreenShotWithClose {
actions = append(actions, "close")
}
return actions return actions
} }
@@ -641,7 +644,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) (err error) {
} }
return dExt.VideoCrawler(configs) return dExt.VideoCrawler(configs)
case ACTION_ClosePopups: case ACTION_ClosePopups:
return dExt.ClosePopup(action.GetOptions()...) return dExt.ClosePopups(action.GetOptions()...)
} }
return nil return nil
} }
+8 -6
View File
@@ -92,7 +92,7 @@ type PopupInfo struct {
Point PointF `json:"point"` Point PointF `json:"point"`
} }
func (dExt *DriverExt) ClosePopup(options ...ActionOption) error { func (dExt *DriverExt) ClosePopups(options ...ActionOption) error {
actionOptions := NewActionOptions(options...) actionOptions := NewActionOptions(options...)
// default to retry 5 times // default to retry 5 times
@@ -103,10 +103,10 @@ func (dExt *DriverExt) ClosePopup(options ...ActionOption) error {
if builtin.IsZeroFloat64(actionOptions.Interval) { if builtin.IsZeroFloat64(actionOptions.Interval) {
options = append(options, WithInterval(1)) 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...) actionOptions := NewActionOptions(options...)
maxRetryTimes := actionOptions.MaxRetryTimes maxRetryTimes := actionOptions.MaxRetryTimes
interval := actionOptions.Interval interval := actionOptions.Interval
@@ -115,10 +115,12 @@ func (dExt *DriverExt) ClosePopupHandler(options ...ActionOption) error {
screenResult, err := dExt.GetScreenResult( screenResult, err := dExt.GetScreenResult(
WithScreenShotClose(true), WithScreenShotUpload(true)) WithScreenShotClose(true), WithScreenShotUpload(true))
if err != nil { 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
} }
// 1. there are no popups here (fast return normally)
// not popup, fast return // 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 { if screenResult.Popup == nil {
break break
} }
+28 -1
View File
@@ -81,7 +81,7 @@ func TestTapUIWithScreenshot(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
err = driver.TapByUIDetection([]string{"dyhouse", "shoppingbag"}) err = driver.TapByUIDetection(WithScreenShotUITypes("dyhouse", "shoppingbag"))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -97,3 +97,30 @@ func TestDriverExtOCR(t *testing.T) {
t.Logf("point.X: %v, point.Y: %v", point.X, point.Y) t.Logf("point.X: %v, point.Y: %v", point.X, point.Y)
driverExt.Driver.TapFloat(point.X, point.Y-20) 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)
}
}