AmbiguousViewMatcherException Espresso

时间:2017-08-10 11:03:31

标签: android android-espresso exoplayer

我正在尝试使用IdlingResource编写Espresso测试来检查视频播放。

我的项目已托管here

这是测试:

@RunWith(AndroidJUnit4.class)
public class RecipeFetchTest {

@Rule
public ActivityTestRule<RecipeActivity> mActivityTestRule = new ActivityTestRule<>(RecipeActivity.class);

private IdlingResource mIdlingResource;

@Before
public void registerIdlingResource() {
    mIdlingResource = mActivityTestRule.getActivity().getIdlingResource();
    Espresso.registerIdlingResources(mIdlingResource);
}


@Test
public void checkRecipeNameRecipeActivity() {
    onView(ViewMatchers.withId(R.id.rv_recipes)).perform(RecyclerViewActions.scrollToPosition(1));
    onView(withText("Brownies")).check(matches(isDisplayed()));
}

@Test
public void checkPlayerViewIsVisibleRecipeDetailActivity1() {
    onView(ViewMatchers.withId(R.id.rv_recipes)).perform(RecyclerViewActions.actionOnItemAtPosition(0,click()));
    onView(ViewMatchers.withId(R.id.rv_steps)).perform(RecyclerViewActions.actionOnItemAtPosition(0,click()));
 withContentDescription("playerVideo"))).check(matches(isDisplayed()));
    onView(withId(R.id.playerView)).check(matches(isDisplayed()));
}


@After
public void unregisterIdlingResource() {
    if (mIdlingResource != null) {
        Espresso.unregisterIdlingResources(mIdlingResource);
    }
}

}

我的测试失败并出现此错误:

android.support.test.espresso.AmbiguousViewMatcherException: '(with id: 
gautamhans.xyz.bakeaid:id/playerView and is displayed on the screen to the 
user)' matches multiple views in the hierarchy.
Problem views are marked with '****MATCHES****' below.

+--------->SimpleExoPlayerView{id=2131558584, res-name=playerView, 
visibility=VISIBLE, width=871, height=399, has-focus=false, has-
focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, 
is-focused=false, is-focusable=false, is-layout-requested=false, is-
selected=false, root-is-layout-requested=false, has-input-connection=false, 
x=0.0, y=0.0, child-count=3} ****MATCHES****

+---------->PlaybackControlView{id=2131558584, res-name=playerView, 
visibility=VISIBLE, width=871, height=399, has-focus=false, has-
focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, 
is-focused=false, is-focusable=false, is-layout-requested=false, is-
selected=false, root-is-layout-requested=false, has-input-connection=false, 
x=0.0, y=0.0, child-count=1} ****MATCHES****

根据测试,我有两个具有相同res-id的视图,即“playerView”。

一个是 SimpleExoPlayerView 另一个是 PlaybackControlView

我记得定义 SimpleExoPlayerView 但不是 PlaybackControlView

所以,请帮助。

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。

我认为SimpleExoPlayer会自动生成PlaybackControlView。 我不知道我们是否可以避免这一代,但我得到一个解决方法。

看看这一行:

onView(allOf(instanceOf(SimpleExoPlayerView.class), withId(R.id.playerView))).check(matches(isDisplayed()));

我只是添加一个Matcher以确保检查SimpleExoPlayer对象,然后检查它是否正确显示。