Search code examples
androidkotlinuser-interfacetestingandroid-espresso

Difference between specifying a view as isRoot() & withId


I want to know the difference in specifying a view in different ways

onView(withId(R.id.btnAuthLogin)).perform(click());

onView(isRoot()).perform(waitId(R.id.btnAuthLogin, 1000));

It's not the delay thing that i want to know

What happens when we specify isRoot() rather than specifying withID.

Hope there is no confusion.


Solution

  • isRoot() returns the root view of your layout, such as the constraint or relative layout hosting your views.

    withId() returns the view with a matching ID from the layout, or throws an error showing the structure of your view hierarchy

    You set a views Id in XML using android:id="@+id/your_id_here"