点击按钮不起作用

时间:2011-03-02 06:33:23

标签: java android robotium

我是robotium的新手,现在我正在自动化应用程序。

应用程序以启动画面开始,然后在加载1ndicator 15秒后进入菜单屏幕,在菜单屏幕中有一个名为 Application 的按钮。当我继续单击该按钮时,它会返回错误。

注意:当我使用搜索文本时,它会返回名称存在的按钮

protected void setUp() throws Exception {
    solo = new Solo(getInstrumentation(), getActivity());
}

public void testCanOpenSettings() throws Exception {

     String appName = solo.getCurrentActivity().getClass().getSimpleName();
     System.out.println(appName);
     String appName1 = solo.getCurrentActivity().getClass().getSimpleName();
     System.out.println(appName1); 
     solo.assertCurrentActivity("Home screen", appName1); 
     solo.waitForActivity(appName1, 10000);
     solo.clickonbutton("Application");
}

@Override
public void tearDown() throws Exception {
    try {
        solo.finalize();
    } catch (Throwable e) {
        e.printStackTrace();
    }
    getActivity().finish();
    super.tearDown();
}

堆栈追踪:

junit.framework.AssertionFailedError: No Button with text Application is found!
at com.jayway.android.robotium.solo.ViewFetcher.getView(ViewFetcher.java:350)
at com.jayway.android.robotium.solo.Solo.getButton(Solo.java:1233)
at com.impiger.fff.controller.Test.testCanOpenSettings(Test.java:45)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:205)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:195)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:175)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:444)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)

2 个答案:

答案 0 :(得分:0)

你确定按钮的名称是这样的应用程序android:text =“Application”?

答案 1 :(得分:0)

你确定它是一个按钮吗?请尝试clickOnText()。