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..0fc3cb1f 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 } @@ -97,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...) @@ -160,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")) diff --git a/uixt/driver_session.go b/uixt/driver_session.go index 43bc1491..35f5cc57 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,14 +195,22 @@ 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) // 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("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