thatMatchesActivityNamed

fun thatMatchesActivityNamed(activityClassName: String): TypeSafeMatcher<Root>

Returns a TypeSafeMatcher for Root which matches the root which belongs to the given arbitrary string activityClassName, which must contain a fully qualified class name, such as com.example.application.internal.TestActivity.

This can be used to ensure that a TypeSafeMatcher is used to match views on a specific Android Activity, even when a qualified class name is unknown to the class loader, which can be the case in end-to-end tests.

When obtaining ViewInteraction with onView, pass root matcher to ViewInteraction.inRoot. When obtaining ViewInteraction with waitForView, pass root matcher as an argument. Example:

waitForView(thatIsStopNavigationButton, rootMatcher =
thatMatchesActivity("com.example.TestNavigationActivity"))
.check(matches(isDisplayed()))
.perform(click()

onView(thatIsStopNavigationButton)
.inRoot(thatMatchesActivity("com.example.TestNavigationActivity"))
.waitForMatcher(isDisplayed())
.perform(click())