Robotium : Some Useful functionalities and Methods To Make Automation Scripts More Robust

robotium

1. Targeting Tabs In The Application

Example Case Study:

Suppose We have three tabs in a Screen/Activity in the application. named Tab1 , Tab2 , And Tab3.

And we want to navigate to Tab2 or Tab3 as by default the application launches Tab1. In this case we can manage by writing scripts like
solo.clickOnText(“Tab2”); But in reality It may click on the text ‘Tab2’ which is a part of the context of body of Tab1. So to make sure that only the link navigating to ‘Tab2’ is clicked we have to write scripts in the folowing way:

ViewGroup tabs = (ViewGroup)solo.getView(android.R.id.tabs);
View tab=tabs.getChildAt(1); //change 1 to the desired index.
solo.clickOnView(tab);

2. Targeting Hardware Menu Button and Hardware Back Button

MENU:

             solo.sendKey(Solo.MENU);

BACK:

              solo.sendKey(KeyEvent.KEYCODE_BACK);

3.Get Number of tabs In the current screen:

ViewGroup tabs = (ViewGroup)solo.getView(android.R.id.tabs); //Change tabs in id.tabs to the target id.
int tabcount=tabs.getChildCount();

4. Set Timeout Of various waitFor methods to your desired duration:

Timeout class facilitates to set and get Timeout details of various functions which has a default timeout duration.

e.g Timeout.setLargeTimeout(assert….//or any funtion );
       Timeout.setSmallTimeout(assert….//or any funtion );

       Timeout.getLargeTimeout(assert….//or any funtion );

      Timeout.getSmallTimeout(assert….//or any funtion );

5. Check If a button is in Enabled or Disabled State:

solo.getButton(“Clear History”).isEnabled();

Returns true if enabled otherwise false.