Display alert dialog while running an Android test case

0
0

I am using Robotium to automate testing of an application. Is there a way I can display an alert box while executing a particular test case.

Thanks.

  • You must to post comments
0
0

It is possible to do, nearly everything is possible but before I give you the answer do you have a good reason to do this? I cant easily thing of a good reason why a test should open an alert box but you may know best.

Robotium has the method.

solo.getCurrentActivity();

Using this you can get an Activity Context and with such a thing you can do pretty much anything that you could do in an android activity. The page http://developer.android.com/guide/topics/ui/dialogs.html tells us how to make a dialog, you will notice the first line calls a method to get the currentActivity, instead of that I replaced it with the robotium method above.

// 1. Instantiate an AlertDialog.Builder with its constructor
AlertDialog.Builder builder = new AlertDialog.Builder(solo.getCurrentActivity());
// 2. Chain together various setter methods to set the dialog characteristics
builder
.setMessage(R.string.dialog_message)
.setTitle(R.string.dialog_title);
// 3. Get the AlertDialog from create()
AlertDialog dialog = builder.create();

this will create a dialog, then just call the dialogs .show() method to show it on the screen.

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website