Skip to content

Commit

Permalink
fix: fix issue related to baseline profile generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ImaginativeShohag committed Dec 21, 2024
1 parent 523ce4d commit f3e36c4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ private fun MenuItem(
) {
Text(
modifier = Modifier
.testTag(item.testTag)
.fillMaxWidth(),
text = buildAnnotatedString {
append(item.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ data class Tutorial(
val name: String,
val description: String? = null,
val route: TutorialsScreen,
val level: TutorialLevel
val level: TutorialLevel,
val testTag: String = "tutorial-${route.route}"
) {
companion object {
val tutorialList = listOf(
Expand Down Expand Up @@ -150,7 +151,8 @@ data class Tutorial(
name = "Navigation blank screen issue",
description = "Solutions for `popBackStack()` blank screen issue.",
route = TutorialsScreen.TutorialPopBackStack,
level = TutorialLevel.Intermediate
level = TutorialLevel.Intermediate,
testTag = "tutorial-popbackstack"
),
Tutorial(
name = "Baseline profiles",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@

package org.imaginativeworld.whynotcompose.benchmarks.baselineprofile

import android.util.Log
import androidx.benchmark.macro.junit4.BaselineProfileRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import org.imaginativeworld.whynotcompose.benchmarks.commonModuleTraverseActions
import org.imaginativeworld.whynotcompose.benchmarks.clickAndWaitForIdle
import org.imaginativeworld.whynotcompose.benchmarks.dumpWindowHierarchy
import org.imaginativeworld.whynotcompose.benchmarks.pressBackAndWaitForIdle
import org.imaginativeworld.whynotcompose.benchmarks.startActivityAndAllowNotifications
import org.imaginativeworld.whynotcompose.benchmarks.waitAndFindObject
import org.imaginativeworld.whynotcompose.benchmarks.waitAndFindObjects
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -97,10 +101,34 @@ class TutorialsModuleBaselineProfile {
// Wait for home screen
device.waitAndFindObject(By.res("screen:home"), 5_000)

commonModuleTraverseActions(
moduleButtonText = "Tutorials",
screenTag = "screen:tutorials:index"
)
val moduleButtonText = "Tutorials"
val screenTag = "screen:tutorials:index"

val moduleButton = device.findObject(By.text(moduleButtonText))
device.clickAndWaitForIdle(moduleButton)

val items = device.waitAndFindObjects(By.res("list-item"), 5_000)

Log.d("BaselineProfileGenerator", "hierarchy: ${device.dumpWindowHierarchy()}")

val count = items.count()

for (i in 0..<count) {
device.waitAndFindObject(By.res(screenTag), 5_000)
val items = device.waitAndFindObjects(By.res("list-item"), 5_000)

// PopBackStack tutorial is open a new activity, so the go back will not work.
// So we will ignore this item traverse.
val popBackStackItem = items[i].findObject(By.res("tutorial-popbackstack"))
if (popBackStackItem != null) continue
// ----------------------------------------------------------------

device.clickAndWaitForIdle(items[i])

Thread.sleep(2_000)

device.pressBackAndWaitForIdle()
}
}
}
}

0 comments on commit f3e36c4

Please sign in to comment.