From a29d8991cdaf283ec7c9d802c0e52064ad0e4941 Mon Sep 17 00:00:00 2001 From: Ben Weiss Date: Tue, 19 Mar 2024 15:06:56 +0100 Subject: [PATCH] Handle empty topics during baseline profile generation Change-Id: I8655a51908e0c994d40cd2ea242723d65cc201c6 --- .../apps/nowinandroid/foryou/ForYouActions.kt | 12 +++++++++--- .../apps/nowinandroid/interests/InterestsActions.kt | 10 +++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/benchmarks/src/main/kotlin/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt b/benchmarks/src/main/kotlin/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt index 20b941a243..2b1519b667 100644 --- a/benchmarks/src/main/kotlin/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt +++ b/benchmarks/src/main/kotlin/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt @@ -16,6 +16,7 @@ package com.google.samples.apps.nowinandroid.foryou +import android.util.Log import androidx.benchmark.macro.MacrobenchmarkScope import androidx.test.uiautomator.By import androidx.test.uiautomator.Until @@ -25,6 +26,8 @@ import com.google.samples.apps.nowinandroid.waitAndFindObject import com.google.samples.apps.nowinandroid.waitForObjectOnTopAppBar import org.junit.Assert.fail +private const val TAG = "ForYouActions" + fun MacrobenchmarkScope.forYouWaitForContent() { // Wait until content is loaded by checking if topics are loaded device.wait(Until.gone(By.res("loadingWheel")), 5_000) @@ -41,6 +44,12 @@ fun MacrobenchmarkScope.forYouWaitForContent() { */ fun MacrobenchmarkScope.forYouSelectTopics(recheckTopicsIfChecked: Boolean = false) { val topics = device.findObject(By.res("forYou:topicSelection")) + val withChildren = topics.childCount != 0 + if (!withChildren) { + // TODO: Ensure ForYou has topics. + Log.w(TAG, "no topics found, can't scroll for baseline profile generation.") + return + } // Set gesture margin from sides not to trigger system gesture navigation val horizontalMargin = 10 * topics.visibleBounds.width() / 100 @@ -51,9 +60,6 @@ fun MacrobenchmarkScope.forYouSelectTopics(recheckTopicsIfChecked: Boolean = fal var visited = 0 while (visited < 3) { - if (topics.childCount == 0) { - fail("No topics found, can't generate profile for ForYou page.") - } // 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 diff --git a/benchmarks/src/main/kotlin/com/google/samples/apps/nowinandroid/interests/InterestsActions.kt b/benchmarks/src/main/kotlin/com/google/samples/apps/nowinandroid/interests/InterestsActions.kt index 05b276faab..db7b46c8c5 100644 --- a/benchmarks/src/main/kotlin/com/google/samples/apps/nowinandroid/interests/InterestsActions.kt +++ b/benchmarks/src/main/kotlin/com/google/samples/apps/nowinandroid/interests/InterestsActions.kt @@ -16,12 +16,15 @@ package com.google.samples.apps.nowinandroid.interests +import android.util.Log import androidx.benchmark.macro.MacrobenchmarkScope import androidx.test.uiautomator.By import androidx.test.uiautomator.Until import com.google.samples.apps.nowinandroid.flingElementDownUp import com.google.samples.apps.nowinandroid.waitForObjectOnTopAppBar +private const val TAG = "InterestsActions" + fun MacrobenchmarkScope.goToInterestsScreen() { device.findObject(By.text("Interests")).click() device.waitForIdle() @@ -35,7 +38,12 @@ fun MacrobenchmarkScope.goToInterestsScreen() { fun MacrobenchmarkScope.interestsScrollTopicsDownUp() { device.wait(Until.hasObject(By.res("interests:topics")), 5_000) val topicsList = device.findObject(By.res("interests:topics")) - device.flingElementDownUp(topicsList) + if (topicsList != null) { + // TODO: Ensure topics are availble. + device.flingElementDownUp(topicsList) + } else { + Log.w(TAG, "No topics found, can't scroll during baseline profile generation.") + } } fun MacrobenchmarkScope.interestsWaitForTopics() {