Examples for Robotium
Asked Answered
M

5

9

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.

Mita answered 22/2, 2010 at 16:33 Comment(0)
L
15

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

Liner answered 22/2, 2010 at 19:15 Comment(0)
M
14

I can say, what you are not able to do with Robotium :)

  1. 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)

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

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

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

  5. 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!

Meed answered 5/4, 2011 at 11:50 Comment(2)
you can catch Robotium errors using: try { ... } catch( Error err) { .. } // By this way Robotium will not crash your test.Meed
You can get parent view and click on it, sometimes it much more bigger than image or text. Hope it will help someone.Missis
T
2

searchText method also searches ListViews. You can use it together with assertions to ensure that your ListViews contain the right content

Tamekia answered 25/2, 2010 at 20:31 Comment(0)
R
1

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

Reggie answered 16/7, 2010 at 8:18 Comment(0)
M
0
  • Views

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.

  • Other

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.

Missis answered 24/11, 2012 at 13:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.