0

I took a Codelab Lunch-tray App it had no Tests so I tried to create these tests to practice. I tried to create testcases for it based on another codelab Codelab Cupcake The way these 2 projects differ is that on the second codelab(Lunch-tray) the "Next" button is in uppercase. Which I can not figure out how to write a test to make it pass.

enter image description here

enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Lixo
  • 71
  • 11

2 Answers2

0
val myNextButton = composeTestRule.activity.getString(R.string.btn_next).uppercase()
composeTestRule.onNodeWithText(myNextButton).performClick()
navController.assertCurrentRouteName(LixoPlayScreen.SideDishScreen.name)

This seems to work, but on mouse over activity I see this message

Avoid calling often as it can involve synchronization and can be slow.

blackgreen
  • 34,072
  • 23
  • 111
  • 129
Lixo
  • 71
  • 11
0

In the onNodeWithText method you can set the ignoreCase to true.

Something like:

    composeTestRule.onNodeWithText(
          text = composeTestRule.activity.getString(R.string.next),
          ignoreCase = true)
        .performClick()

In the codelab, to use the onNodeWithStringId method just change:

fun <A : ComponentActivity> AndroidComposeTestRule<ActivityScenarioRule<A>, A>.onNodeWithStringId(
   @StringRes id: Int
): SemanticsNodeInteraction = onNodeWithText(activity.getString(id),ignoreCase = true)
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841