7

adaptör örneğine sahip değil. Android (4.0+) uygulama parçamda (Aktivitede) Sekme çubuğu ile kullanıyorum.Android Espresso: ViewPager,

Espresso testi oluşturmak istiyorum ancak ana Etkinliği oluşturup parçayı açarsam.

java.lang.IllegalStateException: ViewPager does not have adapter instance. 
at com.astuetz.PagerSlidingTabStrip.setViewPager(PagerSlidingTabStrip.java:177) 
at cz.villamemories.detoxme.staticcontent.StaticContentFragment.onCreateView(StaticContentFragment.java:197) 

Benim kod parçasındaki:

@Override 
public void onActivityCreated(Bundle savedInstanceState) { 
    super.onActivityCreated(savedInstanceState); 

     mViewPagerAdapter = new StaticContentPagerAdapter(
       this.getChildFragmentManager(), mItemsList, categories); 

     mPager.setAdapter(mViewPagerAdapter); 

     mTabs.setViewPager(mPager); //line 197 

Eğer bir sorun olabilir bazı ipucu var mı bu özel durum olsun? Yanlış olan ne?

+0

Bunu hiç çözdünüz mü? – athor

+0

Hayır ... biraz ipucu var mı? –

+0

Maalesef ... Bende aynı sorun var :( – athor

cevap

1

Ayrıca, sorun karşısında ViewPager ile sorunla karşı karşıya kalıyordum. Bu sorun, görüntüleyici cihazımın birden çok kök öğeye sahip olmasından dolayı oluşuyor.

@RunWith(JUnit4.class) 
public class FragmentTest { 

private static final String TAG = "FragmentTest"; 

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

@Test 
public void checkTabSwiping() { 
    onView(nthChildOf(withId(R.id.main_content), 5)).check(matches(withId(R.id.homecontentgrouppager))); 
} 

public static Matcher<View> firstChildOf(final Matcher<View> parentMatcher) { 
    return new TypeSafeMatcher<View>() { 
     @Override 
     public void describeTo(Description description) { 
      description.appendText("with first child view of type parentMatcher"); 
     } 

     @Override 
     public boolean matchesSafely(View view) { 

      if (!(view.getParent() instanceof ViewGroup)) { 
       return parentMatcher.matches(view.getParent()); 
      } 
      ViewGroup group = (ViewGroup) view.getParent(); 
      return parentMatcher.matches(view.getParent()) && group.getChildAt(0).equals(view); 

     } 
    }; 
} 
public static Matcher<View> nthChildOf(final Matcher<View> parentMatcher, 
             final int childPosition){ 
    return new TypeSafeMatcher<View>() { 
     @Override 
     public void describeTo(Description description) { 
      description.appendText("with " + childPosition + " child view of type parentMatcher"); 
     } 

     @Override 
     public boolean matchesSafely(View view) { 
      if (!(view.getParent() instanceof ViewGroup)) { 
       return parentMatcher.matches(view.getParent()); 
      } 

      ViewGroup group = (ViewGroup) view.getParent(); 
      return parentMatcher.matches(view.getParent()) && view.equals(group.getChildAt(childPosition)); 
     } 
    }; 
} 
} 

ve bu size Expresso Framework bir test vakası oluşturmak için yardımcı olabilir umuyoruz benim homefragment.xml dosyası

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:animateLayoutChanges="true" 
android:background="@color/black" 
android:orientation="vertical"> 

<android.support.v4.view.ViewPager 
    android:id="@+id/promotionalviewpager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"></android.support.v4.view.ViewPager> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="@dimen/size_5" 
    android:gravity="center_horizontal"> 

    <LinearLayout 
     android:id="@+id/viewPagerCountDots" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:gravity="center_horizontal" 
     android:orientation="horizontal" /> 

</RelativeLayout> 

olduğunu.