我刚开始使用robotium。演示程序可以毫无问题地运行,但是当我使用EditText
和Button
编写第一个测试脚本时,出现了问题。我的环境是android 2.1,脚本非常简单,只需输入用户名和密码,然后点击sumbit按钮登录。
的脚本如下:机器人的问题
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();
}
}
的一个问题是双方的名字和PSW填充在第一EditText
,另一种是solo.clickOnButton(0);
单击第一个EditText
,而不是第一Button
。我也尝试使用Button
的文本名称,但结果是一样的。看起来所有的操作都被放到了第一个EditText
。我想问题是什么。 ?任何建议感谢
这就是我写的解决这个问题。 http://chanakaudaya.wordpress.com/2012/03/31/robotium-button-click-not-working-solution – 2012-03-31 15:21:50