2017-09-19 6 views
0

나는 에스프레소에 초보자입니다. 내가 ID configuration 다음 ID add_sound과 하위 항목에 클릭으로 항목에 클릭을 수행하고자하는에스 프레소에서 아이템을 구하십시오.

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 

    <item 
     android:id="@+id/configuration" 
     android:icon="@drawable/ic_settings" 
     android:title="Configuration" 
     app:showAsAction="ifRoom"> 

     <menu> 
      <item 
       android:id="@+id/add_sound" 
       android:title="Add a sound" 
       app:showAsAction="ifRoom" /> 

      <item 
       android:id="@+id/takeof_sound" 
       android:enabled="false" 
       android:title="Take of the sound" 
       app:showAsAction="ifRoom" /> 

      <item 
       android:id="@+id/add_image" 
       android:title="Add an image" 
       app:showAsAction="ifRoom" /> 

      <item 
       android:id="@+id/takeof_image" 
       android:enabled="false" 
       android:title="Take of the image" 
       app:showAsAction="ifRoom" /> 
     </menu> 

    </item> 

    <item 
     android:id="@+id/add" 
     android:icon="@drawable/ic_add" 
     android:title="Add" 
     app:showAsAction="ifRoom" /> 
</menu> 

:이 menu.xml 파일이 있습니다.

android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: com.example.adrien.smartalarm:id/add_sound 
If the target view is not part of the view hierarchy, you may need to use Espresso.onData to load it from one of the following AdapterViews:android.support.v7.widget.MenuPopupWindow$MenuDropDownListView{5a0c4d8 VFED.VC.. .F...... 0,0-686,672} 

내가 한 일에 어떤 문제가 :이 오류 그러나

public void menuConfigurationTest() 
    { 
     onView(withId(R.id.configuration)).perform(click()); 
     onView(withId(R.id.add_sound)).perform(click()); 
    } 

: 그래서, 나는이 코드를 입력 한?

답변

1

문제는 하위 메뉴가 활동의보기 계층 구조에 속하지 않는 PopupWindow에 표시된다는 점입니다. 따라서 다음을 추가해야합니다.

.inRoot(RootMatchers.isPlatformPopup()) 

다음 항목은 MenuDropDownListView라는 특수 ListView에 표시됩니다. 따라서 onView()는 여기서 작동하지 않습니다. onData()를 사용해야합니다.

따라서 전체 식입니다 :

onData(CoreMatchers.anything()) 
     .inRoot(RootMatchers.isPlatformPopup()) // isPlatformPopup() == is in PopupWindow 
     .inAdapterView(CoreMatchers.<View>instanceOf(MenuPopupWindow.MenuDropDownListView.class)) 
     .atPosition(0) // for the first submenu item, here: add_sound 
     .perform(click());