单击带有 Espresso 的主页图标 [英] Click home icon with Espresso

查看:39
本文介绍了单击带有 Espresso 的主页图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过以下方式单击某些 Espresso 测试中的主页图标:

I am trying to click the home icon in some Espresso tests via:

onView(withId(android.R.id.home)).perform(click());

这适用于 Android > 3.0 - 但对于旧版本失败,因为 appcompat 那时似乎没有将此 id 用于此元素.什么是做我想做的事的好方法?

This works fine for Android > 3.0 - but fails for older versions as appcompat does not seem to use this id for this element then. What is a good approach to do what I want to do?

推荐答案

为了不依赖于应用程序区域设置,您可以使用来自 Matt LoganR.string.abc_action_bar_up_description 替换Navigate up":

To not depend on the app locale, you can use the code from Matt Logan by replacing "Navigate up" with R.string.abc_action_bar_up_description:

onView(withContentDescription(R.string.abc_action_bar_up_description)).perform(click());

这对我帮助很大,因为我有超过 5 种语言的应用程序,我不得不这样做.

This helped me a lot because I have an app in more than 5 languages and I had to act like this.

这篇关于单击带有 Espresso 的主页图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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