我想檢查使用/取消選中複選框在我的咖啡測試:如何專注於espresso中的頁面元素?
termsAndConditionsCheckbox.check(matches(isChecked()));
termsAndConditionsCheckbox.perform(scrollTo()).perform(click());
termsAndConditionsCheckbox.check(matches(isNotChecked()));
但得到錯誤:
Error performing 'scroll to' on view
Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints:
(view has effective visibility=VISIBLE and is descendant of a: (is assignable from class: class android.widget.ScrollView or is assignable from class: class android.widget.HorizontalScrollView))
Target view: "AppCompatCheckBox{id=2131689839, res-name=tnc_checkbox, visibility=VISIBLE, width=96, height=96, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-conn
通過去除scrollTo,只用點擊(),但仍無法嘗試執行點擊。
ScrollView是否是CheckBox? –
不,但我嘗試了幾個選項,如scrollTo() –
'scrollTo()'期望目標元素是'ScrollView'的子元素,所以如果你的視圖太大而不適合屏幕,你需要將其封裝在佈局XML中的'ScrollView'中。很快就會寫出完整的答案。 –