-
public final class ViewBuilderClass 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 Summary
Constructors Constructor Description ViewBuilder()
-
Method Summary
Modifier and Type Method Description final UnitwithIndex(Integer index, Function1<ViewBuilder, Unit> function)Matches only view at given index, if there are multiple views that matches final UnitonPosition(Integer position)Matches view at given position in ViewGroup final UnitisRoot()Matches only root views final UnitwithId(Integer id)Matches the view with given resource id final UnitwithTag(Object tag)Matches the view with given tag assigned final UnitisEnabled()Matches the view if it is in ENABLED state final UnitisDisabled()Matches the view if it is not in ENABLED state final UnitwithText(String text)Matches the view with given text final UnitwithText(@StringRes() Integer textId, Boolean cacheTextValue)Matches the view with given text final UnitwithText(Matcher<String> matcher)Matches the view with given text matcher final UnitwithoutText(String text)Matches if the view does not have a given text final UnitwithoutText(@StringRes() Integer resId, Boolean cacheTextValue)Matches if the view does not have a given text final UnitwithAnyText()Matches the view which contains any text final UnitcontainsText(String text)Matches the view which contain given text final UnitwithHint(String hint)Matches the view which contain given hint final UnitwithResourceName(String name)Matches the view with given resource name final UnitwithResourceName(Matcher<String> matcher)Matches the view by resource name with given matcher final UnitwithContentDescription(String description)Matches the view with given content description final UnitwithContentDescription(@StringRes() Integer resourceId)Matches the view with given content description final UnitwithParent(Function1<ViewBuilder, Unit> function)Matches the view which has parent with given matcher final UnitwithDrawable(@DrawableRes() Integer resId, Function1<Drawable, Bitmap> toBitmap)Matches the view with given drawable final UnitwithDrawable(Drawable drawable, Function1<Drawable, Bitmap> toBitmap)Matches the view with given drawable final UnitwithRating(Float rating)Matches the view which is RatingBar with given value final UnitwithBackgroundColor(@ColorRes() Integer resId)Matches the view with given background color final UnitwithBackgroundColor(String colorCode)Matches the view with given background color code final UnitisFirst()Matches the first view final UnitisVisible()Matches the view with VISIBLE visibility final UnitisInvisible()Matches the view with INVISIBLE visibility final UnitisGone()Matches the view with GONE visibility final UnitisDisplayed()Matches the view that is displayed final UnitisNotDisplayed()Matches the view that is not displayed final UnitisCompletelyDisplayed()Matches the view that is completely displayed final UnitisNotCompletelyDisplayed()Matches the view that is not completely displayed final UnitisClickable()Matches the view that is clickable final UnitisNotClickable()Matches the view that is not clickable final UnitisDescendantOfA(Function1<ViewBuilder, Unit> function)Matches the view which is descendant of given matcher final UnitwithDescendant(Function1<ViewBuilder, Unit> function)Matches the view which has descendant of given matcher final UnitwithSibling(Function1<ViewBuilder, Unit> function)Matches the view which has sibling of given matcher final UnitwithClassName(Matcher<String> matcher)Matches the view which class name matches given matcher final UnitisInstanceOf(Class<?> clazz)Matches the view by class instance final UnitisAssignableFrom(Class<out View> clazz)Matches views based on instance or subclass of the provided class. final UnitwithMatcher(Matcher<View> matcher)Matches the view with given custom matcher final ViewInteractionDelegategetViewInteractionDelegate()Returns view interaction delegate based on all given matchers final Matcher<View>getViewMatcher()Returns combined view matcher with AllOf. -
-
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 matchfunction- ViewBuilder that will result in matcher
-
onPosition
final Unit onPosition(Integer position)
Matches view at given position in ViewGroup
- Parameters:
position- position in ViewGroup
-
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
-
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 matchcacheTextValue- 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 matchedcacheTextValue- 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 matchtoBitmap- 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 matchtoBitmap- 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(@ColorRes() Integer resId)
Matches the view with given background color
- Parameters:
resId- Color to match
-
withBackgroundColor
final Unit withBackgroundColor(String colorCode)
Matches the view with given background color code
- Parameters:
colorCode- Color code to match
-
isInvisible
final Unit isInvisible()
Matches the view with INVISIBLE visibility
-
isDisplayed
final Unit isDisplayed()
Matches the view that is displayed
-
isNotDisplayed
final Unit isNotDisplayed()
Matches the view that is not displayed
-
isCompletelyDisplayed
final Unit isCompletelyDisplayed()
Matches the view that is completely displayed
-
isNotCompletelyDisplayed
final Unit isNotCompletelyDisplayed()
Matches the view that is not completely displayed
-
isClickable
final Unit isClickable()
Matches the view that is clickable
-
isNotClickable
final Unit isNotClickable()
Matches the view that is not clickable
-
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
-
getViewInteractionDelegate
final ViewInteractionDelegate getViewInteractionDelegate()
Returns view interaction delegate based on all given matchers
-
getViewMatcher
final Matcher<View> getViewMatcher()
Returns combined view matcher with AllOf.allOf()
-
-
-
-