Package 

Class ViewBuilder


  • 
    public final class ViewBuilder
    
                        

    Class for building view matchers and interactions

    This class helps to build matches for views and get their interactions. Please note that any function invoking will add specific matcher to the list and after that all of them will be combined with help of AllOf.allOf()

    • Constructor Detail

      • ViewBuilder

        ViewBuilder()
    • Method Detail

      • withIndex

         final Unit withIndex(Integer index, Function1<ViewBuilder, Unit> function)

        Matches only view at given index, if there are multiple views that matches

        Parameters:
        index - Index of the view to match
        function - ViewBuilder that will result in matcher
      • isRoot

         final Unit isRoot()

        Matches only root views

      • withId

         final Unit withId(Integer id)

        Matches the view with given resource id

        Parameters:
        id - Resource id to match
      • withTag

         final Unit withTag(Object tag)

        Matches the view with given tag assigned

        Parameters:
        tag - Tag object to match
      • isEnabled

         final Unit isEnabled()

        Matches the view if it is in ENABLED state

      • isDisabled

         final Unit isDisabled()

        Matches the view if it is not in ENABLED state

      • withText

         final Unit withText(String text)

        Matches the view with given text

        Parameters:
        text - Text to match
      • withText

         final Unit withText(@StringRes() Integer textId, Boolean cacheTextValue)

        Matches the view with given text

        Parameters:
        textId - String resource to match
        cacheTextValue - whether to cache the text extracted from resources for future checks
      • withText

         final Unit withText(Matcher<String> matcher)

        Matches the view with given text matcher

        Parameters:
        matcher - Text matcher to add
      • withoutText

         final Unit withoutText(String text)

        Matches if the view does not have a given text

        Parameters:
        text - Text to be matched
      • withoutText

         final Unit withoutText(@StringRes() Integer resId, Boolean cacheTextValue)

        Matches if the view does not have a given text

        Parameters:
        resId - String resource to be matched
        cacheTextValue - whether to cache the text extracted from resources for future checks
      • withAnyText

         final Unit withAnyText()

        Matches the view which contains any text

      • containsText

         final Unit containsText(String text)

        Matches the view which contain given text

        Parameters:
        text - Text to search
      • withHint

         final Unit withHint(String hint)

        Matches the view which contain given hint

        Parameters:
        hint - text of hint
      • withResourceName

         final Unit withResourceName(String name)

        Matches the view with given resource name

        Parameters:
        name - Resource name to match
      • withResourceName

         final Unit withResourceName(Matcher<String> matcher)

        Matches the view by resource name with given matcher

        Parameters:
        matcher - Matcher for resource name
      • withContentDescription

         final Unit withContentDescription(String description)

        Matches the view with given content description

        Parameters:
        description - Content description to match
      • withContentDescription

         final Unit withContentDescription(@StringRes() Integer resourceId)

        Matches the view with given content description

        Parameters:
        resourceId - Resource id of content description to match
      • withParent

         final Unit withParent(Function1<ViewBuilder, Unit> function)

        Matches the view which has parent with given matcher

        Parameters:
        function - ViewBuilder which will result in parent matcher
      • withDrawable

         final Unit withDrawable(@DrawableRes() Integer resId, Function1<Drawable, Bitmap> toBitmap)

        Matches the view with given drawable

        Parameters:
        resId - Drawable resource to match
        toBitmap - Lambda with custom Drawable -> Bitmap converter (default is null)
      • withDrawable

         final Unit withDrawable(Drawable drawable, Function1<Drawable, Bitmap> toBitmap)

        Matches the view with given drawable

        Parameters:
        drawable - Drawable to match
        toBitmap - Lambda with custom Drawable -> Bitmap converter (default is null)
      • withRating

         final Unit withRating(Float rating)

        Matches the view which is RatingBar with given value

        Parameters:
        rating - value of RatingBar
      • withBackgroundColor

         final Unit withBackgroundColor(String colorCode)

        Matches the view with given background color code

        Parameters:
        colorCode - Color code to match
      • isVisible

         final Unit isVisible()

        Matches the view with VISIBLE visibility

      • isInvisible

         final Unit isInvisible()

        Matches the view with INVISIBLE visibility

      • isGone

         final Unit isGone()

        Matches the view with GONE visibility

      • isDescendantOfA

         final Unit isDescendantOfA(Function1<ViewBuilder, Unit> function)

        Matches the view which is descendant of given matcher

        Parameters:
        function - ViewBuilder which will result in parent matcher
      • withDescendant

         final Unit withDescendant(Function1<ViewBuilder, Unit> function)

        Matches the view which has descendant of given matcher

        Parameters:
        function - ViewBuilder which will result in descendant matcher
      • withSibling

         final Unit withSibling(Function1<ViewBuilder, Unit> function)

        Matches the view which has sibling of given matcher

        Parameters:
        function - ViewBuilder which will result in sibling matcher
      • withClassName

         final Unit withClassName(Matcher<String> matcher)

        Matches the view which class name matches given matcher

        Parameters:
        matcher - Matcher of class name
      • isInstanceOf

         final Unit isInstanceOf(Class<?> clazz)

        Matches the view by class instance

        Parameters:
        clazz - Class to match
      • isAssignableFrom

         final Unit isAssignableFrom(Class<out View> clazz)

        Matches views based on instance or subclass of the provided class.

        Parameters:
        clazz - Class to match
      • withMatcher

         final Unit withMatcher(Matcher<View> matcher)

        Matches the view with given custom matcher

        Parameters:
        matcher - Matcher that needs to be added
      • getViewMatcher

         final Matcher<View> getViewMatcher()

        Returns combined view matcher with AllOf.allOf()