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

社会主义新天地 提交于 2019-12-14 02:34:35

问题


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?


回答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" />



回答2:


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.



来源:https://stackoverflow.com/questions/26020839/how-to-check-from-robotium-that-my-png-is-present-on-the-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!