Skip to content

Commit

Permalink
Match only visible views (#780)
Browse files Browse the repository at this point in the history
* Android: force matchers to ignore layouts with GONE visibility, closes #761

* filter out views with effective visibility different than VISIBLE
  • Loading branch information
rotemmiz authored Jun 10, 2018
1 parent 607e082 commit b9a832f
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.wix.detox.espresso;

import android.support.test.espresso.matcher.ViewMatchers;
import android.view.View;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;

import static android.support.test.espresso.matcher.ViewMatchers.Visibility;
import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA;
Expand Down Expand Up @@ -33,15 +35,15 @@ private DetoxMatcher() {

public static Matcher<View> matcherForText(String text) {
// return anyOf(withText(text), withContentDescription(text));
return allOf(withText(text), isDisplayed());
return allOf(withText(text), ViewMatchers.withEffectiveVisibility(Visibility.VISIBLE));
}

public static Matcher<View> matcherForContentDescription(String contentDescription) {
return allOf(withContentDescription(contentDescription), isDisplayed());
return allOf(withContentDescription(contentDescription), ViewMatchers.withEffectiveVisibility(Visibility.VISIBLE));
}

public static Matcher<View> matcherForTestId(String testId) {
return allOf(withTagValue(is((Object) testId)), isDisplayed());
return allOf(withTagValue(is((Object) testId)), ViewMatchers.withEffectiveVisibility(Visibility.VISIBLE));
}

public static Matcher<View> matcherForAnd(Matcher<View> m1, Matcher<View> m2) {
Expand All @@ -67,7 +69,7 @@ public static Matcher<View> matcherWithDescendant(Matcher<View> m, Matcher<View>
public static Matcher<View> matcherForClass(final String className) {
try {
Class cls = Class.forName(className);
return allOf(isAssignableFrom(cls), isDisplayed());
return allOf(isAssignableFrom(cls), ViewMatchers.withEffectiveVisibility(Visibility.VISIBLE));
} catch (ClassNotFoundException e) {
// empty
}
Expand Down

0 comments on commit b9a832f

Please sign in to comment.