rahul7386 / robotium

Automatically exported from code.google.com/p/robotium
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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 reported on code.google.com by glamour....@gmail.com on 24 Feb 2014 at 8:03

GoogleCodeExporter commented 9 years ago
You can use solo.clickOnView(solo.getView("id of your view");

Original comment by renasr...@gmail.com on 24 Feb 2014 at 3:53

GoogleCodeExporter commented 9 years ago
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:7
6)
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(ActivityInstrumentationTes
tCase2.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:54
5)
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"

Original comment by glamour....@gmail.com on 26 Feb 2014 at 7:07