Reputation: 423
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.
Upvotes: 7
Views: 5790
Reputation: 89
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!
Upvotes: 2
Reputation: 326
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().
Upvotes: 13