How to test screenshots of a view pager in Android using Espresso 2.2

I am writing an automation test for the View pager using Espresso 2.2, in which I need to check the functionality of the swipe.

I wrote the code below:

 @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)));}}

However, the swipeLeft () method does not get permission. Please let me know where I am doing wrong? Your help would be greatly appreciated.

+4
source share
2 answers

You need to import swipeLeft () as:

import static android.support.test.espresso.action.ViewActions.swipeLeft;

Side note: The sample code has swipLeft (), not swipeLeft ().

+9
source

, , . Espresso 90%, . , . , : : SwipeRefreshLayout? , !

0

Source: https://habr.com/ru/post/1609741/


All Articles