jeudi 3 mai 2018

Espresso no views in hierarchy for Alert Dialog ids

I'm trying to find elements which make up an Alert Dialog (from v7.appcompact which contains a title, a message, and a button1) based on their id, however I'm consistently getting NoMatchingViewException: No views in hierarchy found despite the fact that the id is shown in the View Hierarchy that Espresso prints out. For example onView(withId(R.id.alertTitle)) results in:

android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: com.XXX.android.YYY/alertTitle
View Hierarchy:
+------>DialogTitle{id=16909043, res-name=alertTitle, visibility=VISIBLE, width=393, height=41, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@3165406, tag=null, root-is-layout-requested=false, has-input-connection=false, x=36.0, y=27.0, text=Error, input-type=0, ime-target=false, has-links=false}

I've tried explicitly stating that R should be for android.support.v7.appcompat as well as the main app however I've had no luck. I can find the views I want using withText however I'd really prefer to go by id.

Does anyone have any suggestions/examples of how to do this? I feel like there is something obvious that I am missing, but that I can't see it because I'm new to Espresso.

Aucun commentaire:

Enregistrer un commentaire