I have a App with several Fragments which are managed by one Activity. My Problem is that I want to test the Application and test the UI of each Fragment. I can test the first Fragment and get all Views of this, but when I click on a Button or something else (to replace the Fragment with another Fragment) I can’t get any View of the new Fragment, but my MainActivity says that the current Fragment is the new Fragment.
@UiThreadTest
public void testNewFragmentScrollView() {
assertTrue(mActivity.getFragmentType().equals(FragmentTypes.FRAGMENT_STARTSCREEN));
ivNewFragment.performClick(); // replace fragment
sleep();
assertTrue(mActivity.getFragmentType().equals(FragmentTypes.FRAGMENT_NEW));
//get something from new fragment, ID is copied from xml file and not false
ScrollView scrollView = (ScrollView) mActivity.findViewById(R.id.sv_fragment_new_scrollable);
assertTrue(scrollView != null); //#false???
mActivity.finish();
}
Do I have to update something in my Testclass or why i’m getting no Views from the new Fragment?
Ok I solved my problem by splitting the code. When I change the Fragment in setUp and wait some ms, I can get all views from the new Fragment in each testmethod