I just start to use robotium. The demo can be run without any problem, but when I wrote first test script by using EditText
and Button
, problems occured. My environment is android 2.1 and the script is quite simple, just input username and psw, then click sumbit button to login.
The script is as follows:
package com.tpc.test;
import com.tpc.login.Login;
import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.Smoke;
public class LoginTest extends ActivityInstrumentationTestCase2<Login>{
private Solo solo;
public LoginTest() {
super("com.tpc", Login.class);
}
public void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
@Smoke
public void testApp() throws Exception {
String appName = solo.getCurrentActivity().getClass().getSimpleName();
System.out.println(appName);
solo.getButton(0).getClass().getSimpleName();
solo.assertCurrentActivity("Expected login activity", appName);
System.out.println(solo.getButton(0).getText());//can get the text of button
solo.enterText(0, "name"); //input name to the 1st EditText is OK
solo.enterText(1, "psw"); // Actually inout psw after name to the 1st EditText
solo.clickOnButton(0); //Expect click the 1st button.Actually click the 1st EditText
//assert of sample, not been modified
boolean expected = true;
boolean actual = solo.searchText("Note 1") && solo.searchText("Note 2");
assertEquals("Note 1 and/or Note 2 are not found", false, actual);
}
@Override
public void tearDown() throws Exception {
try {
solo.finalize();
} catch (Throwable e) {
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}
}
One problem is both name and psw is filled in the first EditText
,the other is solo.clickOnButton(0);
click the first EditText
, NOT the first Button
. I also tried to use the text name of the Button
, but the result was the same. It seems all the operations been put to the first EditText
. I wanna what's the problem. Any suggestion?thanks