Search in sources :

Example 21 with NoMatchingViewException

use of android.support.test.espresso.NoMatchingViewException in project material-components-android by material-components.

the class TabLayoutTest method testSetScrollPosition.

private void testSetScrollPosition(final boolean isLtr) throws Throwable {
    activityTestRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            activityTestRule.getActivity().setContentView(R.layout.design_tabs_fixed_width);
        }
    });
    final TabLayout tabs = (TabLayout) activityTestRule.getActivity().findViewById(R.id.tabs);
    assertEquals(TabLayout.MODE_SCROLLABLE, tabs.getTabMode());
    final TabLayoutScrollIdlingResource idler = new TabLayoutScrollIdlingResource(tabs);
    Espresso.registerIdlingResources(idler);
    // We're going to call setScrollPosition() incrementally, as if scrolling between one tab
    // and the next. Use the middle tab for best results. The positionOffsets should be in the
    // range [0, 1), so the final call will wrap to 0 but use the next tab's position.
    final int middleTab = tabs.getTabCount() / 2;
    final int[] positions = { middleTab, middleTab, middleTab, middleTab, middleTab + 1 };
    final float[] positionOffsets = { 0f, .25f, .5f, .75f, 0f };
    // Set layout direction
    onView(withId(R.id.tabs)).perform(setLayoutDirection(isLtr ? ViewCompat.LAYOUT_DIRECTION_LTR : ViewCompat.LAYOUT_DIRECTION_RTL));
    // Make sure it's scrolled all the way to the start
    onView(withId(R.id.tabs)).perform(selectTab(0));
    // Perform a series of setScrollPosition() calls
    final AtomicInteger lastScrollX = new AtomicInteger(tabs.getScrollX());
    for (int i = 0; i < positions.length; i++) {
        onView(withId(R.id.tabs)).perform(setScrollPosition(positions[i], positionOffsets[i])).check(new ViewAssertion() {

            @Override
            public void check(View view, NoMatchingViewException notFoundException) {
                if (view == null) {
                    throw notFoundException;
                }
                // Verify increasing or decreasing scroll X values
                int sx = view.getScrollX();
                assertTrue(isLtr ? sx > lastScrollX.get() : sx < lastScrollX.get());
                lastScrollX.set(sx);
            }
        });
    }
    Espresso.unregisterIdlingResources(idler);
}
Also used : ViewAssertion(android.support.test.espresso.ViewAssertion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NoMatchingViewException(android.support.test.espresso.NoMatchingViewException) View(android.view.View) Espresso.onView(android.support.test.espresso.Espresso.onView)

Example 22 with NoMatchingViewException

use of android.support.test.espresso.NoMatchingViewException in project material-components-android by material-components.

the class BottomSheetBehaviorTest method testInvisibleThenVisible.

@Test
@MediumTest
public void testInvisibleThenVisible() throws Throwable {
    activityTestRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            // The bottom sheet is initially invisible
            getBottomSheet().setVisibility(View.INVISIBLE);
            // Then it becomes visible when the CoL is touched
            getCoordinatorLayout().setOnTouchListener(new View.OnTouchListener() {

                @Override
                public boolean onTouch(View view, MotionEvent e) {
                    if (e.getAction() == MotionEvent.ACTION_DOWN) {
                        getBottomSheet().setVisibility(View.VISIBLE);
                        return true;
                    }
                    return false;
                }
            });
            assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
        }
    });
    // Drag over the CoL
    Espresso.onView(ViewMatchers.withId(R.id.coordinator)).perform(new DragAction(GeneralLocation.BOTTOM_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER)).check(new ViewAssertion() {

        @Override
        public void check(View view, NoMatchingViewException e) {
            // The bottom sheet should not react to the touch events
            assertThat(getBottomSheet(), is(ViewMatchers.isDisplayed()));
            assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
        }
    });
}
Also used : ViewAssertion(android.support.test.espresso.ViewAssertion) NoMatchingViewException(android.support.test.espresso.NoMatchingViewException) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent) SmallTest(android.support.test.filters.SmallTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 23 with NoMatchingViewException

use of android.support.test.espresso.NoMatchingViewException in project material-components-android by material-components.

the class BottomSheetBehaviorTouchTest method testTouchCoordinatorLayout.

@Test
public void testTouchCoordinatorLayout() {
    final CoordinatorLayoutActivity activity = activityTestRule.getActivity();
    mDown = false;
    Espresso.onView(sameInstance((View) activity.mCoordinatorLayout)).perform(// Click outside the bottom sheet
    ViewActions.click()).check(new ViewAssertion() {

        @Override
        public void check(View view, NoMatchingViewException e) {
            assertThat(e, is(nullValue()));
            assertThat(view, is(notNullValue()));
            // Check that the touch event fell through to the container
            assertThat(mDown, is(true));
        }
    });
}
Also used : ViewAssertion(android.support.test.espresso.ViewAssertion) CoordinatorLayoutActivity(android.support.design.testapp.CoordinatorLayoutActivity) NoMatchingViewException(android.support.test.espresso.NoMatchingViewException) View(android.view.View) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 24 with NoMatchingViewException

use of android.support.test.espresso.NoMatchingViewException in project wire-android by wireapp.

the class UsernameEditFragmentTest method assertShortUsernameShowsError.

@Test
public void assertShortUsernameShowsError() throws InterruptedException {
    String currentUsername = "";
    attachFragment(ChangeUsernamePreferenceDialogFragment.newInstance(currentUsername, true), ChangeUsernamePreferenceDialogFragment.TAG);
    Thread.sleep(400);
    onView(withId(R.id.acet__change_username)).perform(typeTextIntoFocusedView("1"));
    Thread.sleep(400);
    onView(withId(R.id.til__change_username)).check(new ViewAssertion() {

        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            CharSequence error = ((TextInputLayout) view).getError();
            if (error == null || error.length() == 0) {
                throw new AssertionFailedError("Error field is empty");
            }
        }
    });
}
Also used : ViewAssertion(android.support.test.espresso.ViewAssertion) NoMatchingViewException(android.support.test.espresso.NoMatchingViewException) AssertionFailedError(junit.framework.AssertionFailedError) ViewActions.typeTextIntoFocusedView(android.support.test.espresso.action.ViewActions.typeTextIntoFocusedView) Espresso.onView(android.support.test.espresso.Espresso.onView) View(android.view.View) Test(org.junit.Test) FragmentTest(com.waz.zclient.testutils.FragmentTest)

Example 25 with NoMatchingViewException

use of android.support.test.espresso.NoMatchingViewException in project wire-android by wireapp.

the class UsernameEditFragmentTest method assertInvalidUsernameCantBeSet.

@Test
public void assertInvalidUsernameCantBeSet() throws InterruptedException {
    String currentUsername = "";
    attachFragment(ChangeUsernamePreferenceDialogFragment.newInstance(currentUsername, true), ChangeUsernamePreferenceDialogFragment.TAG);
    Thread.sleep(400);
    onView(withId(R.id.acet__change_username)).perform(typeTextIntoFocusedView("1"));
    Thread.sleep(400);
    onView(withId(R.id.til__change_username)).check(new ViewAssertion() {

        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            if (!view.isEnabled()) {
                throw new AssertionFailedError("View is enabled");
            }
        }
    });
}
Also used : ViewAssertion(android.support.test.espresso.ViewAssertion) NoMatchingViewException(android.support.test.espresso.NoMatchingViewException) AssertionFailedError(junit.framework.AssertionFailedError) ViewActions.typeTextIntoFocusedView(android.support.test.espresso.action.ViewActions.typeTextIntoFocusedView) Espresso.onView(android.support.test.espresso.Espresso.onView) View(android.view.View) Test(org.junit.Test) FragmentTest(com.waz.zclient.testutils.FragmentTest)

Aggregations

NoMatchingViewException (android.support.test.espresso.NoMatchingViewException)34 ViewAssertion (android.support.test.espresso.ViewAssertion)23 View (android.view.View)23 Espresso.onView (android.support.test.espresso.Espresso.onView)16 TextView (android.widget.TextView)9 ViewInteraction (android.support.test.espresso.ViewInteraction)7 RootMatchers.withDecorView (android.support.test.espresso.matcher.RootMatchers.withDecorView)7 AssertionFailedError (junit.framework.AssertionFailedError)7 Test (org.junit.Test)7 TypedArray (android.content.res.TypedArray)5 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 Spanned (android.text.Spanned)5 TextPaint (android.text.TextPaint)5 SuggestionSpan (android.text.style.SuggestionSpan)5 TextAppearanceSpan (android.text.style.TextAppearanceSpan)5 DragHandleUtils.onHandleView (android.widget.espresso.DragHandleUtils.onHandleView)5 Calendar (java.util.Calendar)5 GregorianCalendar (java.util.GregorianCalendar)5 PerformException (android.support.test.espresso.PerformException)3 NoMatchingRootException (android.support.test.espresso.NoMatchingRootException)2