编辑在robotium中找不到的文本

时间:2013-10-22 05:48:32

标签: android testing android-edittext robotium

嗨,我目前正在研究robotium,我已经使用以下代码完成了示例测试项目:

public void testLoginToWhatsApp() throws InterruptedException { 
    solo.waitForActivity(LAUNCHER_ACTIVITY_CLASS);
    assertTrue(solo.searchText("WhatsApp"));
    solo.clickOnButton("Log In");
    solo.clearEditText(0);
    solo.enterText(0, "stest");
    solo.clearEditText(1);
    solo.enterText(1, "123456"); 
    final EditText Text = solo.getEditText(1);
    solo.getCurrentActivity().runOnUiThread(new Runnable() {
        public void run() {
            Text.onEditorAction(EditorInfo.IME_ACTION_DONE);
        }
    });
    solo.sleep(2000);
    solo.clickOnScreen(239, 761, 3); 
    assertTrue(solo.searchText("My Profile"));
    solo.sleep(3000);
}

我的错误日志如下:

junit.framework.AssertionFailedError: EditText is not found!
at com.jayway.android.robotium.solo.Waiter.waitForAndGetView(Waiter.java:501)
at com.jayway.android.robotium.solo.Solo.clearEditText(Solo.java:1783)
at com.WhatsApp.test.StartWhatsApp.testLoginToWhatsApp(StartWhatsApp.java:53)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)

我已经提供了代码,并且已经尝试了here给出的说明,但我仍然无法清除此错误日志,欢迎任何我犯错误的指导

1 个答案:

答案 0 :(得分:0)

即使我遇到类似的问题,我还有6个以上需要填写的文本框。 Robotium能够填充到3(索引开始:0)。 但它无法找到第四个指数或第五个指数。 它扔了:

junit.framework.AssertionFailedError: expected:<true> but was:<false>

at com.testJR.TestApk.testIfTheZipIsValid(TestApk.java:332) at java.lang.reflect.Method.invokeNative(Native Method) 在android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214) 在android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199) 在android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192) 在android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190) 在android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175) 在android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555) 在android.app.Instrumentation $ InstrumentationThread.run(Instrumentation.java:1584)

但我能用solo.scrollUp()解决问题; 旧不代码:

public void testIfTheZipIsValid() {
    UserActivities.fillTheFirstPage(solo);
    UserActivities.fillFullName(solo, "Prabhat_123");
    UserActivities.fillAdress(solo, "AAAA");
    UserActivities.fillState(solo, "UP");
    UserActivities.fillCity(solo, "Pune");
    UserActivities.fillZip(solo, String.valueOf("10"));
    UserActivities.fillPhone(solo, "8951592336");
    assertEquals(true, false);
}

新工作代码:

public void testIfTheZipIsValid() {
    UserActivities.fillTheFirstPage(solo);
    UserActivities.fillFullName(solo, "Prabhat_123");
    UserActivities.fillAdress(solo, "AAAA");
    UserActivities.fillState(solo, "UP");
    UserActivities.fillCity(solo, "Pune");
    solo.scrollUp();
    UserActivities.fillZip(solo, String.valueOf("10"));
    solo.scrollUp();
    UserActivities.fillPhone(solo, "8951592336");
    assertEquals(true, false);
}

PS。这不是一个永久性的解决方案,我很幸运能够找到解决方法。这应该在将来的版本中修复。