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

如何使用Espresso 2.2在Android中测试查看寻呼机滑动手势,android,automation,android-viewpager,android-espresso,Android,Automation,Android Viewpager,Android Espresso,我正在使用Espresso 2.2编写查看寻呼机的自动化测试,其中需要测试刷卡功能 我已经编写了以下代码: @LargeTest public class FirstActivityTest { @Rule public ActivityTestRule<FirstActivity> firstActivityTestRule = new ActivityTestRule<>( FirstActivity.class); @Test publi

我正在使用Espresso 2.2编写查看寻呼机的自动化测试,其中需要测试刷卡功能

我已经编写了以下代码:

 @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)));}}
@LargeTest
公共类首次活动测试{
@统治
公共活动测试规则第一个活动测试规则=
新的ActivityTestRule(FirstActivity.class);
@试验
public void TestViewPagerSwipeFunctionary()引发InterruptedException{
onView(带id(R.id.tv_commu))。检查(匹配(带文本(R.string.first_screen_text)));
onView(使用id(R.id.tv_skip))。检查(匹配项(使用text(R.string.skip)));
onView(使用id(首先是R.id单选按钮)).check(匹配项(isChecked());
onView(带id(R.id.view_pager)).perform(swipLeft());
onView(带id(右id单选按钮秒))
.检查(匹配项(isChecked());
onView(带id(R.id.tv_comp))。检查(匹配(带文本(R.string.second_screen_text)));
onView(使用id(R.id.tv_skip))。检查(匹配项(使用text(R.string.skip)));
onView(带id(R.id.view_pager)).perform(swipeLeft());
onView(带id(右id单选按钮第三个))
.检查(匹配项(isChecked());
onView(使用id(R.id.tv_skip))。检查(匹配项(使用text(R.string.skip)));
onView(带id(R.id.tv_person)).check(匹配(带文本(R.string.third_screen_text)));}

但是,无法解析swipleft()方法。请让我知道我哪里做错了?非常感谢您的帮助。

您必须导入swipeLeft(),如:

旁注:
示例代码使用swipLeft()而不是swipLeft()。

即使您能够滑动,也会看到操作,但测试仍将失败。默认情况下,浓缩咖啡验证90%的可见性,否则将失败。您需要自己定制可见性,基本上降低它。请参考此解决方案:
希望这有帮助

嗨,这个问题解决了吗?请添加更多关于您的问题的信息facedYeah,它已被解决,需要做静态导入。
import static android.support.test.espresso.action.ViewActions.swipeLeft;