lundi 25 avril 2016

Android Espresso - No views in hierarchy found matching

I have an android app that I'm trying to do some basic testing on.

public class TimePickerTest {

@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class);

@Test
public void timePickerReturnsATime() {

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

When I run this, I get "No views in hierarchy found matching". And it lists up a huge list of the hierarchy. The beginning looks like this:

View Hierarchy:
+>DecorView{id=-1, visibility=VISIBLE, width=1080, height=1920, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2} |
+->LinearLayout{id=-1, visibility=VISIBLE, width=1080, height=1776, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2} |
+-->ViewStub{id=16909225, res-name=action_mode_bar_stub, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}

It has tons of views which is hard to identify and the id number doesn't make sense to me. How do I access the views I want? Do I have to start at the home screen and navigate me to the view I want?

The only view I have managed to access yet, is the fragment_container, but I can't figure out where to go from there.

Aucun commentaire:

Enregistrer un commentaire