From 3d524d95ccdcc014e133ebd0d73550190b4c5405 Mon Sep 17 00:00:00 2001 From: mlykotom Date: Mon, 23 Jan 2023 10:53:00 +0100 Subject: [PATCH] Fix selecting topics Change-Id: I958ad68ead1dffce0916dd5d6b7bff275b201fc7 --- .../apps/nowinandroid/foryou/ForYouActions.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt b/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt index b407dfcb1..5e4952fbb 100644 --- a/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt +++ b/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt @@ -44,11 +44,20 @@ fun MacrobenchmarkScope.forYouSelectTopics(recheckTopicsIfChecked: Boolean = fal topics.setGestureMargins(horizontalMargin, 0, horizontalMargin, 0) // Select some topics to show some feed content - repeat(3) { index -> + var index = 0 + var visited = 0 + + while (visited < 3) { // Selecting some topics, which will populate items in the feed. val topic = topics.children[index % topics.childCount] // Find the checkable element to figure out whether it's checked or not val topicCheckIcon = topic.findObject(By.checkable(true)) + // Topic icon may not be visible if it's out of the screen boundaries + // If that's the case, let's try another index + if (topicCheckIcon == null) { + index++ + continue + } when { // Topic wasn't checked, so just do that @@ -69,6 +78,9 @@ fun MacrobenchmarkScope.forYouSelectTopics(recheckTopicsIfChecked: Boolean = fal // Topic is checked, but we don't recheck it } } + + index++ + visited++ } }