0

因此,我有一個帶有可選項列表的AlertDialog。其中一個總是被選中。在儀器測試中,我想打開對話框並檢查是否選擇了具有特定文本的項目。如何使用Espresso測試框架在AlertDialog中選中該項目

onView(withText(R.string.country_FI)) .check(matches(isSelected()))

+0

究竟是行不通的:我一直在使用沒有用下面的代碼片段試過嗎?以及你得到的錯誤信息是什麼(請提供日誌輸出)? 您的測試是否正確打開對話框,並在檢查項目時失敗? – stamanuel

回答

0
I hope help full for you 

    ViewInteraction customTextView = onView(
       allOf(withId(R.id.tv_switch), withText("Switch care"), 
         withParent(allOf(withId(R.id.ll_care), 
           withParent(withId(android.R.id.content)))), 
         isDisplayed())); 
     customTextView.perform(click()); 

     ViewInteraction mDButton = onView(
       allOf(withId(R.id.buttonDefaultPositive), withText("Continue"), isDisplayed())); 
     mDButton.perform(click()); 
相關問題