AndroidJUnit4 Espresso崩溃,因为其他片段中使用了相同的ID

时间:2017-12-06 06:38:49

标签: android unit-testing junit android-espresso

由于应用程序中使用的重复ID,Espresso崩溃是否有任何解决方案使用重复的ID名称。

onView(withId(R.id.linearMenu)).perform(click());

崩溃

  

android.support.test.espresso.NoMatchingViewException:没有视图   层次结构找到匹配:具有id:   com.Example.activities:ID / linearMenu

1 个答案:

答案 0 :(得分:0)

从这里count child elements with same id

import pandas as pd
df1= pd.DataFrame(["0000D3447E","0000F2892E"])
df1.columns=['data']
df2=pd.DataFrame(["0000D3447E","0000D3447E","0000D3447E","0000D3447E","0000F2892E"])
df2.columns=['data']

df1['count']= df1['data'].map(df2['data'].value_counts())

df1

}

然后致电

public static Matcher<View> withChildViewCount(final int count, final Matcher<View> childMatcher) {
return new BoundedMatcher<View, ViewGroup>(ViewGroup.class) {
    @Override
    protected boolean matchesSafely(ViewGroup viewGroup) {
        int matchCount = 0;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            if (childMatcher.matches(viewGroup.getChildAt(i))) {
                matchCount++;
            }
        }

        return matchCount == count;
    }

    @Override
    public void describeTo(Description description) {
        description.appendText("ViewGroup with child-count=" + count + " and");
        childMatcher.describeTo(description);
    }
};