我有TabLayout
與ViewPager
,第3頁有一個SwitchCompat
我想執行一個click()
上,但它什麼都沒做。Espresso:單擊()上SwitchCompat不工作
@Test
public void checkSummaryPageUpdates_worksCorrect() {
onView(withId(R.id.view_pager)).perform(swipeLeft());
onView(withId(R.id.view_pager)).perform(swipeLeft());
onView(withId(R.id.gs_switch)).check(matches(isDisplayed()));
onView(withId(R.id.gs_switch)).perform(click());
onView(withId(R.id.gs_switch)).check(matches(isChecked())); // AssertionFailed
}
這是錯誤
android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with checkbox state: is ' doesn't match the selected view. Expected: with checkbox state: is true
的SwitchCompat似乎有以下特性:
Got: "SwitchCompat{id=2131689643, res-name=gs_switch, visibility=VISIBLE, width=996, height=100, 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-connection=false, x=0.0, y=0.0, text=GLÜCKSSPIRALE +5,00 €, input-type=0, ime-target=false, has-links=false, is-checked=false}"
錯誤說,開關沒有被選中,但這個問題似乎發生之前,導致開關只是保持未選中,perform(click())
似乎什麼都不做。任何人都可以幫忙
是的,謝謝你我只是用這個,它工作得很好。但是,爲什麼click()不起作用?它不應該只與perform.click()一起工作? – dan