From b9a832f665606f130a37c7d924c6cfc5ef014e41 Mon Sep 17 00:00:00 2001 From: Rotem Mizrachi-Meidan Date: Sun, 10 Jun 2018 11:39:43 +0300 Subject: [PATCH] Match only visible views (#780) * Android: force matchers to ignore layouts with GONE visibility, closes #761 * filter out views with effective visibility different than VISIBLE --- .../main/java/com/wix/detox/espresso/DetoxMatcher.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/detox/android/detox/src/main/java/com/wix/detox/espresso/DetoxMatcher.java b/detox/android/detox/src/main/java/com/wix/detox/espresso/DetoxMatcher.java index 606c5527ec..e00e627b39 100644 --- a/detox/android/detox/src/main/java/com/wix/detox/espresso/DetoxMatcher.java +++ b/detox/android/detox/src/main/java/com/wix/detox/espresso/DetoxMatcher.java @@ -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; @@ -33,15 +35,15 @@ private DetoxMatcher() { public static Matcher 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 matcherForContentDescription(String contentDescription) { - return allOf(withContentDescription(contentDescription), isDisplayed()); + return allOf(withContentDescription(contentDescription), ViewMatchers.withEffectiveVisibility(Visibility.VISIBLE)); } public static Matcher matcherForTestId(String testId) { - return allOf(withTagValue(is((Object) testId)), isDisplayed()); + return allOf(withTagValue(is((Object) testId)), ViewMatchers.withEffectiveVisibility(Visibility.VISIBLE)); } public static Matcher matcherForAnd(Matcher m1, Matcher m2) { @@ -67,7 +69,7 @@ public static Matcher matcherWithDescendant(Matcher m, Matcher public static Matcher 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 }