|
|
|
@ -18,11 +18,9 @@ package com.google.samples.apps.nowinandroid.foryou
|
|
|
|
|
|
|
|
|
|
import androidx.benchmark.macro.MacrobenchmarkScope
|
|
|
|
|
import androidx.test.uiautomator.By
|
|
|
|
|
import androidx.test.uiautomator.Direction.RIGHT
|
|
|
|
|
import androidx.test.uiautomator.Until
|
|
|
|
|
import androidx.test.uiautomator.untilHasChildren
|
|
|
|
|
import com.google.samples.apps.nowinandroid.flingElementDownUp
|
|
|
|
|
import kotlin.random.Random.Default.nextInt
|
|
|
|
|
|
|
|
|
|
fun MacrobenchmarkScope.forYouWaitForContent() {
|
|
|
|
|
// Wait until content is loaded by checking if authors are loaded
|
|
|
|
@ -33,21 +31,40 @@ fun MacrobenchmarkScope.forYouWaitForContent() {
|
|
|
|
|
obj.wait(untilHasChildren(), 30_000)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun MacrobenchmarkScope.forYouSelectAuthors() {
|
|
|
|
|
/**
|
|
|
|
|
* Selects some authors, which will show the feed content for them.
|
|
|
|
|
* [recheckAuthorsIfChecked] Authors may be already checked from the previous iteration.
|
|
|
|
|
*/
|
|
|
|
|
fun MacrobenchmarkScope.forYouSelectAuthors(recheckAuthorsIfChecked: Boolean = false) {
|
|
|
|
|
val authors = device.findObject(By.res("forYou:authors"))
|
|
|
|
|
|
|
|
|
|
// set gesture margin from sides not to trigger system gesture navigation
|
|
|
|
|
// Set gesture margin from sides not to trigger system gesture navigation
|
|
|
|
|
val horizontalMargin = 10 * authors.visibleBounds.width() / 100
|
|
|
|
|
authors.setGestureMargins(horizontalMargin, 0, horizontalMargin, 0)
|
|
|
|
|
|
|
|
|
|
// select some random authors to show some feed content
|
|
|
|
|
repeat(3) {
|
|
|
|
|
// picks randomly from visible authors
|
|
|
|
|
val randomChild = nextInt(0, authors.childCount)
|
|
|
|
|
val author = authors.children[randomChild]
|
|
|
|
|
// Select some authors to show some feed content
|
|
|
|
|
repeat(3) { index ->
|
|
|
|
|
val author = authors.children[index % authors.childCount]
|
|
|
|
|
|
|
|
|
|
when {
|
|
|
|
|
// Author wasn't checked, so just do that
|
|
|
|
|
!author.isChecked -> {
|
|
|
|
|
author.click()
|
|
|
|
|
device.waitForIdle()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The author was checked already and we want to recheck it, so just do it twice
|
|
|
|
|
recheckAuthorsIfChecked -> {
|
|
|
|
|
repeat(2) {
|
|
|
|
|
author.click()
|
|
|
|
|
device.waitForIdle()
|
|
|
|
|
authors.fling(RIGHT)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else -> {
|
|
|
|
|
// The author is checked, but we don't recheck it
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|