2016-08-30 156 views
2

我目前正在嘗試通過它的類和它的文本來獲得Espresso來匹配UIElement,因爲它當前沒有資源ID(我知道,我知道...)。我不確定這是什麼正確的語法,因爲Espresso文檔是模糊的(我對這一點和編程一般都很陌生,所以我確信我錯過了一些東西)。這是我到目前爲止有:咖啡 - 匹配一個類的實例

onView(allOf(instanceOf(android.widget.CheckBox)), withText("S"))). 
       perform(scrollTo()). 
       check(matches(isChecked())); 

我試過打字只是「文本框」,但在這兩種情況下,我得到錯誤的「預期的表達」。到目前爲止,這是識別這個元素的唯一方法,所以任何指針都會有幫助。謝謝!

+0

嘗試:onView(allOf(是(}這種( android.widget.CheckBox)),withText(「S」))) – jeprubio

+0

我做到了。仍然得到了「預期表達」的消息 – Los

回答

2

這是我的例子:

onView(allOf(instanceOf(Toolbar.class), withChild(withText(R.string.action_settings)))) 
.check(matches(isDisplayed())); 

,所以我想在您的測試將是

onView(allOf(instanceOf(android.widget.CheckBox.class)), withText("S"))). 
       perform(scrollTo()). 
       check(matches(isChecked())); 

希望這將有助於