From 9d3c3d57cc7b98366d8c609344c7c01c7a4d7646 Mon Sep 17 00:00:00 2001 From: Divyansh-Jaiswal <110939626+Divyansh-Jaiswal@users.noreply.github.com> Date: Mon, 19 Jan 2026 02:54:13 +0530 Subject: [PATCH] Update scrolluntilvisible-for-fragments.md to stop infinite loop This PR improves the scrollUntilVisible implementation to handle edge cases in fragment-based layouts and slow-loading content. Key changes Retry limit added: Loops are capped at 10 retries to prevent infinite loops in CI pipelines. Slow UI support: Added waitForAnimationToEnd after each swipe to ensure elements have time to render after scrolling. Explicit final assertion: Ensures tests fail clearly if the element is never found, improving test reliability. Benefits Works reliably with fragment-based layouts. Prevents CI hangs due to infinite loops. Handles network-loaded or animation-heavy screens gracefully. Provides clear failure messages when elements are missing. --- .../scrolluntilvisible-for-fragments.md | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/advanced/recipes/scrolluntilvisible-for-fragments.md b/advanced/recipes/scrolluntilvisible-for-fragments.md index 4b675f12..bcb4fb56 100644 --- a/advanced/recipes/scrolluntilvisible-for-fragments.md +++ b/advanced/recipes/scrolluntilvisible-for-fragments.md @@ -17,30 +17,43 @@ Working with their test developers and other folks in the community, we develope ```yaml -- evalScript: ${output.foundElement = 0} +# Initialize state +- evalScript: ${output.foundElement = false} +- evalScript: ${output.retries = 0} -# Check if it's already visible +# Check if element is already visible - runFlow: when: visible: id: "the_thing_we_want" commands: - - evalScript: ${output.foundElement = 1} + - evalScript: ${output.foundElement = true} -# Loop until found +# Loop until element is found or retries exhausted - repeat: while: - true: ${output.foundElement == 0} + true: ${!output.foundElement && output.retries < 10} commands: - # Swipe up, from 90% down the screen to 75% down the screen + # Swipe vertically in the bottom portion of the screen (fragment-safe) - swipe: start: 50%, 90% end: 50%, 75% - # Check if it's visible yet + + # Wait for UI / animation to settle + - waitForAnimationToEnd + + # Check visibility again - runFlow: when: visible: id: "the_thing_we_want" commands: - - evalScript: ${output.foundElement = 1} + - evalScript: ${output.foundElement = true} + + # Increment retry counter + - evalScript: ${output.retries += 1} + +# Final assertion to ensure the element is visible +- assertVisible: + id: "the_thing_we_want" ```