1

I create an additional method:

public boolean exampleEdTxt1(){
 try{
  solo.getCurrentActivity().getResources().getDrawable(R.drawable.action_drw);
  return true;
 }
 catch(AssertionError e){
  return false;
 }
}

But, when test is runing, code

assertTrue(exampleEdTxt1());

always returns success and code

assertFalse(exampleEdTxt1());

always returns fail.

How to check from Robotium that my png is present on the screen?

2 Answers2

1

try using .isShown()

solo.getCurrentActivity().getResources().getDrawable(R.drawable.action_drw).isShown();

this assert i used to check if my image is displayed:

assertEquals(true, solo.getCurrentActivity().findViewById(R.id.getting_started_image_1).isShown());

hope it helps

Here i check for imageView

Boolean isVisible = (Boolean) solo.getCurrentActivity().findViewById(R.id.imageView1).isShown();
        assertTrue(isVisible);

Here is to check for drawable (image)

Boolean isVisible2 = (Boolean) solo.getCurrentActivity().getResources().getDrawable(R.drawable.image).isVisible();
        assertTrue(isVisible2);

imageView from the xml i used:

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="186dp"
    android:layout_height="90dp"
    android:src="@drawable/image" />
gionnut
  • 99
  • 3
  • Unfortunately, this method fails. "isShown()" IDE highlights in red with the message: "Cannot resolve method 'isShown()'". Although I am successfully using the code: assertTrue(solo.getView(R.id.action_search).isShown()); But if I try to check: assertEquals(false,getActivity().getResources().getDrawable(R.drawable.edit_btn).isVisible()); test falls on this line with an error: expected: but was: – Игорь Кожин Oct 02 '14 at 08:26
  • For Boolean isVisible2 = (Boolean) solo.getCurrentActivity().getResources().getDrawable(R.drawable.image).isVisible(); code assertTrue(isVisible2); - always returns success (Even if there is no drawable on the screen) and code assertFalse(isVisible2); - always returns fail. – Игорь Кожин Oct 13 '14 at 09:04
  • Drawable.isVisible() method return internal state of visibility (when you explicitly say imageView.setVisible(true), true is what you get) but does not check id drawable is shown on screen. – Kamil Seweryn Mar 14 '15 at 12:28
0

For

Boolean isVisible2 = (Boolean) solo.getCurrentActivity().getResources().getDrawable(R.drawable.image).isVisible();

code

assertTrue(isVisible2);

always returns success (Even if there is no drawable on the screen) and code

assertFalse(isVisible2);

always returns fail.