I’m writing a UI test case (using ActivityUnitTestCase) and would like to check if at a given time a View subclass is visible to the user. I’ve found the View#isShown() method, which claims to do exactly this – checking the visibility field of this element and all its parents – but somehow it always returns “false” for all the elements. I’ll be grateful for some help. If it makes it easier, I can paste some code.
Also, I found ViewAsserts#assertOnScreen(View origin, View view) but it doesn’t seem to do the right thing either – always returns true. Am I perhaps calling it wrong: assertOnScreen(viewImTesting.getRootView(), viewImTesting)?
Thanks,
Jan
I found a sensible workaround: just checking View#getVisibility() against View#VISIBLE, VIEW#INVISIBLE, or VIEW#GONE.
This probably doesn’t work when e.g. a parent view is not visible but this one has visibility set to VISIBLE, but for most cases it should suffice.