mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 00:37:03 +05:30
feat(benchmark): restore full UI exploration
This commit is contained in:
parent
4137d73539
commit
7c59130af9
4 changed files with 37 additions and 35 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2022 Harsh Shandilya.
|
* Copyright © 2022-2023 Harsh Shandilya.
|
||||||
* Use of this source code is governed by an MIT-style
|
* Use of this source code is governed by an MIT-style
|
||||||
* license that can be found in the LICENSE file or at
|
* license that can be found in the LICENSE file or at
|
||||||
* https://opensource.org/licenses/MIT.
|
* https://opensource.org/licenses/MIT.
|
||||||
|
@ -50,7 +50,17 @@ class BaselineProfileBenchmark {
|
||||||
startupMode = StartupMode.COLD,
|
startupMode = StartupMode.COLD,
|
||||||
compilationMode = compilationMode
|
compilationMode = compilationMode
|
||||||
) {
|
) {
|
||||||
|
device.executeShellCommand("pm clear $PACKAGE_NAME")
|
||||||
|
|
||||||
startActivityAndWait()
|
startActivityAndWait()
|
||||||
|
|
||||||
|
device.waitForIdle()
|
||||||
|
|
||||||
|
device.savePosts()
|
||||||
|
|
||||||
|
device.exploreScreens()
|
||||||
|
|
||||||
|
device.returnToHottestScreen()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,16 @@ class BaselineProfileGenerator {
|
||||||
packageName = PACKAGE_NAME,
|
packageName = PACKAGE_NAME,
|
||||||
maxIterations = 8,
|
maxIterations = 8,
|
||||||
) {
|
) {
|
||||||
|
device.executeShellCommand("pm clear $PACKAGE_NAME")
|
||||||
|
|
||||||
startActivityAndWait()
|
startActivityAndWait()
|
||||||
|
|
||||||
|
device.waitForIdle()
|
||||||
|
|
||||||
|
device.savePosts()
|
||||||
|
|
||||||
|
device.exploreScreens()
|
||||||
|
|
||||||
|
device.returnToHottestScreen()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,56 +6,38 @@
|
||||||
*/
|
*/
|
||||||
package dev.msfjarvis.claw.benchmark
|
package dev.msfjarvis.claw.benchmark
|
||||||
|
|
||||||
import androidx.benchmark.macro.MacrobenchmarkScope
|
|
||||||
import androidx.test.uiautomator.By
|
import androidx.test.uiautomator.By
|
||||||
|
import androidx.test.uiautomator.BySelector
|
||||||
import androidx.test.uiautomator.UiDevice
|
import androidx.test.uiautomator.UiDevice
|
||||||
import androidx.test.uiautomator.UiObject2
|
import androidx.test.uiautomator.UiObject2
|
||||||
import androidx.test.uiautomator.Until
|
import androidx.test.uiautomator.Until
|
||||||
|
|
||||||
const val PACKAGE_NAME = "dev.msfjarvis.claw.android.benchmark"
|
const val PACKAGE_NAME = "dev.msfjarvis.claw.android.benchmark"
|
||||||
private const val AWAIT_TIMEOUT = 10_000L
|
private const val AWAIT_TIMEOUT = 10_000L
|
||||||
private const val SAVE_BUTTON_DESC = "Add to saved posts"
|
private const val SAVE_BUTTON_ID = "save_button"
|
||||||
private const val NAV_ID_HOTTEST = "HOTTEST"
|
private const val NAV_ID_HOTTEST = "HOTTEST"
|
||||||
private const val NAV_ID_NEWEST = "NEWEST"
|
private const val NAV_ID_NEWEST = "NEWEST"
|
||||||
private const val NAV_ID_SAVED = "SAVED"
|
private const val NAV_ID_SAVED = "SAVED"
|
||||||
private const val COMMENT_BUTTON_DESC = "Open comments"
|
|
||||||
|
|
||||||
@Suppress("Unused")
|
fun UiDevice.savePosts() {
|
||||||
fun MacrobenchmarkScope.exploreUI(device: UiDevice) {
|
waitForObject(By.res(SAVE_BUTTON_ID)).click()
|
||||||
startActivityAndWait()
|
|
||||||
device.run {
|
|
||||||
savePosts()
|
|
||||||
|
|
||||||
exploreScreens()
|
|
||||||
|
|
||||||
returnToHottestScreen()
|
|
||||||
|
|
||||||
openCommentsScreen()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun UiDevice.waitForSubmitterName() {
|
|
||||||
wait(Until.hasObject(By.textContains("Submitted by")), AWAIT_TIMEOUT)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun UiDevice.savePosts() {
|
|
||||||
waitForSubmitterName()
|
|
||||||
findObjects(By.desc(SAVE_BUTTON_DESC)).forEach(UiObject2::click)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun UiDevice.exploreScreens() {
|
fun UiDevice.exploreScreens() {
|
||||||
listOf(NAV_ID_HOTTEST, NAV_ID_NEWEST, NAV_ID_SAVED).forEach { tag ->
|
listOf(NAV_ID_HOTTEST, NAV_ID_NEWEST, NAV_ID_SAVED).forEach { tag ->
|
||||||
findObject(By.res(tag)).click()
|
waitForObject(By.res(tag)).click()
|
||||||
waitForSubmitterName()
|
waitForIdle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun UiDevice.returnToHottestScreen() {
|
fun UiDevice.returnToHottestScreen() {
|
||||||
findObject(By.res(NAV_ID_HOTTEST)).click()
|
waitForObject(By.res(NAV_ID_HOTTEST)).click()
|
||||||
waitForSubmitterName()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun UiDevice.openCommentsScreen() {
|
private fun UiDevice.waitForObject(selector: BySelector, timeout: Long = AWAIT_TIMEOUT): UiObject2 {
|
||||||
waitForSubmitterName()
|
if (wait(Until.hasObject(selector), timeout)) {
|
||||||
findObjects(By.desc(COMMENT_BUTTON_DESC)).first().click()
|
return findObject(selector)
|
||||||
|
}
|
||||||
|
|
||||||
|
error("Object with selector [$selector] not found")
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,7 +207,7 @@ private fun CommentsButton(
|
||||||
imageVector = Icons.Filled.Comment,
|
imageVector = Icons.Filled.Comment,
|
||||||
tint = MaterialTheme.colorScheme.secondary,
|
tint = MaterialTheme.colorScheme.secondary,
|
||||||
contentDescription = "Open comments",
|
contentDescription = "Open comments",
|
||||||
modifier = Modifier.align(Alignment.Center),
|
modifier = Modifier.align(Alignment.Center).testTag("comments_button"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue