0

I have an AlertDialog as below, I don't know how to test it with Robotium in Android Studio. Can anyone give me a hint for that?

    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) {

... ...

Sam
  • 1
  • 2

1 Answers1

2

See 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.

It means that for your AlertDialog you would need to use the solo.clickOnView(solo.getView(dialogId)) method.

Check out also 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
}
Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94