(Robotium)操作栏上/ home键点击 [英] (Robotium) Action bar up/home button click

查看:391
本文介绍了(Robotium)操作栏上/ home键点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 Robotium 作为库JUnit测试我的Andr​​oid应用程序。我写了一些测试,效果很好。但是,当我尝试写一个测试本土动作条的<强>的/ home键点击,它失败了。

我的测试code是很简单的:

My test code is very simple:

Solo solo = new Solo(getInstrumentation(), getActivity());
...
solo.clickOnActionBarHomeButton(); // I expected it will click the Up/Home button of ActionBar

我希望上面的code会点击本土动作条的向上/ Home按键,但它失败了,什么也没有发生的行动吧。为什么?

I expected the above code will click the Up/Home button of native ActionBar, but it is failed, nothing was happening on action bar. Why??

PS 我使用的是Android 4.2.1的设备。

P.S. I am using an Android 4.2.1 device.

推荐答案

我用这个功能:

public void clickOnActionBarHomeButton(Solo solo) {
    View homeView = solo.getView(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? android.R.id.home : R.id.home);
    solo.clickOnView(homeView);
}

也许这不是一个完美的决定,但它的工作原理。

Maybe it's not a perfect decision, but it works.

这篇关于(Robotium)操作栏上/ home键点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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