Skip to content

A fully functional Android app built entirely with Kotlin and Jetpack Compose

Improve generator to scroll feed + interests

Tomáš Mlynaričd9ddde10ea7d
diff --git a/benchmark/src/main/java/com/google/samples/apps/nowinandroid/baselineprofile/BaselineProfileGenerator.kt b/benchmark/src/main/java/com/google/samples/apps/nowinandroid/baselineprofile/BaselineProfileGenerator.kt
index 450524cc2..889b62191 100644
--- a/benchmark/src/main/java/com/google/samples/apps/nowinandroid/baselineprofile/BaselineProfileGenerator.kt
+++ b/benchmark/src/main/java/com/google/samples/apps/nowinandroid/baselineprofile/BaselineProfileGenerator.kt
@@ -19,8 +19,12 @@ package com.google.samples.apps.nowinandroid.baselineprofile
import androidx.benchmark.macro.ExperimentalBaselineProfilesApi
import androidx.benchmark.macro.junit4.BaselineProfileRule
import androidx.test.uiautomator.By
-import androidx.test.uiautomator.Direction
import com.google.samples.apps.nowinandroid.PACKAGE_NAME
+import com.google.samples.apps.nowinandroid.foryou.forYouScrollFeedDownUp
+import com.google.samples.apps.nowinandroid.foryou.forYouSelectAuthors
+import com.google.samples.apps.nowinandroid.foryou.forYouWaitForContent
+import com.google.samples.apps.nowinandroid.interests.interestsScrollPeopleDownUp
+import com.google.samples.apps.nowinandroid.interests.interestsScrollTopicsDownUp
import org.junit.Rule
import org.junit.Test
@@ -32,25 +36,31 @@ class BaselineProfileGenerator {
@get:Rule val baselineProfileRule = BaselineProfileRule()
@Test
- fun startup() =
+ fun generate() =
baselineProfileRule.collectBaselineProfile(PACKAGE_NAME) {
- pressHome()
// This block defines the app's critical user journey. Here we are interested in
// optimizing for app startup. But you can also navigate and scroll
// through your most important UI.
+
+ pressHome()
startActivityAndWait()
+
+ // Scroll the feed critical user journey
+ forYouWaitForContent()
+ forYouSelectAuthors()
+ forYouScrollFeedDownUp()
+
+ // Navigate to interests screen
+ device.findObject(By.text("Interests")).click()
device.waitForIdle()
- device.run {
- findObject(By.text("Interests"))
- .click()
- waitForIdle()
- findObject(By.text("Accessibility")).scroll(Direction.DOWN, 2000f)
- waitForIdle()
- findObject(By.text("People")).click()
- waitForIdle()
- findObject(By.textStartsWith("Android")).scroll(Direction.DOWN, 2000f)
- waitForIdle()
- }
+ interestsScrollTopicsDownUp()
+
+ // Navigate to people tab
+ device.findObject(By.text("People")).click()
+ device.waitForIdle()
+
+ interestsScrollPeopleDownUp()
}
}
+
diff --git a/benchmark/src/main/java/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt b/benchmark/src/main/java/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt
new file mode 100644
index 000000000..218e1a210
--- /dev/null
+++ b/benchmark/src/main/java/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.samples.apps.nowinandroid.foryou
+
+import androidx.benchmark.macro.MacrobenchmarkScope
+import androidx.test.uiautomator.By
+import androidx.test.uiautomator.Direction
+import androidx.test.uiautomator.Until
+
+fun MacrobenchmarkScope.forYouWaitForContent() {
+ // Wait until content is loaded
+ device.wait(Until.hasObject(By.text("What are you interested in?")), 30_000)
+}
+
+fun MacrobenchmarkScope.forYouSelectAuthors() {
+ val authors = device.findObject(By.res("forYou:authors"))
+ // select some authors to show some feed content
+ repeat(3) { index ->
+ val author = authors.children[index % authors.childCount]
+ author.click()
+ device.waitForIdle()
+ }
+}
+
+fun MacrobenchmarkScope.forYouScrollFeedDownUp() {
+ val feedList = device.findObject(By.res("forYou:feed"))
+ feedList.fling(Direction.DOWN)
+ device.waitForIdle()
+ feedList.fling(Direction.UP)
+}
diff --git a/benchmark/src/main/java/com/google/samples/apps/nowinandroid/interests/InterestsActions.kt b/benchmark/src/main/java/com/google/samples/apps/nowinandroid/interests/InterestsActions.kt
new file mode 100644
index 000000000..8dea3d308
--- /dev/null
+++ b/benchmark/src/main/java/com/google/samples/apps/nowinandroid/interests/InterestsActions.kt
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.samples.apps.nowinandroid.interests
+
+import androidx.benchmark.macro.MacrobenchmarkScope
+import androidx.test.uiautomator.By
+import androidx.test.uiautomator.Direction
+
+fun MacrobenchmarkScope.interestsScrollTopicsDownUp() {
+ val topicsList = device.findObject(By.res("interests:topics"))
+ topicsList.fling(Direction.DOWN)
+ device.waitForIdle()
+ topicsList.fling(Direction.UP)
+}
+
+fun MacrobenchmarkScope.interestsScrollPeopleDownUp() {
+ val peopleList = device.findObject(By.res("interests:people"))
+ peopleList.fling(Direction.DOWN)
+ device.waitForIdle()
+ peopleList.fling(Direction.UP)
+}
diff --git a/feature-interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/TabContent.kt b/feature-interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/TabContent.kt
index fc75bf49b..3a8c05271 100644
--- a/feature-interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/TabContent.kt
+++ b/feature-interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/TabContent.kt
@@ -29,6 +29,7 @@ import androidx.compose.foundation.shape.CircleShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
+import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import com.google.samples.apps.nowinandroid.core.model.data.FollowableAuthor
import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic
@@ -41,7 +42,9 @@ fun TopicsTabContent(
modifier: Modifier = Modifier
) {
LazyColumn(
- modifier = modifier.padding(horizontal = 16.dp),
+ modifier = modifier
+ .padding(horizontal = 16.dp)
+ .testTag("interests:topics"),
contentPadding = PaddingValues(top = 8.dp)
) {
topics.forEach { followableTopic ->
@@ -77,7 +80,9 @@ fun AuthorsTabContent(
modifier: Modifier = Modifier
) {
LazyColumn(
- modifier = modifier.padding(horizontal = 16.dp),
+ modifier = modifier
+ .padding(horizontal = 16.dp)
+ .testTag("interests:people"),
contentPadding = PaddingValues(top = 8.dp)
) {
authors.forEach { followableAuthor ->