将浓缩咖啡设置为浓缩咖啡 [英] Set Spinner item with espresso

查看:110
本文介绍了将浓缩咖啡设置为浓缩咖啡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在浓缩咖啡测试中如何在微调器中设置项目.

I want to know how to set an item in a spinner in espresso testing.

onView(withId(R.id.spinner_gender)).perform(click());
onData(allOf(is(instanceOf(String.class)))).atPosition(0).perform(click());

上面的代码不起作用:/

This code above does not work :/

推荐答案

您的代码段看起来正确,因此测试类的另一部分可能有问题? 您是否可以使用异常或堆栈跟踪来更新您的问题?还要查看espresso 文档以获得更多信息.解释.

Your code snippet looks correct, so there may be an issue with another part of your test class? Are you getting an Exception or stack-trace you can update your question with? Also check the espresso documentation for a bit more explaination.

查看小代码示例,了解如何通过文本或位置选择微调器选项.

See small code example of how you can select a spinner option by text or it's position.

@RunWith(AndroidJUnit4.class)
public class BasicEspressoTest {
    @Rule
    public ActivityTestRule<MainActivity> testRule = new ActivityTestRule<>(MainActivity.class);

    @Test
    public void selectBySpinnerPosition() throws Exception {
        onView(withId(R.id.spinner)).perform(click());
        onData(allOf(is(instanceOf(String.class)))).atPosition(0).perform(click());
    }

    @Test
    public void selectBySpinnerText() throws Exception {
        onView(withId(R.id.spinner)).perform(click());
        onData(allOf(is(instanceOf(String.class)), is("spinner's text"))).perform(click());
    }
}

这篇关于将浓缩咖啡设置为浓缩咖啡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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