Android Espresso检查选定的微调器文本 [英] Android Espresso check selected spinner text

查看:83
本文介绍了Android Espresso检查选定的微调器文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Espresso测试中有此代码

I have this code in my Espresso test

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中选择了该项目.

What I'm trying to do is to click the item in the Spinner and check if it's indeed selected in the Spinner.

但是我遇到了这个错误:

android.support.test.espresso.base.DefaultFailureHandler $ AssertionFailedWithCauseError:'带文字:包含"CCD"的字符串'与所选视图不匹配. 预期值:带文字:包含"CCD"的字符串 得到了:"AppCompatSpinner {id = 2131558533,res-name = src,可见性= VISIBLE,宽度= 528,高度= 163,has-focus = false,has-focusable = true,has-window-focus = true,可点击= true,已启用= 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}"

android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with text: a string containing "CCD"' doesn't match the selected view. Expected: with text: a string containing "CCD" Got: "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}"

推荐答案

withText()替换为withSpinnerText()

onView(withId(spinnerId)).perform(click());
onData(allOf(is(instanceOf(String.class)), is(selectionText))).perform(click());
onView(withId(spinnerId)).check(matches(withSpinnerText(containsString(selectionText))));

参考: https://code.google.com/p/android -test-kit/issues/detail?id = 85

这篇关于Android Espresso检查选定的微调器文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆