ロボティウムを使い始めたばかりです。デモは問題なく実行できますが、 と を使用して最初のテスト スクリプトを作成したときにEditText
、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();
}
}
1 つの問題は、name と psw の両方が最初EditText
に入力されていることです。もう 1 つは、最初ではなく最初をクリックsolo.clickOnButton(0);
することです。のテキスト名も使用しようとしましたが、結果は同じでした。すべての操作が最初に配置されているようです。何が問題なのか知りたいです。何か提案はありますか?ありがとうEditText
Button
Button
EditText