Testing images with Robotium

2,927 views
Skip to first unread message

Bruce

unread,
May 31, 2011, 12:53:53 PM5/31/11
to Robotium Developers
I am new to Robotium and I have been trying to learn how to test
images, but I haven't had any luck so far. I searched this group for
answers and found only a very few things, but couldn't get them to
work for me.

Here's what I want to learn how to do:

1. Take the Robotium tutorial sample AndroidCalculator app and modify
it to add a logo sized jpg image below the current objects on the
screen (I completed this!)

2. Modify the AndroindCalulatorTest java file to detect and confirm
the new jpg - Does a jpg of ANY kind exist? (not done yet)

3. Modify the AndroindCalulatorTest java file to detect and confirm a
specific jpg - Does myspecialname.jpg exist? (not done yet)

From what I have seen, I need to use the getCurrentImageViews in some
way. I saw this snippet of code in another thread:

for(Image image : solo.getCurrentImageViews())
  String name = image.getName();

...then do the assert, etc.

However, the program complains that cannot convert the image type
ImageView to Image. There are other problems as well, and I'm sure I'm
making some syntactical errors that compound the issue. What I need
is some actual working code to look at so I can get familiar with it.
Can anyone help me with this? Are there examples out there?

Bruce

chlondziu

unread,
Jun 1, 2011, 7:19:55 AM6/1/11
to Robotium Developers
If you want to check if you got correct image you can use Yahor code
http://softteco.blogspot.com/2011/04/android-take-screenshot.html

Thanks to that you can take screenshot of screen, from that screenshot
you can cut interesting field and comapre that image with image from
assets.

Yahor Paulavets

unread,
Jun 8, 2011, 9:07:35 AM6/8/11
to robotium-...@googlegroups.com
Hello,

Image and ImaveView are different classes, change Image to ImageView,
and possibly your code will work!

Best regards,
Yahor

--
You received this message because you are subscribed to the Google Groups "Robotium Developers" group.
To post to this group, send email to robotium-...@googlegroups.com.
To unsubscribe from this group, send email to robotium-develo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/robotium-developers?hl=en.


Yahor Paulavets

unread,
Jun 8, 2011, 9:16:44 AM6/8/11
to robotium-...@googlegroups.com
Hello,

Also you can find ImageView by this way:

ImageView imageView = (ImageView) getActivity().findViewById(R.id.ImageView01);
ImageView has member - getDrawable(), you can assert it for Null, I think, to verify image was loaded.

Please continue share your work progress to make us understand what did you try.

Best regards,
Yahor

Bruce

unread,
Jun 21, 2011, 2:10:40 PM6/21/11
to Robotium Developers
On Jun 8, 9:16 am, Yahor Paulavets <ypaulav...@agilefusion.com> wrote:
> Hello,
>
> Also you can find ImageView by this way:
>
> ImageView imageView = (ImageView) getActivity().findViewById(R.id.ImageView01);
>
Hi Yohar,

Thanks for trying to help.

I get an error of "R.id.Imageview01 cannot be resolved" when I try
this.

I also tried this without success:
Drawable name = ImageView.getDrawable(); // ERROR
- cannot make a static reference to the non-static method
getDrawable() from the type ImageView
assertTrue(name.equals("tssgpicsmall.jpg"));

Do I have to make a new, non-static instance of this class for this to
work? What would that look like? I'm finding it hard to believe I
can't confirm the existence of a simple image file.

Bruce

Yahor Paulavets

unread,
Jun 21, 2011, 2:48:20 PM6/21/11
to robotium-...@googlegroups.com
Hello,


"I get an error of "R.id.Imageview01 cannot be resolved" when I try
this."
- You need to find your own proper resource id.

"   Drawable name = ImageView.getDrawable();  "
- ImageView is a type, how do you think it is possible to get drawable from a type? :)

Try to iterate through all views using solo.getViews();

Implement any kind of loop through this collection and check if View is instance of ImageView:

for(View testView: solo.getViews()) {
      if(testView instanceof ImageView) {
            // You have found it and can manipulate with its instance after casting:
            ImageView myImageToTest = (ImageView) testView;
            // TODO: add any logic you need.
            // Cancel cycle if correct view was found:
            break;
      }
}

Please let me know what kind of road stones do you have.

Best regards,
Yahor


Bruce

navneet kumar

unread,
Jan 28, 2012, 12:27:55 PM1/28/12
to robotium-...@googlegroups.com
hi yahor,
is there any way of getting the name of the image on the imageView?? in my case the imageView is dynamically getting updated with different images and i want to track that using Robotium...
any help would be greatly appreciated.
/Navneet.

Yahor Paulavets

unread,
Jan 30, 2012, 2:54:08 AM1/30/12
to robotium-...@googlegroups.com
hello navneet,

I think there are no such way. If you find it - please let me know.

I think you have to make your code "testable" and add some mechanism to get current image name.
For example, method which will download new image should set its name to same variable you could read from test.

Best regards,
Yahor

--
You received this message because you are subscribed to the Google Groups "Robotium Developers" group.
Reply all
Reply to author
Forward
0 new messages