gpt4 book ai didi

android - 单击 Robotium 中的操作栏菜单项

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:11:57 26 4
gpt4 key购买 nike

我正在尝试在 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 - 单击 Robotium 中的操作栏菜单项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15993314/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com