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

前端之家收集整理的这篇文章主要介绍了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中的菜单:@H_301_5@

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

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

View is null and therefore cannot be clicked.

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

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

解决方法

如果您在Android 4.0上运行Robotium测试,请考虑使用solo.clickOnActionBarItem().
原文链接:https://www.f2er.com/android/317041.html

猜你在找的Android相关文章