Skip to content

Commit

Permalink
Handle empty topics during baseline profile generation
Browse files Browse the repository at this point in the history
Change-Id: I8655a51908e0c994d40cd2ea242723d65cc201c6
  • Loading branch information
keyboardsurfer committed Mar 19, 2024
1 parent a6ef205 commit a29d899
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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() {
Expand Down

0 comments on commit a29d899

Please sign in to comment.