I'm testing my Android application with Robotium and I'm facing one intermittent problem. My application starts with a SigninActivity which allows the user to signin and after that he is directed to the second activity which has a list that is filled after a request to a web server.
The first question is: since all my activities can only be accessed after the user is logged in, I need to start every test for every activity from the login screen. So what I'm doing is for every activity test class, I'm inheriting it from
ActivityInstrumentationTestCase2<SigninActivity>
and in the setUp method I'm loggin in the user. Is this the correct approach?
Second question: I want to test the list data in the second activity that is filled after a request to the web server. As mentioned above, in my setup method I login the user, and I use
solo.waitForActivity(SecondActivity.class, BIG_TIMEOUT)
solo.waitForView(ListView.class)
to guarantee that the second activity and the list are present. The problem is, even with this verification I often get
junit.framework.AssertionFailedError: Can not click on line number 2 as there are only 0 lines available
Test an App with RobotiumStep 1 − Create a test Project in the Android Studio named as “RobotiumTest”. Choose all the default options until you reach to the main page. Step 2 − Copy the Robotium jar file into the Lib folder of the project. Step 3 − Add the dependency in build.
Robotium Test cases can be executed on Android Emulator as well as the Real device, we don't need to write any specific configuration code to run Robotium test cases on the Real device. Robotium Can be easily written in the Maven project also, and it can be run through continuous integration tools.
Robotium is an open-source test framework for writing automatic gray box testing cases for Android applications. With the support of Robotium, test case developers can write function, system and acceptance test scenarios, spanning multiple Android activities.
I was able to test multiple activities in my application by using the following approach:
sample code: public void testDisplayBlackBox() {
//Click on add ident button
solo.clickOnButton("Tap to get another number");
if (solo.waitForActivity(IdentityTemplateActivity.class)) {
// select ident type
solo.clickOnImageButton(0);
// add name/label and create ident
if (solo.waitForActivity(NumberDetailActivity.class)) {
solo.enterText(0, "Robotium");
solo.enterText(1, "test 1");
solo.clickOnImageButton(6);
}
}
First, writing logic code in setUp method isn't good idea. I would recommend you to use the fact, that test cases are run in alphabetical order - create one test method with login and then you are logged in your application in rest of them (if that case is run first), so you don't have to sign in before every test method.
About your second question, solo.waitForView(ListView.class) waits for a specified time (I don't remember what is default), but you don't assert it. You should rather use:
assertTrue(solo.waitForView(ListView.class));
However it seems to be a problem with ListView. Make sure you have only one list view on the screen, otherwise you have to use index of that:
solo.clickInList(int line, int index)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With