From f4c541d62af36d7bcd710487b6407d52bef11c20 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Wed, 23 Jul 2025 20:16:03 +0800 Subject: [PATCH 1/5] fix: abort loop when find action failed --- internal/version/VERSION | 2 +- uixt/driver_ext_swipe.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/version/VERSION b/internal/version/VERSION index d486bb38..1085f853 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0-250721 +v5.0.0-250723 diff --git a/uixt/driver_ext_swipe.go b/uixt/driver_ext_swipe.go index d8012fa0..ad41de53 100644 --- a/uixt/driver_ext_swipe.go +++ b/uixt/driver_ext_swipe.go @@ -31,7 +31,9 @@ func (dExt *XTDriver) LoopUntil(findAction, findCondition, foundAction Action, o } if err := findAction(dExt); err != nil { + // find action failed, abort loop log.Error().Err(err).Msgf("find action failed") + return err } } @@ -85,7 +87,8 @@ func prepareSwipeAction(dExt *XTDriver, params interface{}, opts ...option.Actio return err } } else { - return fmt.Errorf("invalid swipe params %v", swipeDirection) + return errors.Wrap(code.InvalidParamError, + fmt.Sprintf("invalid swipe params %v", swipeDirection)) } return nil } From af227cfcd2854c9eac8fa8c853ef1d82e518a221 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Wed, 23 Jul 2025 20:51:54 +0800 Subject: [PATCH 2/5] fix: check if synthesizeEvent timeout error and add extra retry --- uixt/driver_session.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/uixt/driver_session.go b/uixt/driver_session.go index 43bc1491..2cc26e0c 100644 --- a/uixt/driver_session.go +++ b/uixt/driver_session.go @@ -183,6 +183,8 @@ func (s *DriverSession) RequestWithRetry(method string, urlStr string, rawBody [ maxRetry = options.MaxRetryTimes } + synthesizeEventRetryAdded := false + for attempt := 1; attempt <= maxRetry; attempt++ { // Execute the request rawResp, err = s.Request(method, urlStr, rawBody, opts...) @@ -193,13 +195,20 @@ func (s *DriverSession) RequestWithRetry(method string, urlStr string, rawBody [ return rawResp, nil } + // only for WDA driver, check if "synthesizeEvent timeout" error and add extra retry + if strings.Contains(err.Error(), "synthesizeEvent timeout") && !synthesizeEventRetryAdded { + log.Warn().Err(err).Msg("synthesizeEvent timeout detected, adding one extra retry") + maxRetry++ + synthesizeEventRetryAdded = true + } + // Notice: use DeviceHTTPDriverError when request driver failed lastError = errors.Wrap(code.DeviceHTTPDriverError, err.Error()) - log.Warn().Err(err).Msgf("request failed, attempt %d/%d", attempt, s.maxRetry) + log.Warn().Err(err).Msgf("request failed, attempt %d/%d", attempt, maxRetry) // If this was the last attempt, break - if attempt == s.maxRetry { - log.Error().Err(lastError).Msgf("all %d retry attempts failed, giving up", s.maxRetry) + if attempt == maxRetry { + log.Error().Err(lastError).Msgf("all %d retry attempts failed, giving up", maxRetry) break } From 4189ccebff2b873bdc3be9167db05ec4724f79e9 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Wed, 23 Jul 2025 20:58:27 +0800 Subject: [PATCH 3/5] change: update logs --- uixt/driver_session.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/uixt/driver_session.go b/uixt/driver_session.go index 2cc26e0c..35f5cc57 100644 --- a/uixt/driver_session.go +++ b/uixt/driver_session.go @@ -204,12 +204,13 @@ func (s *DriverSession) RequestWithRetry(method string, urlStr string, rawBody [ // Notice: use DeviceHTTPDriverError when request driver failed lastError = errors.Wrap(code.DeviceHTTPDriverError, err.Error()) - log.Warn().Err(err).Msgf("request failed, attempt %d/%d", attempt, maxRetry) // If this was the last attempt, break if attempt == maxRetry { - log.Error().Err(lastError).Msgf("all %d retry attempts failed, giving up", maxRetry) + log.Error().Err(lastError).Msgf("request failed after %d retries, giving up", maxRetry) break + } else { + log.Warn().Err(lastError).Msgf("request failed after %d/%d retries, retrying", attempt, maxRetry) } // Wait before next attempt From 9037c76878d02c75fdcf43ce66efedb34514c190 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Wed, 23 Jul 2025 21:18:50 +0800 Subject: [PATCH 4/5] fix: add 1s interval for swipe to tap --- uixt/driver_ext_swipe.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uixt/driver_ext_swipe.go b/uixt/driver_ext_swipe.go index ad41de53..32d1b59d 100644 --- a/uixt/driver_ext_swipe.go +++ b/uixt/driver_ext_swipe.go @@ -100,7 +100,7 @@ func (dExt *XTDriver) SwipeToTapTexts(texts []string, opts ...option.ActionOptio } log.Info().Strs("texts", texts).Msg("swipe to tap texts") - opts = append(opts, option.WithMatchOne(true), option.WithRegex(true)) + opts = append(opts, option.WithMatchOne(true), option.WithRegex(true), option.WithInterval(1)) // Remove identifier for swipe operations to avoid WDA/UIA2 logging actionOptions := option.NewActionOptions(opts...) From 70366ed83e3d3f2bc41c24672da9ebd1903a71f4 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Wed, 23 Jul 2025 21:27:40 +0800 Subject: [PATCH 5/5] fix: add 1s interval when swipe to first screen --- uixt/driver_ext_swipe.go | 1 + 1 file changed, 1 insertion(+) diff --git a/uixt/driver_ext_swipe.go b/uixt/driver_ext_swipe.go index 32d1b59d..0fc3cb1f 100644 --- a/uixt/driver_ext_swipe.go +++ b/uixt/driver_ext_swipe.go @@ -163,6 +163,7 @@ func (dExt *XTDriver) SwipeToTapApp(appName string, opts ...option.ActionOption) // swipe to first screen for i := 0; i < 5; i++ { dExt.Swipe(0.5, 0.5, 0.9, 0.5, optionsWithoutIdentifier...) + time.Sleep(1 * time.Second) } opts = append(opts, option.WithDirection("left"))