Skip to content

Commit c06b9ce

Browse files
committed
Update ComposeTestRuleExtensions.kt
1 parent 9da739e commit c06b9ce

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

app/src/androidTest/java/com/example/reply/test/ComposeTestRuleExtensions.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,21 @@ import androidx.compose.ui.test.SemanticsNodeInteraction
2121
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
2222
import androidx.compose.ui.test.onNodeWithContentDescription
2323
import androidx.compose.ui.test.onNodeWithTag
24+
import androidx.compose.ui.test.onNodeWithText
2425
import androidx.test.ext.junit.rules.ActivityScenarioRule
2526

27+
/**
28+
* Finds a semantics node with the given string resource id.
29+
*
30+
* The [onNodeWithText] finder provided by compose ui test API, doesn't support usage of
31+
* string resource id to find the semantics node. This extension function accesses string resource
32+
* using underlying activity property and passes it to [onNodeWithText] function as argument and
33+
* returns the [SemanticsNodeInteraction] object.
34+
*/
35+
fun <A : ComponentActivity> AndroidComposeTestRule<ActivityScenarioRule<A>, A>.onNodeWithStringId(
36+
@StringRes id: Int
37+
): SemanticsNodeInteraction = onNodeWithText(activity.getString(id))
38+
2639
/**
2740
* Finds a semantics node from the content description with the given string resource id.
2841
*

0 commit comments

Comments
 (0)