Reputation: 91
I found a tool for Instrumentation Testing called Robotium.It is easy and simple for black box testing of android applications. We can use it as follows:
solo.clickOnText("Other");
solo.clickOnButton("Edit");
assertTrue(solo.searchText("Edit Window"));
solo.enterText(1, "Some text for testing purposes")
solo.clickOnButton("Save");
assertTrue(solo.searchText("Changes have been made successfully"));
solo.clickOnButton("Ok");
assertTrue(solo.searchText("Some text for testing purposes"));
Can any body have more idea about it? Can any one please tell how can we use it for webviews and listviews etc.
Upvotes: 9
Views: 26274
Reputation: 7043
For listViews you can use following method solo.getCurrentListViews()
which return a number of list views on the current screen, and then iterate through or get other object types (android widgets) from them for example you need to click image views from all lists on the screen which not redirect you to another activity and only change state of other objects:
ArrayList<ListView> lw = solo.getCurrentListViews(); // get all list views
// logging to logcat
Log.i("stats", "number of list views on the current screen: " + aLw.size());
if (aLw.size() != 0)
for (ListView l: aLw) {
// Take all image views from list and click each
ArrayList <ImageView> aIw = solo.getCurrentImageViews(l);
Log.i("stats", "list view " + l + " contains " + iw.size() + " image views.");
if (aIw.size() != 0)
for (int i = 0; i < aIw.size(); ) {
// clicking
solo.clickOnView(aIw.get(i));
Log.i("click", "image view " + i " clicked.");
}
}
You can type text to editText view or get text from textViews. You can combine Robotium with Java and Android API. For example check visibility of images on the screen using getVisibility() method and comparing it with three major states View.GONE, View.VISIBLE, View.INVISIBLE. Or you can check connection using Java method HttpURLrequest before execution of your tests.
If you have source you can take objects from any layout knowing its ID! Also exist a lot of awesome stuff like solo.waitForActivity()
, solo.assertMemoryNotLow()
, solo.takeScreenShot()
.
More examples about Robotium usage you can find here by joining Robotium community.
Upvotes: 0
Reputation: 1919
Please see the QA wiki page for common question and answers on what Robotium supports: http://code.google.com/p/robotium/wiki/QuestionsAndAnswers
Also please go to the Getting Started page: http://code.google.com/p/robotium/wiki/Getting_Started
There you will find an example test project that you download and look at for ideas. You can also download the javadoc from: http://code.google.com/p/robotium/downloads/list to see what functionality there is at the moment.
For tutorials please visit: http://code.google.com/p/robotium/wiki/RobotiumTutorials
Sincerely, Renas
Upvotes: 15
Reputation: 2489
I can say, what you are not able to do with Robotium :)
Cross Activities testing, Robotium is able to work only with same certificate app, otherwise you will get inject events exception (eg you are not able to do clicks on screen keyboard)
Robotium has no mechanism to handle expected/unexpected alerts/popus/dialogues. For example iOs javascript tests has very simple boolean flag and callback for handling alerts
Robotium has big problem with auto scrolling methods (possibly currently it is fixed) for example if you are looking for the text, which is not shown, Robotium will stack in the end of the scroll view and make assertTrue(false) to stop scrolling
Robotium has assertTrue(false) logic for reporting problems/unexpected situations instead of returning some Enum value or boolean (success/fail) so for a good stress tests which are run 24/7 you need to add your own methods which will not stop test, just handle 'method fail to click x y' result value
You will need to implement some logic to click items in the scroll/list view. Because of Robotium clicks in the center of the view, you will always get exception or assertTrue(false) when try to click view with only 20% part shown
In general Robotium is very cool and helpful and I like it very much :) And I can't imagine life without this great library!
Upvotes: 14
Reputation: 11
In order to click List. If your activity is ListActivity type you can use clickInList with one parameter which is the index of line that should be clicked. In other cases use clickInList with two parameters – listview screen index and line number. For WebView if you load a page you should use waitForText() mathod to check content.
more examples: http://bitbar.com/blog/54/automated-ui-testing-android-applications-robotium
Upvotes: 1
Reputation: 1293
searchText method also searches ListViews. You can use it together with assertions to ensure that your ListViews contain the right content
Upvotes: 2