【发布时间】:2015-10-03 22:18:07
【问题描述】:
我的 Espresso 测试中有此代码
onView(withId(R.id.src))
.perform(click());
onData(hasToString(startsWith("CCD")))
.perform(click());
onView(withId(R.id.src))
.check(matches(withText(containsString("CCD"))));
我正在尝试做的是单击Spinner 中的项目并检查它是否确实在Spinner 中被选中。
但我收到此错误:
android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with text: a string contains "CCD"' 与所选视图不匹配。 预期:带有文本:包含“CCD”的字符串 得到:“AppCompatSpinner{id=2131558533, res-name=src, visibility=VISIBLE, width=528, height=163, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable =true, is-enabled=true, is-focused=false, is-focusable=true, 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}"
【问题讨论】:
-
在测试 spresso 文档中,他们展示了一种解决方案,可以从微调器的索引位置选择一个项目,我认为这是正确的方法...... URL:github.com/vgrec/EspressoExamples/blob/master/app/src/…