gpt4 book ai didi

java - 如何在 Robotium for Android Studio 中测试 AlertDialog 项目单击

转载 作者:行者123 更新时间:2023-12-02 04:13:29 25 4
gpt4 key购买 nike

我有一个如下的AlertDialog,我不知道如何在Android Studio中用Robotium测试它。谁能给我一点提示吗?

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);

alertDialogBuilder.setTitle("Select");
final String[] items = {"Take a picture using carmera", "Choose a picture from Album"};
alertDialogBuilder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {

......

最佳答案

参见 this answer to a similar question:

This works for me:

solo.clickOnView(solo.getView(android.R.id.button1)); 

where the 'Positive' button is android.R.id.button1, the 'Negative' button is android.R.id.button2 and 'Neutral' is android.R.id.button3.

这意味着对于您的 AlertDialog,您需要使用 solo.clickOnView(solo.getView(dialogId)) 方法。

另请查看 this answer to a similar question:

lets say you have some code like this

solo.clickOnView(view1);

solo.clickOnView(view2);

and you know the dialog can appear between these two steps of your test, you can place in code that is something like:

if(solo.waitForView(dialogView, 1000, false)){
solo.clickOnView(dialogDismissButton);
solo.clickOnView(view2) //retry the step above
}

关于java - 如何在 Robotium for Android Studio 中测试 AlertDialog 项目单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33560746/

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