小编Kav*_*asu的帖子

如何选择在Robotium上单击哪个按钮以获得警报对话框?

我是Robotium的新手.我使用对话框构建器创建了一个警告对话框,并使用show命令调用它.我默认使用Robotium触发'ok'按钮,我无法对'cancel'按钮执行相同操作.由于对话框与id没有关联,我不知道如何获取按钮的id.这是我的对话框代码

alertDialogBuilder
.setMessage("Please enter only numbers without any spaces")
.setCancelable(true)
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
 public void onClick(DialogInterface dialog, int id) {
 dialog.cancel();
 }
 })
 .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
 public void onClick(DialogInterface dialog, int id) {
 dialog.cancel();
 }
 });
Run Code Online (Sandbox Code Playgroud)

我用来触发Test Class中'ok'按钮的代码是

 solo.getCurrentActivity().runOnUiThread(new Runnable() {
 public void run() {
 solo.getCurrentActivity().getCurrentFocus().requestFocus();
 }
 });
 this.sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
Run Code Online (Sandbox Code Playgroud)

如何为"取消"按钮执行相同的操作?提前致谢.

android robotium android-alertdialog

10
推荐指数
2
解决办法
8162
查看次数

标签 统计

android ×1

android-alertdialog ×1

robotium ×1