In Android test, how to check that view is displayed?

I am writing a test UI example (using ActivityUnitTestCase) and would like to check if the view of the View subclass is currently visible to the user. I found the View # isShown () method , which claims to do just that - checking the field of view of this element and all its parents - but for some reason it always returns false for all elements. I will be grateful for the help. If this simplifies, I can insert the code.

In addition, I found ViewAsserts # assertOnScreen (View start, View view) , but it also does not work correctly - it always returns true. Perhaps I called it wrong: assertOnScreen (viewImTesting.getRootView (), viewImTesting)?

Thanks, Jan

+3
source share
3 answers

I found a reasonable workaround: simply by checking View # getVisibility () against View # VISIBLE , VIEW # INVISIBLE or VIEW # GONE .

This probably does not work when, for example, the parent view is not displayed, but it has the visibility set to VISIBLE, but in most cases this should be enough.

+2
source

Try using

final View origin = activityImTesting.getWindow().getDecorView();
android.test.ViewAsserts.assertOnScreen(origin, viewImTesting);
0
source

, ? @dtmilano Android-, , "".

visibility = gone , , , , . , - x y, 0.

ViewAsserts.java, assertOnScreen() y , , 0, .

: assertOnScreen, , , , , , , .

, ( )!

0

Source: https://habr.com/ru/post/1790470/


All Articles