在运行Android测试用例时显示警报对话框 [英] Display alert dialog while running an Android test case
问题描述
我正在使用Robotium来自动化应用程序的测试.有没有一种方法可以在执行特定测试用例时显示警报框.
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.
谢谢.
推荐答案
可以做到,几乎所有可能,但是在我给您答案之前,您有充分的理由这样做吗?我不能轻易说出为什么测试应该打开警报框但您可能最了解的一个很好的理由.
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有此方法.
Robotium has the method.
solo.getCurrentActivity();
使用它可以获得活动上下文,通过这种事情,您可以执行在android活动中可以执行的几乎所有操作.页面 http://developer.android.com/guide/topics/ui/dialogs .html 告诉我们如何进行对话框,您会注意到第一行调用了一个获取currentActivity的方法,而不是我用上面的robotium方法替换了它.
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();
这将创建一个对话框,然后只需调用对话框.show()方法以将其显示在屏幕上即可.
this will create a dialog, then just call the dialogs .show() method to show it on the screen.
这篇关于在运行Android测试用例时显示警报对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!