ahsing / android-test-kit

Automatically exported from code.google.com/p/android-test-kit
0 stars 0 forks source link

isDisplayed() is not implemented with the way it should #37

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
This is what ViewMatchers.withEffectiveVisibility says in its comment:

Note: Contrary to what the name may imply, view visibility does not directly 
translate into whether the view is displayed on screen (use isDisplayed() for 
that). For example, the view and all of its ancestors can have 
visibility=VISIBLE, but the view may need to be scrolled to in order to be 
actually visible to the user. Unless you're specifically targeting the 
visibility
value with your test, use isDisplayed.

However, if you look at isDisplayed's code, you'll see that it still uses 
withEffectiveVisibility as its way to determine visibility, not simple 
View.VISIBLE:

      public boolean matchesSafely(View view) {
        return view.getGlobalVisibleRect(new Rect()) &&
            withEffectiveVisibility(Visibility.VISIBLE).matches(view);
      }

What is the expected output? What do you see instead?
This should be changed to a simple integer matching like:

is(Visibility.VISIBLE).matches(view.getVisibility())

What version of the product are you using? On what operating system?
4.1.2 emulator

Please provide any additional information below.
I met a rare problem today after running my tests without problem in almost 50 
tries. A view that should be visible says its visibility=GONE and threw an 
exception because of that. Since it's the 7th or 8th check of the same UI page, 
all views in that page should have already loaded, so this should not be the 
case where the view hasn't been loaded yet. And from the underlying data(I 
check that in the previous step) and the codes in my app, I can't find any 
possibility for that view being not visible at that moment. And in last 50 
tries, this view was visible with the same data and codes. So the only 
possibility for this to fail because of visibility=GONE is that Espresso thinks 
one of its parent has visibility=GONE. But that should not happen if I am 
calling isDisplayed().

Original issue reported on code.google.com by K76...@gmail.com on 26 Dec 2013 at 3:34

GoogleCodeExporter commented 9 years ago
isDisplayed uses withEffectiveVisibility *and* view.getGlobalVisibleRect.

@Override
      public boolean matchesSafely(View view) {
        return view.getGlobalVisibleRect(new Rect()) &&
            withEffectiveVisibility(Visibility.VISIBLE).matches(view);
      }

Original comment by vale...@google.com on 9 Jan 2014 at 7:38