I am writing automation test for View pager using Espresso 2.2 in which I need to test the swipe functionality.
I have written the below code:
@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 method swipeLeft() is not getting resolved. Please let me know where I am doing wrong? Your help will be highly appreciated.
You have to import swipeLeft() like:
import static android.support.test.espresso.action.ViewActions.swipeLeft;
Side note: The example code has swipLeft() rather than swipeLeft().
Even if you are able to swipe, you will see the action but the test will still fail. By default, Espresso validate 90% visibility and it fails otherwise. You need to customized the visibility yourself, basically lower it. Please refer to this solution: Espresso: How to test SwipeRefreshLayout? Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With