Android application is combination of multiple controls respective to functionality like to show text on screen developers use TextView, to show input field they use EditText, to show button they use Button and many other controls as
1. TextView To show text
2. EditText To show input field
3. Button To show button
4. ImageView To show multimedia image
5. ImageButton To show Image button
Each control has its own class comprise of multiple functions to work intelligently. Robotium is automated testing tool for Android applications. It identifies the control used on screen and allow user to interact with control through different ways. Robotium api provides the solo class which contains long list of functions to simulate real user actions on controls like Click, LongClick, Drag, Scroll up, Scroll Down, Click on ToggleButton etc..
To automate Android application test engineer can use both
1. Control’s native class
2. Robotium functions list for that specific controls
Like to work with TextView test engineer can use the TextView class and Robotium functions for TextView like getText, getCurrentTextViews(parent) and many others. Combination of both can make almost everything possible to automate android applications.
For new test engineers it’s quite tough to work intelligently with controls used on screen unless they know controls in brief. In this discussion/tutorial we will take each control one by one, explain its use and try to find out the combination of tricks we can use to work intelligently with these controls.
1. TextView
TextView is used to show text on screen, there can be any number of TextView controls on a screen depends upon the need of UI like a list showing results in rows may contains single TextView on each row or multiple on each row. We will go through each possible scenario and try to work with it
If there are 2 TextView controls on a screen to get their values we can use following Robotium function
String vTextViewValue = solo.getText(index).toString();
Index shows the number of TextView control used on screen, for first TextView it will be 0,
String vTextViewValue1 = solo.getText(0).toString();
and for second text view it will be 1 like.
String vTextViewValue2 = solo.getText(1).toString();
If there is a TextView control with some text we can get it using
TextView vTextView = solo.getText(“text”);
getText(“text”) will search and return the TextView control on screen matching the “text”. vTextView can use all functions of TextView class like to getId, getScaleX, getScaleY, getCurrentTextColor etc.
If there are many TextView controls in a list on a screen we will get the list on screen and then all TextView controls in that list,
ListView lvResults = solo.getCurrentListViews().get(0);
ArrayList
First line is getting the first list used on screen, and second line it getting all TextView controls in ArrayList. All TextView controls in specific list are stored in ArrayList, one can easily work with them.
2. EditText
EditText is used to enter text on screen, there can be any number of EditText controls on a screen depends upon the need of UI. Using Robotium we can write in EditTex and also get already written value. We will go through each possible scenario and try to work with it
If we need to enter some value in EditText on screen, we can write by using
solo.enterText(index, “value”);
the index parameter is used to call the number of Edit/Text on screen, like if there are two EditText controls on a login screen 0 is for first one and 1 is for second one on login screen,
solo.enterText(0, “username”);
solo.enterText(1, “password”);
If we want to get already written value in some EditText we can
String vEditTextValue = solo.getText(0).getText().toString();
the 0 represent the first EditText on screen, and value is saved in vEditTextValue variable. We can get the value of any EditText on screen by entering its index.
If there are many EditText controls on a screen we will get all EditText controls like,
ArrayList
Above line will get all EditText controls on screen and save them in ArrayList, one can easily work with them.
We can get EditText like
EditText vEditText = solo.getEditText(index);
index is number of control on screen, it will return the EditText object and all functions of EditText Class of Android SDK are available to use.
We can also get EditText like
EditText vEditText = solo.getEditText(string);
string is value of control on screen, it will return the EditText object and all functions of EditText Class of Android SDK are available to use.
3. Button
Button is used on screen to click on some action, through Robotium user can click on button by,
solo.clickOnButton(index);
index shows the number of buttons on screen, if user needs to click on first button there will be 0 in place of index & 1 in case of second button on screen.
User can also click on button by identifying text written on screen like
solo.clickOnButton(string);
String shows the text visible on button, like if user needs to click on ‘Submit’ button there will be
will be
solo.clickOnButton(“Submit”);
User can also get all buttons on screen if there are many like
ArrayList
Above line will get all Button controls on screen and save them in ArrayList, one can easily work with them.
We can get button like
Button vButton = solo.getButton(0);
0 represents the first button on screen; there will be 1 if user needs to interact with second button on screen. It will return the Button object and all functions of Button Class of Android SDK are available to use.
We can also get button like
Button vButton = solo.getButton(string);
string represents the text on button, there will be “Submit” if user needs to interact with Submit button on screen. it will return the Button object and all functions of Button Class of Android SDK are available to use.
4. ImageView
Images are used to show graphics on screen, Through Robotium user can interact with images easily
User can click on image like that, index shows the number of image on screen, user will enter 0 if there needs to click on first image on screen, and 1 if it needs to click on second image on screen
solo.clickOnImage(index)
If there are many ImageView controls on screen, user can get all of the them through Robotium like,
ArrayList
Above line will get all ImageView controls on screen and save them in ArrayList, one can easily work with them.
We can get button like
ImageView vImageView = solo.getImage(index);
0 represents the first image on screen; there will be 1 if user needs to interact with second button on screen. it will return the ImageView object and all functions of ImageView Class of Android SDK are available to use.
5. ImageButton
There can be button images used in Andorid Applications, Through Robotium user can easily interact with them.
User can click on imageButton like that,
solo.clickOnImageButton(index);
index shows the number of imageButton on screen, user will enter 0 if there needs to click on first imageButton on screen, and 1 if it needs to click on second imageButton on screen
If there are many ImageButton controls on screen, user can get all of the them through Robotium like,
ArrayList
Above line will get all ImageButton controls on screen and save them in ArrayList, one can easily work with them.
We can get button like
ImageButton vImageButton = solo.getImageButton(index);
0 represents the first ImageButton on screen; there will be 1 if user needs to interact with second button on screen. it will return the ImageButton object and all functions of ImageButton Class of Android SDK are available to use.
Note: Soon will upload the next parts with more controls