你好,我目前正在做 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 上给出的说明,但我仍然无法清除这个错误日志,欢迎任何我犯错误的指导
最佳答案
即使我遇到了类似的问题,我也有超过 6 个文本框需要填写。 Robotium 能够填充到 3(索引开始:0)。 但它无法找到第 4 个索引或第 5 个索引。 它正在 throw :
junit.framework.AssertionFailedError: expected:<true> but was:<false>
在 com.testJR.TestApk.testIfTheZipIsValid(TestApk.java:332) 在 java.lang.reflect.Method.invokeNative( native 方法) 在 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);
}
附言。这不是一个永久的解决方案,我很幸运能够找到解决办法。这应该在未来的版本中修复。
关于android - 编辑在 robotium 中找不到的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19509927/