RobotiumTech / robotium

Android UI Testing
http://www.robotium.org
Apache License 2.0
2.86k stars 786 forks source link

Can't click on ImageButton by It's ID #660

Closed renas closed 9 years ago

renas commented 9 years ago

From glamour....@gmail.com on February 24, 2014 00:03:03

I'm using a recording tool for making automation tests and I don't have access to source code .. and here's the recorded steps by the tool .. assertTrue("Wait for image button (index: 2) failed.", solo.waitForImageButton(2, 20000)); solo.clickOnImageButton(2); } But, It fails on different devices as same button may have different indices

I found a function "waitForImageButtonById" but no functions for click on ImageButton by Id

Used version : Robotium 5.0.1

Original issue: http://code.google.com/p/robotium/issues/detail?id=581

renas commented 9 years ago

From renasr...@gmail.com on February 24, 2014 07:53:26

You can use solo.clickOnView(solo.getView("id of your view");

Status: Invalid
Owner: renasr...@gmail.com

renas commented 9 years ago

From glamour....@gmail.com on February 25, 2014 23:07:16

I tried it already and it failed .. here's the failure trace:

junit.framework.AssertionFailedError: View with id: 'com.softxpert.sds.R.id.addFolderAction' is not found! at com.robotium.solo.Solo.getView(Solo.java:1990) at com.robotium.solo.Solo.getView(Solo.java:1970) at com.example.android.apis.test.test.AddIconTest3.testRecorded(AddIconTest3.java:76) 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:169) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:545) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1575)

also I tried to find the view by id as the following: ImageButton imageButton = (ImageButton) solo.findViewById("com.softxpert.sds.R.id.addFolderAction"); solo.clickOnImageButton(imageButton); But, It caused a class cast exception "com.android.internal.view.menu.ActionMenuItemView cannot be cast to android.widget.ImageButton"