How to know if it is a Fragment that is on the screen, in interface test?

Asked

Viewed 84 times

1

I would like to know, in automated interface tests, how to know if a Fragment is on the screen or not.

If it is a Fragment, example, ratingfragment, I will "perform" a "click". If it’s another one, I’ll take another action.

Thank you!

Code below:

@RunWith(AndroidJUnit4.class)
@LargeTest
public class CommunityUiTest {

    String emailSearch = "[email protected]";
    String emailLogin = "[email protected]";
    String pass = "2016";
    String pass2 = "2015";

    @Rule
    public ActivityTestRule mActivityRule = new ActivityTestRule<>(MainActivity.class);

    @After
    public void setUp(){
        Logout();
    }  
  @Test
    public void shouldOfferRide(){
        SystemClock.sleep(1500);
        Login();
        onView(withId(R.id.searchButton)).perform(typeText(emailSearch));
        onView(withId(R.id.searchButton)).perform(pressImeActionButton());
        onView(withId(R.id.community_user_ask_button)).perform(click());
        SystemClock.sleep(1500);
        onView(withId(R.id.button1)).perform(click());
        onView(withId(R.id.send_request)).perform(click());
        SystemClock.sleep(1500);
        ((MainActivity)mActivityRule.getActivity()).navItemClick(4);
        SystemClock.sleep(3500);
        LoginMyrides();
        onView(withId(R.id.my_rides_tab_bar)).perform(click());
        SystemClock.sleep(1000);

        //I have to know is ratingfragment before perform click below
        //Preciso saber se é o ratingfragment para executar ou não o perform(click) abaixo

        onView(withId(R.id.rating_bar)).perform(click());
        onView(withId(R.id.deny_btn)).perform(click());
    }

        public void Login(){
        onView(withId(R.id.edt_new_login_email)).perform(typeText(emailLogin));
        onView(withText(R.string.next_button)).perform(click());
        onView(withId(R.id.edt_new_password)).perform(typeText(senha));
        onView(withText(R.string.login_new_pass)).perform(click());
    }

    public void Logout(){
        new SessionManager(mActivityRule.getActivity()).logoutUser();
    }
}

1 answer

1


After much reading saw that the correct answer is that the espresso is developed for tests in isolated set, ie, should be mounted a test for when the Fragment is visible.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.