首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AmbiguousViewMatcherException Espresso

AmbiguousViewMatcherException Espresso
EN

Stack Overflow用户
提问于 2017-08-10 11:03:31
回答 1查看 828关注 0票数 1

我试图用IdlingResource编写一个Espresso测试来检查视频回放。

我的项目是托管的这里

这是一个考验:

代码语言:javascript
复制
@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);
    }
}

}

我发现这个错误导致测试失败:

代码语言:javascript
复制
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

所以,我们会很感激你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2017-09-01 09:41:36

我也有同样的问题。

我认为SimpleExoPlayer会自动生成一个PlaybackControlView。我不知道我们是否能避免这一代人,但我找到了解决办法。

看这句话:

代码语言:javascript
复制
onView(allOf(instanceOf(SimpleExoPlayerView.class), withId(R.id.playerView))).check(matches(isDisplayed()));

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45611942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档