-
Notifications
You must be signed in to change notification settings - Fork 0
Check if a button is displayed on the screen
Devrath edited this page Mar 4, 2024
·
2 revisions
@Composable
fun DisplayButtonDemo() {
Button(
modifier = Modifier.semantics { contentDescription = "Hello World" },
onClick = {}) {
Text(text = "Hello World!")
}
}
class DisplayButtonDemoKtTest {
// This rule is used to test if there os just a composable we are testing without activity
@get:Rule
val composeTestRule = createComposeRule()
@Test
fun myTest() {
// <------------------------ ASSIGN ------------------------>
val textToBeMatched = "Hello World"
// Set the content
composeTestRule.setContent {
DisplayButtonDemo()
}
// <------------------------ ACT -------------------------->
// Find the composable on the UI tree
composeTestRule.onNodeWithText(textToBeMatched).isDisplayed()
}
}