如何使用Espresso 2.2在Android中测试查看寻呼机滑动手势

前端之家收集整理的这篇文章主要介绍了如何使用Espresso 2.2在Android中测试查看寻呼机滑动手势前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用Espresso 2.2为View pager编写自动化测试,我需要在其中测试滑动功能.

我写了下面的代码

  1. @LargeTest
  2. public class FirstActivityTest {
  3.  
  4. @Rule
  5. public ActivityTestRule<FirstActivity> firstActivityTestRule =
  6. new ActivityTestRule<>( FirstActivity.class);
  7.  
  8. @Test
  9. public void testViewPagerSwipeFunctionality() throws InterruptedException{
  10.  
  11.  
  12. onView(withId(R.id.tv_commu)).check(matches(withText(R.string.first_screen_text)));
  13.  
  14. onView(withId(R.id.tv_skip)).check(matches(withText(R.string.skip))) ;
  15.  
  16. onView(withId(R.id.radio_button_first)).check(matches(isChecked()));
  17. onView(withId(R.id.view_pager)).perform(swipLeft());
  18.  
  19. onView(withId(R.id.radio_button_second))
  20. .check(matches(isChecked()));
  21. onView(withId(R.id.tv_comp)).check(matches(withText(R.string.second_screen_text)));
  22.  
  23. onView(withId(R.id.tv_skip)).check(matches(withText(R.string.skip))) ;
  24.  
  25. onView(withId(R.id.view_pager)).perform(swipeLeft());
  26.  
  27. onView(withId(R.id.radio_button_third))
  28. .check(matches(isChecked()));
  29. onView(withId(R.id.tv_skip)).check(matches(withText(R.string.skip))) ;
  30. onView(withId(R.id.tv_person)).check(matches(withText(R.string.third_screen_text)));}}

但是swipeLeft()方法没有得到解决.请告诉我我在哪里做错了?我们将非常感谢您的帮助.

解决方法

你必须导入swipeLeft(),如:
  1. import static android.support.test.espresso.action.ViewActions.swipeLeft;

边注:示例代码具有swipLeft()而不是swipeLeft().

猜你在找的Android相关文章