0

로 inAdapterView을 설정합니다. 나는 실행하는 경우 :Espresso.onData 내가 설정 한 옵션의 목록을 포함하는에 AlertDialog가에 AlertDialog

onView(allOf(withClassName(Matchers.equalTo(AppCompatCheckedTextView.class.getName())), withText(displayName))) 
       .perform(click()); 

상황은에 AlertDialog의 옵션 목록이 완전히 표시하기에 너무 긴 경우를 제외하고, 훌륭하게 작동합니다.

그래서 대신 onData를 사용하여 항목을 찾으려고하지만 onData에서 만든 DataInteraction 객체에 어떤보기에서 데이터를 찾는지를 알 수없는 방법입니다.

클릭하려고하는 AppCompatCheckedTextView 개체는 ID가 select_dialog_listview 인 AlertController $ RecyleListView에 포함되어 있습니다.

onData(withText(displayName)) 
       .inAdapterView(withClassName(Matchers.equalTo("android.internal.app.AlertController$RecyleListView"))) 
       .perform(click()); 

onData(withText(displayName)) 
       .inAdapterView(withId(R.select_dialog_listview)) 
       .perform(click()); 

및 그러나 계층 구조에 일치하는보기가 없다는 오류 메시지가 : 그래서, 나는 노력했다.

그렇다면 알림 대화 상자에 맞춤보기를 추가하여 ID로 찾을 수 있는지 확인해 보았습니다.

나는 단지의 LinearLayout을 포함하는 레이아웃 파일이 있습니다

final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()) 
        .setTitle(args.getString(TITLE)) 
        .setView(LayoutInflater.from(getContext()).inflate(R.layout.alert_dialog_view, null))      
        .setSingleChoiceItems(ARRAY_OF_CHARSEQUENCE, args.getInt(SELECTED_INDEX), new DialogInterface.OnClickListener() { 
         @Override 
         public void onClick(DialogInterface dialog, int which) { 
          // handle click 
          dismiss(); 
         } 
        }); 

그리고 에스프레소에서 찾을 : : 내에 AlertDialog 빌더에 추가

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/dialog_view"> 
</LinearLayout> 

onData(withText(displayName)) 
        .inAdapterView(withId(R.dialog_view)) 
        .perform(click()); 

오류 :

android.support.test.espresso.PerformException: Error performing 'load adapter data' on view 'with id: org.OUR.APPLICATION:id/dialog_view'. 

클릭을 수행하기 위해 onData를 사용하는 것이 맞다면, DataInteraction을 AlertDialog보기로 지정하는 적절한 방법은 무엇입니까?

+0

대신 사용하려고 onData''의'onView (withText (R.string.test_account)) inRoot (isDialog()) 검사 (일치 (isDisplayed())); ' – piotrek1543

+0

inDialog를 inRoot과 함께 사용하는 것에 대해 알지 못했습니다. 알아두면 좋을 것 같습니다. 그러나이 상황에서 onView를 사용하는 기본 문제는 해결되지 않았습니다. onView를 사용하면 적어도 부분적으로 볼 수있는보기 만 일치합니다. 그래서 onData를 사용하려고 했으므로 가시성에 관계없이 올바른 항목을 검색 할 수있었습니다. – jhonvolkd

+0

''에스프레소 '를 돕기 위해'UiAtomator'를 사용하십시오 : http://qathread.blogspot.com/2015/05/espresso-uiautomator-perfect-tandem.html – piotrek1543

답변

1

"com.android.internal.app.AlertController $ RecycleListView"가 나와 작동하는 경우 "RecyleListView"에 오타가 있음에 유의하십시오.

또한 onData() 매개 변수는 "dataMatcher"여야하며 ArrayAdapter (이 경우 String)에서 T로 사용되는 유형의 instanceOf()가 작동합니다.

나를 위해 작동합니다..

onData(is(instanceOf(String.class))).inAdapterView(allOf(withClassName(equalTo("com.android.internal.app.AlertController$RecycleListView")), isDisplayed())).atPosition(index).perform(click());