austgl / robotium

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

Missing clickOnImageButton(int id) #129

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
clickOnImageButton() only takes an index, not and R.id.

What version of the product are you using? On what operating system?
Robotium 2.4, any OS

Please provide any additional information below.
It would be useful to have a method to click on an ImageButton based on its ID 
rather than just its index which might change over time when you restructure 
the UI.

At the moment, we use something like this:
int i = 0;
for (ImageButton imageButton : solo.getCurrentImageButtons()) {
    if (imageButton.getId() == imageButtonId) {
        solo.clickOnImageButton(i);
        break;
    }
    ++i;
}

Original issue reported on code.google.com by aried3r on 22 Jul 2011 at 1:07

GoogleCodeExporter commented 9 years ago
You can do the following:

ImageButton imageButton = (Image) solo.getView(R.id.of.imagebutton);

solo.clickOnView(imageButton);

Original comment by renasr...@gmail.com on 24 Jul 2011 at 3:12

GoogleCodeExporter commented 9 years ago
Sometimes the emulator is too slow, so when I call 
solo.getView(R.id.of.imagebutton) it will return null. I had to add a 
solo.sleep(1000) before it, which isn't always enough. It also seems silly to 
me, of putting solo.sleep() everywhere just to make the code more reliable.
With the - not so clean - method of using the loop I never encountered this 
issue, because solo.getCurrentImageButtons() always returned all of the 
ImageButtons.

Is there no cleaner _and_ more reliable method of using the loop? Because I 
will probably revert to using the loop if there is not.

Original comment by aried3r on 26 Jul 2011 at 3:11

GoogleCodeExporter commented 9 years ago
I agree, using sleeps is not a good solution. Try this:

solo.waitForView(ImageButton.class);
ImageButton imageButton = (Image) solo.getView(R.id.of.imagebutton);

solo.clickOnView(imageButton);

If you want to be even more specific you can use:

solo.waitForView(final Class<T> viewClass, final int minimumNumberOfMatches, 
final int timeout)

Original comment by renasr...@gmail.com on 26 Jul 2011 at 3:39

GoogleCodeExporter commented 9 years ago
Thank you. This worked out nicely.

Original comment by aried3r on 29 Jul 2011 at 9:03

GoogleCodeExporter commented 9 years ago
I wrote that within my code to click on an image button ...

solo.waitForView(ImageButton.class);
ImageButton imageButton = (ImageButton) 
solo.getView("com.softxpert.sds.R.id.addFolderAction");
solo.clickOnView(imageButton);

BUT, It doesn't work and here's the error .. any help ?

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:5
7)
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)

Original comment by glamour....@gmail.com on 23 Feb 2014 at 8:24

GoogleCodeExporter commented 9 years ago
Try to use this as the I'd string instead: addFolderA

Original comment by renasr...@gmail.com on 23 Feb 2014 at 2:28