Robotium

Introducing Robotium Recorder

Introductory Words from Renas at linkedin
 
We are thrilled to announce the official release of our new product, Robotium Recorder. Robotium Recorder is significant in that anyone in a matter of minutes can create professional test cases, utilizing and taking full advantage of the Robotium framework. It is the result of 4 years of continuous feedback from the testing community and includes cool features like our unique ClickToAssert™ feature that we are certain you will love.

Robotium Tech, our new company, will drive both the development of the Robotium framework and Robotium Recorder going forward. We have a number of exciting ideas and products that we can’t wait to develop and share with you!

To try Robotium Recorder for free go to Robotium.com and follow the installation instructions.

http://www.robotium.com/

We look forward to and welcome any feedback!

Best,
Renas and the Robotium Tech team

Running Robotium Test Project using Ant

Pre-Reqs:

– JDK should be installed with JAVA_HOME evnrionment variable set
– Ant – can be found on Apache
–  Working Robotium Test Project, one can find already desinged sample TestProject here
–  Make sure that all required jars are in libs directory and added from build path setting of Eclipse
– Device/emulator should be connected to pc

Lets Start:

1. In Eclipse workspace having testProject, run the following command to set up Ant for the app project:

android update project -p [TestProject Path]

android tool is used to create/update projects, we need to update our exisiting project. it will generate any required files and folders that are either missing or need to be updated.

2. Next step is to link test project with AUT(Application Under Test). Note that the path given to -m must be the relative path to the project under test, seen from the test project, not the workspace:

android update test-project -m [../ProjectPath] -p [Testproject path]

3. To setup library projects

android update lib-project –target “Google Inc.:Google APIs:17” –path [path]

4. Refresh the projects in Eclipse

5. Test if you can build the app project with

ant clean debug

It should come up with “BUILD Successfull” status

6. Run the last command

ant clean debug install test

It will make all necessary installations and run testProject, see the command line for results. 



How to analyse Memory Availability of Android Testing Project

Both approaches worked for me, please using any of your choice,

Getting Runtime Memory using Runtime

static void checkMemory() {

double vTotalMem = Double.valueOf(Runtime.getRuntime().totalMemory());
double vMaxMem = Double.valueOf(Runtime.getRuntime().maxMemory());
double vAvailableMem = Double
.valueOf(Runtime.getRuntime().freeMemory());
print(“Runtime Memory info: TotalMem=”
+ Math.round(vTotalMem / 1048576) + “mb. MaxMemory”
+ Math.round(vMaxMem / 1048576) + ” mb. AvailableMemory=”
+ Math.round(vAvailableMem / 1048576) + ” mb.”);

}
Getting Memory using ActivityManager 

static void checkMemory() {
              ((ActivityManager)solo.getCurrentActivity()
                        .getSystemService(“activity”)).getMemoryInfo(mi);
              print(“Kernal Memory info: AvailableMemory=”+mi.
                         availMem/1048576+“mb IsMemLow=”+mi.lowMemory);
        if(mi.lowMemory) print(“memory is increasing”);
              else print(“Memory condition is fine”);
 
}

Get number of views on Android screen using Robotium

Please call the respective function to get its number on screen,

ImageViews:

       static int getNoOfImageViews() {
return solo.getCurrentViews(ImageView.class).size();
}
ImageButtons:
static int getNoOfImageButtons() {
return  solo.getCurrentViews(ImageButton.class).size();
}
RadioButtons:
static int getNoOfRadioButtons() {
return  solo.getCurrentViews(RadioButton.class).size();
}
RadioGroup:
static int getNoOfRadioGroup() {
return  solo.getCurrentViews(RadioGroup.class).size();
}
CheckBox:
static int getNoOfCheckbox() {
return  solo.getCurrentViews(CheckBox.class).size();
}
ListView:
static int getNoOfListViews() {
return  solo.getCurrentViews(ListView.class).size();
}
TextViews in a ListView:
static int getNoOfTextViewsInListView() {
return  solo.getCurrentViews(TextView.class,
solo.getCurrentViews(ListView.class).get(0)).size();
}
ImageViews in a ListView:
static int getNoOfImageViewsInListView() {
return  solo.getCurrentViews(ImageView.class,
solo.getCurrentViews(ListView.class).get(0)).size();
}
GridView:
static int getNoOfGridViews() {
return  solo.getCurrentViews(GridView.class).size();
}
ImageViews in a GridView:
static int getNoOfImageViewsInGridView() {
return  solo.getCurrentViews(GridView.class,
solo.getCurrentViews(GridView.class).get(0)).size();
}
ToggleButton:
static int getNoOfToggleButtons() {
return  solo.getCurrentViews(ToggleButton.class).size();
}
Button:
static int getNoOfButtons() {
return  solo.getCurrentViews(Button.class).size();
}
TextViews:
static int getNoOfTextViews() {
return  solo.getCurrentViews(TextView.class).size();

}

How to get all ImageButtons on screen using Robotium

static void getAllImageButtons() {
ArrayList allImageButton = solo
.getCurrentViews(ImageButton.class);
print(“Total ImageButtons:” + allImageButton.size());
for (ImageView vImageButton : allImageButton) {
if (vImageButton.getVisibility() == View.VISIBLE) {
print(“Image Button ID: “ + vImageButton.getId() + “Tag: “
+ vImageButton.getTag().toString() + ” Visibility:”
+ vImageButton.getVisibility() + “View String: “
+ vImageButton.toString());
}
}

}

How to get all ImageViews on screen using Robotium

static void getAllImageViews() {
ArrayList allImageViews = solo
.getCurrentViews(ImageView.class);
print(“Total ImageViews:” + allImageViews.size());
for (ImageView vImageView : allImageViews) {
if (vImageView.getVisibility() == View.VISIBLE) {
print(“Image ID: “
+ vImageView.getId()
+ “Tag: “
+ (vImageView.getTag() != null ? vImageView.getTag()
.toString() : “null”) + ” Visibility:”
+ vImageView.getVisibility() + ” View String :”
+ vImageView.toString());
}
}

}

How to get all ToggleButtons on screen using Robotium

static void printAllToggleButtons() {
ArrayList allToggleButtons = solo.getCurrentViews(ToggleButton.class);
print(“Total ToggleButtons:” + allToggleButtons.size());
for (ToggleButton vToggleButton : allToggleButtons) {
if (vToggleButton.getVisibility() == View.VISIBLE) {
print(“Button ID: “ + vToggleButton.getId() + ” Tag :”
+ vToggleButton.getTag().toString() + ” Value:”
+ vToggleButton.getText().toString() + ” Visibility:”
+ vToggleButton.getVisibility() + ” View String :”
+ vToggleButton.toString());
}
}

}

How to get all Buttons on screen using Robotium

static void printAllButtons() {
ArrayList
print(“Total Buttons:” + allButtons.size());
for (Button vButton : allButtons) {
if (vButton.getVisibility() == View.VISIBLE) {
print(“Button ID: “
+ vButton.getId()
+ ” Tag:”
+ (vButton.getTag() != null ? vButton.getTag()
.toString() : “null”) + ” Value:”
+ vButton.getText().toString() + ” Visibility:”
+ vButton.getVisibility() + ” View String:”
+ vButton.toString());
}
}

}

How to get all TextViews on screen using Robotium

static void printAllTextViews() {
vTextViewsList = null;
vTextViewsList = solo.getCurrentViews(TextView.class);
print(“Total TextViews:” + vTextViewsList.size());
vIndex = 0;
for (TextView vTextView : vTextViewsList) {
if (vTextView.getVisibility() == View.VISIBLE) {
print(“TextView ID: “
+ vTextView.getId()
+ “Index: “
+ vIndex
+ ” Tag: “
+ (vTextView.getTag() != null ? vTextView.getTag()
.toString() : “null”) + ” Value: “
+ vTextView.getText().toString() + ” Visibility: “
+ vTextView.getVisibility() + ” View String: “
+ vTextView.toString());
vIndex++;
}
}

}

How to Get all Views on screen using Robotium

static void printAllViews() {
ArrayList allViews = solo.getCurrentViews();
print(“Total Views:” + allViews.size());
for (View vView : allViews) {
if (vView.getVisibility() == View.VISIBLE) {
print(“View : “ + vView.toString() + “View ID: “
+ vView.getId() + ” Value:”
+ vView.getClass().getName().toString()
+ ” Visibility:” + vView.getVisibility());
}
}

}