From 1a36ae50effba9062c00e141997ff457250e5abd Mon Sep 17 00:00:00 2001 From: mlykotom Date: Wed, 23 Nov 2022 18:38:27 +0100 Subject: [PATCH] Fix selecting authors --- .../BaselineProfileGenerator.kt | 2 +- .../apps/nowinandroid/foryou/ForYouActions.kt | 41 +++++++++++++------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/baselineprofile/BaselineProfileGenerator.kt b/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/baselineprofile/BaselineProfileGenerator.kt index 159506bc8..92fe3c325 100644 --- a/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/baselineprofile/BaselineProfileGenerator.kt +++ b/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/baselineprofile/BaselineProfileGenerator.kt @@ -48,7 +48,7 @@ class BaselineProfileGenerator { // Scroll the feed critical user journey forYouWaitForContent() - forYouSelectAuthors() + forYouSelectAuthors(true) forYouScrollFeedDownUp() // Navigate to saved screen diff --git a/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt b/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt index 3c33e3f13..b945aa188 100644 --- a/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt +++ b/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt @@ -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] - author.click() - device.waitForIdle() - authors.fling(RIGHT) + // 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() + } + } + + else -> { + // The author is checked, but we don't recheck it + } + } } }