androidx.test.espresso.matcher.ViewMatchers.Visibility Java Examples
The following examples show how to use
androidx.test.espresso.matcher.ViewMatchers.Visibility.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TextInputLayoutIconsTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test public void testPrefixDisappearsIfEditTextIsEmpty() { // Click on text field onView(withId(R.id.textinput_prefix)).perform(click()); // Assert prefix is visible onView(allOf( withId(R.id.textinput_prefix_text), isDescendantOfA(withId(R.id.textinput_prefix)))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))); // Click on another text field onView(withId(R.id.textinput_no_icon)).perform(click()); // Assert prefix is not visible onView(allOf( withId(R.id.textinput_prefix_text), isDescendantOfA(withId(R.id.textinput_prefix)))) .check(matches(withEffectiveVisibility(Visibility.GONE))); }
Example #2
Source File: TextInputLayoutIconsTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test public void testSuffixDisappearsIfEditTextIsEmpty() { // Click on text field onView(withId(R.id.textinput_suffix)).perform(click()); // Assert prefix is visible onView(allOf( withId(R.id.textinput_suffix_text), isDescendantOfA(withId(R.id.textinput_suffix)))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))); // Click on another text field onView(withId(R.id.textinput_no_icon)).perform(click()); // Assert suffix is not visible onView(allOf( withId(R.id.textinput_suffix_text), isDescendantOfA(withId(R.id.textinput_suffix)))) .check(matches(withEffectiveVisibility(Visibility.GONE))); }
Example #3
Source File: TextInputLayoutIconsTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test public void testSuffixStaysVisibleWithInputText() { // Type some text on the EditText onView(withId(R.id.textinput_edittext_suffix)).perform(typeText(INPUT_TEXT)); // Click on another text field onView(withId(R.id.textinput_no_icon)).perform(click()); // Assert suffix is still visible onView(allOf( withId(R.id.textinput_suffix_text), isDescendantOfA(withId(R.id.textinput_suffix)))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))); }
Example #4
Source File: ViewMatchersTest.java From android-test with Apache License 2.0 | 5 votes |
@Test public void isGoneTest() { View gone = new View(context); gone.setVisibility(View.GONE); View visible = new View(context); visible.setVisibility(View.VISIBLE); assertFalse(withEffectiveVisibility(Visibility.GONE).matches(visible)); assertTrue(withEffectiveVisibility(Visibility.GONE).matches(gone)); // Make the gone view gone by giving it a gone parent. ViewGroup parent = new RelativeLayout(context); parent.addView(visible); parent.setVisibility(View.GONE); assertTrue(withEffectiveVisibility(Visibility.GONE).matches(visible)); }
Example #5
Source File: ViewMatchersTest.java From android-test with Apache License 2.0 | 5 votes |
@Test public void isInvisibleTest() { View visible = new View(context); visible.setVisibility(View.VISIBLE); View invisible = new View(context); invisible.setVisibility(View.INVISIBLE); assertFalse(withEffectiveVisibility(Visibility.INVISIBLE).matches(visible)); assertTrue(withEffectiveVisibility(Visibility.INVISIBLE).matches(invisible)); // Make the visible view invisible by giving it an invisible parent. ViewGroup parent = new RelativeLayout(context); parent.addView(visible); parent.setVisibility(View.INVISIBLE); assertTrue(withEffectiveVisibility(Visibility.INVISIBLE).matches(visible)); }
Example #6
Source File: ViewMatchersTest.java From android-test with Apache License 2.0 | 5 votes |
@Test public void isVisibleTest() { View visible = new View(context); visible.setVisibility(View.VISIBLE); View invisible = new View(context); invisible.setVisibility(View.INVISIBLE); assertTrue(withEffectiveVisibility(Visibility.VISIBLE).matches(visible)); assertFalse(withEffectiveVisibility(Visibility.VISIBLE).matches(invisible)); // Make the visible view invisible by giving it an invisible parent. ViewGroup parent = new RelativeLayout(context); parent.addView(visible); parent.setVisibility(View.INVISIBLE); assertFalse(withEffectiveVisibility(Visibility.VISIBLE).matches(visible)); }
Example #7
Source File: RemoteViewMatchersTest.java From android-test with Apache License 2.0 | 5 votes |
@Test public void withEffectiveVisibility_transformationFromProto() { Matcher<View> withEffectiveVisibilityMatcher = withEffectiveVisibility(Visibility.VISIBLE); WithEffectiveVisibilityMatcherProto withEffectiveVisibilityProto = (WithEffectiveVisibilityMatcherProto) new GenericRemoteMessage(withEffectiveVisibilityMatcher).toProto(); Matcher<View> withEffectiveVisibilityFromProto = (Matcher<View>) GenericRemoteMessage.FROM.fromProto(withEffectiveVisibilityProto); assertThat(withEffectiveVisibilityFromProto, notNullValue()); assertThat(withEffectiveVisibilityFromProto, instanceOf(WithEffectiveVisibilityMatcher.class)); }
Example #8
Source File: RemoteViewMatchersTest.java From android-test with Apache License 2.0 | 5 votes |
@Test public void withEffectiveVisibility_transformationToProto() { Matcher<View> withEffectiveVisibilityMatcher = withEffectiveVisibility(Visibility.VISIBLE); WithEffectiveVisibilityMatcherProto withEffectiveVisibilityProto = (WithEffectiveVisibilityMatcherProto) new GenericRemoteMessage(withEffectiveVisibilityMatcher).toProto(); assertThat(withEffectiveVisibilityProto, notNullValue()); }
Example #9
Source File: ScrollToAction.java From android-test with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public Matcher<View> getConstraints() { return allOf( withEffectiveVisibility(Visibility.VISIBLE), isDescendantOfA( anyOf( isAssignableFrom(ScrollView.class), isAssignableFrom(HorizontalScrollView.class), isAssignableFrom(ListView.class)))); }
Example #10
Source File: LayoutAssertions.java From android-test with Apache License 2.0 | 5 votes |
/** * Returns a {@link ViewAssertion} that asserts that descendant objects assignable to TextView or * ImageView do not overlap each other. * * <p>Example: {@code onView(rootView).check(noOverlaps());} */ public static ViewAssertion noOverlaps() { return noOverlaps( allOf( withEffectiveVisibility(Visibility.VISIBLE), anyOf(isAssignableFrom(TextView.class), isAssignableFrom(ImageView.class)))); }
Example #11
Source File: NavigationViewTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test public void testActionLayout() { // Open our drawer onView(withId(R.id.drawer_layout)).perform(openDrawer(GravityCompat.START)); // There are four conditions to "find" the menu item with action layout (switch): // 1. Is in the NavigationView // 2. Is direct child of a class that extends RecyclerView // 3. Has a child with "people" text // 4. Has fully displayed child that extends SwitchCompat // Note that condition 2 makes a certain assumption about the internal implementation // details of the NavigationMenu, while conditions 3 and 4 aim to be as generic as // possible and to not rely on the internal details of the current layout implementation // of an individual menu item in NavigationMenu. Matcher<View> menuItemMatcher = allOf( isDescendantOfA(withId(R.id.start_drawer)), isChildOfA(isAssignableFrom(RecyclerView.class)), hasDescendant(withText(menuStringContent.get(R.id.destination_people))), hasDescendant(allOf(isAssignableFrom(SwitchCompat.class), isCompletelyDisplayed()))); // While we don't need to perform any action on our row, the invocation of perform() // makes our matcher actually run. If for some reason NavigationView fails to inflate and // display our SwitchCompat action layout, the next line will fail in the matcher pass. onView(menuItemMatcher).perform(click()); // Check that the full custom view is displayed without title and icon. final Resources res = activityTestRule.getActivity().getResources(); Matcher<View> customItemMatcher = allOf( isDescendantOfA(withId(R.id.start_drawer)), isChildOfA(isAssignableFrom(RecyclerView.class)), hasDescendant(withText(res.getString(R.string.navigate_custom))), hasDescendant( allOf(isAssignableFrom(TextView.class), withEffectiveVisibility(Visibility.GONE)))); onView(customItemMatcher).perform(click()); }
Example #12
Source File: TextInputLayoutIconsTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test public void testSuffixIsVisibleOnFocus() { // Click on text field onView(withId(R.id.textinput_suffix)).perform(click()); // Assert suffix is visible onView(allOf( withId(R.id.textinput_suffix_text), isDescendantOfA(withId(R.id.textinput_suffix)))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))); }
Example #13
Source File: TextInputLayoutIconsTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test public void testPrefixStaysVisibleWithInputText() { // Type some text on the EditText onView(withId(R.id.textinput_edittext_prefix)).perform(typeText(INPUT_TEXT)); // Click on another text field onView(withId(R.id.textinput_no_icon)).perform(click()); // Assert suffix is still visible onView(allOf( withId(R.id.textinput_prefix_text), isDescendantOfA(withId(R.id.textinput_prefix)))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))); }
Example #14
Source File: TextInputLayoutIconsTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test public void testPrefixIsVisibleOnFocus() { // Click on text field onView(withId(R.id.textinput_prefix)).perform(click()); // Assert prefix is visible onView(allOf( withId(R.id.textinput_prefix_text), isDescendantOfA(withId(R.id.textinput_prefix)))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))); }
Example #15
Source File: TextInputLayoutIconsTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test public void testErrorIconMaintainsEndIcon() { // Set error on text field with password toggle icon onView(withId(R.id.textinput_password)).perform(setError("Error")); // Check icon showing is error icon only onView( allOf( withId(R.id.text_input_end_icon), withContentDescription(R.string.error_icon_content_description), isDescendantOfA(withId(R.id.textinput_password)))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))); onView( allOf( withId(R.id.text_input_end_icon), withContentDescription(R.string.password_toggle_content_description), isDescendantOfA(withId(R.id.textinput_password)))) .check(matches(withEffectiveVisibility(Visibility.GONE))); // Unset error onView(withId(R.id.textinput_password)).perform(setError(null)); // Check end icon is back onView( allOf( withId(R.id.text_input_end_icon), withContentDescription(R.string.error_icon_content_description), isDescendantOfA(withId(R.id.textinput_password)))) .check(matches(withEffectiveVisibility(Visibility.GONE))); onView( allOf( withId(R.id.text_input_end_icon), withContentDescription(R.string.password_toggle_content_description), isDescendantOfA(withId(R.id.textinput_password)))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))); }
Example #16
Source File: TextInputLayoutIconsTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test public void testErrorIconAppears() { // Set error onView(withId(R.id.textinput_no_icon)).perform(setError("Error")); // Check the icon is visible onView( allOf( withId(R.id.text_input_end_icon), withContentDescription(R.string.error_icon_content_description), isDescendantOfA(withId(R.id.textinput_no_icon)))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))); }
Example #17
Source File: VisibleViewMatcher.java From kolabnotes-android with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected boolean matchesSafely(View target) { return withEffectiveVisibility(Visibility.VISIBLE).matches(target) && target.getWidth() > 0 && target.getHeight() > 0; }