android – 单击Robotium中的Action Bar菜单项

我正在尝试在Robotium中运行一些自动化测试.我的应用程序中有以下代码,用于设置选项菜单
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
    com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
        inflater.inflate(R.layout.logoutmenu,menu);
        return super.onCreateOptionsMenu(menu);
   }

我尝试使用代码单击Robotium中的菜单

solo.sendKey(Solo.MENU);
solo.clickOnView(solo.getView(R.id.share)); //share is the id of the menu item

但是我的测试因错误而失败:

View is null and therefore cannot be clicked.

我也试过使用下面的代码也失败了:

solo.clickOnView(solo.getView(R.id.logoutmenu));
solo.clickOnMenuItem("Share My Artists");

解决方法

如果您在Android 4.0上运行Robotium测试,请考虑使用solo.clickOnActionBarItem().

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...