Handle empty topics during baseline profile generation

Change-Id: I8655a51908e0c994d40cd2ea242723d65cc201c6
pull/1060/head
Ben Weiss 2 years ago
parent 1dfa3ebd24
commit 29243cfdf6
No known key found for this signature in database
GPG Key ID: 8424F9C1E763A74C

@ -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

@ -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() {

Loading…
Cancel
Save