我正在使用Espresso 2.2为View pager编写自动化测试,我需要在其中测试滑动功能.
我写了下面的代码:
- @LargeTest
- public class FirstActivityTest {
- @Rule
- public ActivityTestRule<FirstActivity> firstActivityTestRule =
- new ActivityTestRule<>( FirstActivity.class);
- @Test
- public void testViewPagerSwipeFunctionality() throws InterruptedException{
- onView(withId(R.id.tv_commu)).check(matches(withText(R.string.first_screen_text)));
- onView(withId(R.id.tv_skip)).check(matches(withText(R.string.skip))) ;
- onView(withId(R.id.radio_button_first)).check(matches(isChecked()));
- onView(withId(R.id.view_pager)).perform(swipLeft());
- onView(withId(R.id.radio_button_second))
- .check(matches(isChecked()));
- onView(withId(R.id.tv_comp)).check(matches(withText(R.string.second_screen_text)));
- onView(withId(R.id.tv_skip)).check(matches(withText(R.string.skip))) ;
- onView(withId(R.id.view_pager)).perform(swipeLeft());
- onView(withId(R.id.radio_button_third))
- .check(matches(isChecked()));
- onView(withId(R.id.tv_skip)).check(matches(withText(R.string.skip))) ;
- onView(withId(R.id.tv_person)).check(matches(withText(R.string.third_screen_text)));}}
解决方法
你必须导入swipeLeft(),如:
- import static android.support.test.espresso.action.ViewActions.swipeLeft;
边注:示例代码具有swipLeft()而不是swipeLeft().