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 20b941a24..6706bb97b 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 @@ -23,7 +24,8 @@ import androidx.test.uiautomator.untilHasChildren import com.google.samples.apps.nowinandroid.flingElementDownUp 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 @@ -41,6 +43,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 +59,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 05b276faa..db7b46c8c 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() {