This is my use case.
- Load a recycler view
- Click on an item that will show a dialog with a radio group
- Select a radio button (# 2) in my test
- Click OK
- Show the recycler view showing the updated text.
My unit test
@Test
public void onNonODeviceSwitchIsShown() throws Exception
{
onView(withText(getString(R.string.PushNotifications))).perform(click());
onView(withId(R.id.recycler_view))
.perform(RecyclerViewActions.actionOnItem(hasDescendant(withText(R.string.general_notification_tone)),
click()));
UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
// Search for correct button in the dialog.
UiObject toneText = uiDevice.findObject(new UiSelector().text("Adara"));
toneText.click();
UiObject2 okButton = uiDevice.findObjects(By.clazz(Button.class)).get(1);
okButton.clickAndWait(Until.newWindow(), 5000);
onView(withId(R.id.recycler_view)).check(
ViewAssertions.matches(allOf(
withText(R.string.custom))));
}
It fails with the following message, which means it does not detect any radio buttons:
androidx.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: '(with string from resource id: <2131887061>)' doesn't match the selected view. Expected: (with string from resource id: <2131887061>) Got: "RecyclerView{id=2131365043, res-name=recycler_view, visibility=VISIBLE, width=1080, height=1584, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=true, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@bc6b8c6, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=9}"
This is the dialog which upon closing will show the recycler view.
This is the part of the recycler view after the dialog is closed.
This is the line that fails
onView(withId(R.id.recycler_view)).check(
ViewAssertions.matches(allOf(
withText(R.string.custom))));
When I check the layout inspector, I see the following set up
RelativeLayout
|
| Ab (id/title) TextView - "General"
| Ab (id/summary) TextView - "Custom"
I don't know why the assertions are failing even though the Custom
text does exist in the recycler view.