我刚开始使用机器人。该演示可以毫无问题地运行,但是当我使用EditText
and编写第一个测试脚本时Button
,出现了问题。我的环境是android 2.1,脚本很简单,只需输入用户名和psw,然后点击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();
}
}
一个问题是name和psw都填在第一个EditText
,另一个是solo.clickOnButton(0);
点击第一个EditText
,不是第一个Button
。我也尝试使用 的文本名称Button
,但结果是一样的。似乎所有的操作都放在了第一位EditText
。我想问有什么问题。有什么建议吗?谢谢