Skip to content

Commit 42f2c1c

Browse files
Move from SNAPSHOT to alpha / rc
Change-Id: I75c04745b3641ad4cabd5df1e3c8b4518e9db9a6
1 parent dea3da5 commit 42f2c1c

File tree

10 files changed

+115
-22
lines changed

10 files changed

+115
-22
lines changed

benchmarks/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ baselineProfile {
6969

7070
dependencies {
7171
implementation(libs.androidx.benchmark.macro)
72+
implementation(libs.androidx.benchmark.traceprocessor)
7273
implementation(libs.androidx.test.core)
7374
implementation(libs.androidx.test.espresso.core)
7475
implementation(libs.androidx.test.ext)

benchmarks/src/main/kotlin/com/google/samples/apps/nowinandroid/GeneralActions.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package com.google.samples.apps.nowinandroid
1818

1919
import android.view.accessibility.AccessibilityNodeInfo
2020
import androidx.test.uiautomator.UiAutomatorTestScope
21-
import androidx.test.uiautomator.onView
21+
import androidx.test.uiautomator.onElement
2222
import androidx.test.uiautomator.textAsString
2323
import androidx.test.uiautomator.watcher.PermissionDialog
2424

@@ -34,12 +34,12 @@ fun UiAutomatorTestScope.startAppAndAllowPermission() {
3434
}
3535

3636
fun UiAutomatorTestScope.textVisibleOnTopAppBar(text: String) =
37-
onTopAppBar { textAsString == text && isVisibleToUser }
37+
onTopAppBar { textAsString() == text && isVisibleToUser }
3838

3939
fun UiAutomatorTestScope.onTopAppBar(
4040
timeoutMs: Long = 10000,
4141
pollIntervalMs: Long = 100,
4242
block: AccessibilityNodeInfo.() -> (Boolean),
4343
) {
44-
onView { viewIdResourceName == "niaTopAppBar" }.onView(timeoutMs, pollIntervalMs, block)
44+
onElement { viewIdResourceName == "niaTopAppBar" }.onElement(timeoutMs, pollIntervalMs, block)
4545
}

benchmarks/src/main/kotlin/com/google/samples/apps/nowinandroid/bookmarks/BookmarksActions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ import androidx.test.uiautomator.textAsString
2121
import com.google.samples.apps.nowinandroid.textVisibleOnTopAppBar
2222

2323
fun UiAutomatorTestScope.goToBookmarksScreen() {
24-
onView { textAsString == "Saved" }.click()
24+
onElement { textAsString == "Saved" }.click()
2525
textVisibleOnTopAppBar("Saved")
2626
}

benchmarks/src/main/kotlin/com/google/samples/apps/nowinandroid/foryou/ForYouActions.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import com.google.samples.apps.nowinandroid.textVisibleOnTopAppBar
2323
import org.junit.Assert.fail
2424

2525
fun UiAutomatorTestScope.forYouWaitForContent() {
26-
onViewOrNull(timeoutMs = 500) { viewIdResourceName == "loadingWheel" && !isVisibleToUser }
26+
onElementOrNull(timeoutMs = 500) { viewIdResourceName == "loadingWheel" && !isVisibleToUser }
2727
// Sometimes, the loading wheel is gone, but the content is not loaded yet
2828
// So we'll wait here for topics to be sure
2929
// Timeout here is quite big, because sometimes data loading takes a long time!
30-
onView(timeoutMs = 30_000) {
30+
onElement(timeoutMs = 30_000) {
3131
viewIdResourceName == "forYou:topicSelection" && childCount > 0 && isVisibleToUser
3232
}
3333
}
@@ -37,7 +37,7 @@ fun UiAutomatorTestScope.forYouWaitForContent() {
3737
* [recheckTopicsIfChecked] Topics may be already checked from the previous iteration.
3838
*/
3939
fun UiAutomatorTestScope.forYouSelectTopics(recheckTopicsIfChecked: Boolean = false) {
40-
onView { viewIdResourceName == "forYou:topicSelection" }.run {
40+
onElement { viewIdResourceName == "forYou:topicSelection" }.run {
4141
if (children.isEmpty()) {
4242
fail("No topics found, can't generate profile for ForYou page.")
4343
}
@@ -59,14 +59,14 @@ fun UiAutomatorTestScope.forYouSelectTopics(recheckTopicsIfChecked: Boolean = fa
5959
}
6060

6161
fun UiAutomatorTestScope.forYouScrollFeedDownUp() {
62-
onView { viewIdResourceName == "forYou:feed" }.run {
62+
onElement { viewIdResourceName == "forYou:feed" }.run {
6363
fling(Direction.DOWN)
6464
fling(Direction.UP)
6565
}
6666
}
6767

6868
fun UiAutomatorTestScope.setAppTheme(isDark: Boolean) {
69-
onView { textAsString == if (isDark) "Dark" else "Light" }.click()
70-
onView { textAsString == "OK" }.click()
69+
onElement { textAsString() == if (isDark) "Dark" else "Light" }.click()
70+
onElement { textAsString() == "OK" }.click()
7171
textVisibleOnTopAppBar("Now in Android")
7272
}

benchmarks/src/main/kotlin/com/google/samples/apps/nowinandroid/interests/InterestsActions.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ import androidx.test.uiautomator.textAsString
2222
import com.google.samples.apps.nowinandroid.textVisibleOnTopAppBar
2323

2424
fun UiAutomatorTestScope.goToInterestsScreen() {
25-
onView { textAsString == "Interests" }.click()
25+
onElement { textAsString() == "Interests" }.click()
2626
textVisibleOnTopAppBar("Interests")
2727
// Wait until content is loaded by checking if interests are loaded
28-
assert(onViewOrNull { viewIdResourceName == "loadingWheel" && !isVisibleToUser } == null)
28+
assert(onElementOrNull { viewIdResourceName == "loadingWheel" && !isVisibleToUser } == null)
2929
}
3030

3131
fun UiAutomatorTestScope.interestsScrollTopicsDownUp() {
32-
onView { viewIdResourceName == "interests:topics" }.run {
32+
onElement { viewIdResourceName == "interests:topics" }.run {
3333
// Set some margin from the sides to prevent triggering system navigation
34-
setGestureMargin(uiDevice.displayWidth / 5)
34+
setGestureMargin(device.displayWidth / 5)
3535
fling(Direction.DOWN)
3636
fling(Direction.UP)
3737
}
3838
}
3939

4040
fun UiAutomatorTestScope.interestsWaitForTopics() {
41-
onView(30_000) { textAsString == "Accessibility" }
41+
onElement(30_000) { textAsString() == "Accessibility" }
4242
}

benchmarks/src/main/kotlin/com/google/samples/apps/nowinandroid/interests/ScrollTopicListBenchmark.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616

1717
package com.google.samples.apps.nowinandroid.interests
1818

19+
import androidx.benchmark.ExperimentalBenchmarkConfigApi
20+
import androidx.benchmark.ExperimentalConfig
21+
import androidx.benchmark.StartupInsightsConfig
1922
import androidx.benchmark.macro.CompilationMode
2023
import androidx.benchmark.macro.FrameTimingMetric
2124
import androidx.benchmark.macro.StartupMode
2225
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
26+
import androidx.benchmark.perfetto.ExperimentalPerfettoCaptureApi
2327
import androidx.test.ext.junit.runners.AndroidJUnit4
2428
import androidx.test.uiautomator.textAsString
2529
import androidx.test.uiautomator.uiAutomator
@@ -30,6 +34,7 @@ import org.junit.Rule
3034
import org.junit.Test
3135
import org.junit.runner.RunWith
3236

37+
@OptIn(ExperimentalBenchmarkConfigApi::class, ExperimentalPerfettoCaptureApi::class)
3338
@RunWith(AndroidJUnit4::class)
3439
class ScrollTopicListBenchmark {
3540
@get:Rule
@@ -46,13 +51,14 @@ class ScrollTopicListBenchmark {
4651
compilationMode = compilationMode,
4752
iterations = ITERATIONS,
4853
startupMode = StartupMode.WARM,
54+
experimentalConfig = ExperimentalConfig(startupInsightsConfig = StartupInsightsConfig(true)),
4955
setupBlock = {
5056
uiAutomator {
5157
// Start the app
5258
pressHome()
5359
startAppAndAllowPermission()
5460
// Navigate to interests screen
55-
onView { textAsString == "Interests" }.click()
61+
onElement { textAsString() == "Interests" }.click()
5662
}
5763
},
5864
) {

benchmarks/src/main/kotlin/com/google/samples/apps/nowinandroid/interests/ScrollTopicListPowerMetricsBenchmark.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class ScrollTopicListPowerMetricsBenchmark {
6868
uiAutomator {
6969
pressHome()
7070
startAppAndAllowPermission()
71-
onView { contentDescription == "Settings" }.click()
71+
onElement { contentDescription == "Settings" }.click()
7272
setAppTheme(isDark)
7373
}
7474
},

benchmarks/src/main/kotlin/com/google/samples/apps/nowinandroid/interests/TopicsScreenRecompositionBenchmark.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import androidx.benchmark.macro.FrameTimingMetric
2121
import androidx.benchmark.macro.StartupMode
2222
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
2323
import androidx.test.ext.junit.runners.AndroidJUnit4
24-
import androidx.test.uiautomator.onView
24+
import androidx.test.uiautomator.onElement
2525
import androidx.test.uiautomator.textAsString
2626
import androidx.test.uiautomator.uiAutomator
2727
import com.google.samples.apps.nowinandroid.ITERATIONS
@@ -53,15 +53,15 @@ class TopicsScreenRecompositionBenchmark {
5353
pressHome()
5454
startAppAndAllowPermission()
5555
// Navigate to interests screen
56-
onView { textAsString == "Interests" }.click()
56+
onElement { textAsString() == "Interests" }.click()
5757
}
5858
},
5959
) {
6060
uiAutomator {
6161
interestsWaitForTopics()
6262
repeat(3) {
6363
// Toggle bookmarked
64-
onView { viewIdResourceName == "interests:topics" }.onView { isCheckable }
64+
onElement { viewIdResourceName == "interests:topics" }.onElement { isCheckable }
6565
.click()
6666
}
6767
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.samples.apps.nowinandroid.userjourney
18+
19+
import androidx.benchmark.macro.CompilationMode
20+
import androidx.benchmark.macro.StartupMode
21+
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
22+
import androidx.test.ext.junit.runners.AndroidJUnit4
23+
import androidx.test.uiautomator.Direction
24+
import androidx.test.uiautomator.scrollToElement
25+
import androidx.test.uiautomator.textAsString
26+
import androidx.test.uiautomator.uiAutomator
27+
import androidx.test.uiautomator.waitForStable
28+
import androidx.test.uiautomator.watcher.PermissionDialog
29+
import com.google.samples.apps.nowinandroid.BaselineProfileMetrics
30+
import com.google.samples.apps.nowinandroid.ITERATIONS
31+
import com.google.samples.apps.nowinandroid.PACKAGE_NAME
32+
import com.google.samples.apps.nowinandroid.foryou.forYouSelectTopics
33+
import org.junit.Rule
34+
import org.junit.Test
35+
import org.junit.runner.RunWith
36+
37+
@RunWith(AndroidJUnit4::class)
38+
class NewUserJourneyBenchmark {
39+
40+
@get:Rule
41+
val benchmarkRule = MacrobenchmarkRule()
42+
43+
@Test
44+
fun measureJourney() = benchmarkRule.measureRepeated(
45+
packageName = PACKAGE_NAME,
46+
metrics = BaselineProfileMetrics.allMetrics,
47+
compilationMode = CompilationMode.DEFAULT,
48+
startupMode = StartupMode.COLD,
49+
iterations = ITERATIONS,
50+
)
51+
{
52+
uiAutomator {
53+
startApp(PACKAGE_NAME)
54+
watchFor(PermissionDialog) {
55+
clickAllow()
56+
}
57+
// Select some topics
58+
forYouSelectTopics()
59+
onElement { textAsString() == "Done" }.click()
60+
onElement { isScrollable }.scroll(Direction.DOWN, 0.25f)
61+
onElement { textAsString() == "Interests" }.click()
62+
63+
activeWindowRoot().waitForStable()
64+
65+
onElement { isScrollable }.scrollToElement(
66+
direction = Direction.DOWN,
67+
block = {
68+
textAsString() == "Performance"
69+
},
70+
).click()
71+
72+
// Enable dynamic color in settings
73+
onElement { contentDescription == "Settings" }.click()
74+
onElement { textAsString() == "Yes" }.click()
75+
pressBack()
76+
77+
// Search for "AndroidX releases"
78+
onElement { contentDescription == "Search" }.click()
79+
// Wait for animations to finish
80+
activeWindowRoot().waitForStable()
81+
type("AndroidX releases")
82+
pressEnter()
83+
}
84+
}
85+
}

gradle/libs.versions.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ androidxEspresso = "3.6.1"
1818
androidxHiltNavigationCompose = "1.2.0"
1919
androidxLifecycle = "2.8.7"
2020
androidxLintGradle = "1.0.0-alpha03"
21-
androidxMacroBenchmark = "1.4.0-alpha11"
21+
androidxMacroBenchmark = "1.4.0-rc01"
2222
androidxMetrics = "1.0.0-beta01"
2323
androidxNavigation = "2.8.5"
2424
androidxProfileinstaller = "1.4.1"
@@ -27,7 +27,7 @@ androidxTestExt = "1.2.1"
2727
androidxTestRules = "1.6.1"
2828
androidxTestRunner = "1.6.2"
2929
androidxTracing = "1.3.0-alpha02"
30-
androidxUiAutomator = "2.4.0-SNAPSHOT"
30+
androidxUiAutomator = "2.4.0-alpha05"
3131
androidxWindowManager = "1.3.0"
3232
androidxWork = "2.10.0"
3333
coil = "2.7.0"
@@ -69,6 +69,7 @@ android-desugarJdkLibs = { group = "com.android.tools", name = "desugar_jdk_libs
6969
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "androidxActivity" }
7070
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidxAppCompat" }
7171
androidx-benchmark-macro = { group = "androidx.benchmark", name = "benchmark-macro-junit4", version.ref = "androidxMacroBenchmark" }
72+
androidx-benchmark-traceprocessor = { group = "androidx.benchmark", name = "benchmark-traceprocessor", version.ref = "androidxMacroBenchmark" }
7273
androidx-browser = { group = "androidx.browser", name = "browser", version.ref = "androidxBrowser" }
7374
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom-alpha", version.ref = "androidxComposeBom" }
7475
androidx-compose-foundation = { group = "androidx.compose.foundation", name = "foundation", version.ref = "androidxComposeFoundation" }

0 commit comments

Comments
 (0)