Fix selecting authors

pull/458/head
mlykotom 2 years ago
parent eea70382d6
commit 1a36ae50ef

@ -48,7 +48,7 @@ class BaselineProfileGenerator {
// Scroll the feed critical user journey // Scroll the feed critical user journey
forYouWaitForContent() forYouWaitForContent()
forYouSelectAuthors() forYouSelectAuthors(true)
forYouScrollFeedDownUp() forYouScrollFeedDownUp()
// Navigate to saved screen // Navigate to saved screen

@ -18,11 +18,9 @@ package com.google.samples.apps.nowinandroid.foryou
import androidx.benchmark.macro.MacrobenchmarkScope import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.test.uiautomator.By import androidx.test.uiautomator.By
import androidx.test.uiautomator.Direction.RIGHT
import androidx.test.uiautomator.Until import androidx.test.uiautomator.Until
import androidx.test.uiautomator.untilHasChildren import androidx.test.uiautomator.untilHasChildren
import com.google.samples.apps.nowinandroid.flingElementDownUp import com.google.samples.apps.nowinandroid.flingElementDownUp
import kotlin.random.Random.Default.nextInt
fun MacrobenchmarkScope.forYouWaitForContent() { fun MacrobenchmarkScope.forYouWaitForContent() {
// Wait until content is loaded by checking if authors are loaded // Wait until content is loaded by checking if authors are loaded
@ -33,21 +31,40 @@ fun MacrobenchmarkScope.forYouWaitForContent() {
obj.wait(untilHasChildren(), 30_000) 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")) 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 val horizontalMargin = 10 * authors.visibleBounds.width() / 100
authors.setGestureMargins(horizontalMargin, 0, horizontalMargin, 0) authors.setGestureMargins(horizontalMargin, 0, horizontalMargin, 0)
// select some random authors to show some feed content // Select some authors to show some feed content
repeat(3) { repeat(3) { index ->
// picks randomly from visible authors val author = authors.children[index % authors.childCount]
val randomChild = nextInt(0, authors.childCount)
val author = authors.children[randomChild] when {
author.click() // Author wasn't checked, so just do that
device.waitForIdle() !author.isChecked -> {
authors.fling(RIGHT) 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()
}
}
else -> {
// The author is checked, but we don't recheck it
}
}
} }
} }

Loading…
Cancel
Save