Search in sources :

Example 6 with NoMatchingViewException

use of android.support.test.espresso.NoMatchingViewException in project platform_frameworks_base by android.

the class TextViewAssertions method hasInsertionPointerAtIndex.

/**
     * Returns a {@link ViewAssertion} that asserts that the text view insertion pointer is at
     * a specified index.<br>
     * <br>
     * View constraints:
     * <ul>
     * <li>must be a text view displayed on screen
     * <ul>
     *
     * @param index  A matcher representing the expected index.
     */
public static ViewAssertion hasInsertionPointerAtIndex(final Matcher<Integer> index) {
    return new ViewAssertion() {

        @Override
        public void check(View view, NoMatchingViewException exception) {
            if (view instanceof TextView) {
                TextView textView = (TextView) view;
                int selectionStart = textView.getSelectionStart();
                int selectionEnd = textView.getSelectionEnd();
                try {
                    assertThat(selectionStart, index);
                    assertThat(selectionEnd, index);
                } catch (IndexOutOfBoundsException e) {
                    throw new AssertionFailedError(e.getMessage());
                }
            } else {
                throw new AssertionFailedError("TextView not found");
            }
        }
    };
}
Also used : ViewAssertion(android.support.test.espresso.ViewAssertion) NoMatchingViewException(android.support.test.espresso.NoMatchingViewException) TextView(android.widget.TextView) AssertionFailedError(junit.framework.AssertionFailedError) TextView(android.widget.TextView) View(android.view.View)

Example 7 with NoMatchingViewException

use of android.support.test.espresso.NoMatchingViewException in project frostwire by frostwire.

the class DownloadTest method searchAudio_download.

@Test
public void searchAudio_download() {
    // muckachina test part one (filtering Archive source)
    // public void filterArchive() {
    ViewInteraction linearLayout = onView(allOf(withContentDescription("FrostWire, Open navigation drawer"), withParent(allOf(withClassName(is("com.android.internal.widget.ActionBarView")), withParent(withClassName(is("com.android.internal.widget.ActionBarContainer"))))), isDisplayed()));
    linearLayout.perform(click());
    final ViewInteraction checkableRelativeLayout = onView(allOf(childAtPosition(allOf(withId(R.id.left_drawer), withParent(withId(R.id.activity_main_left_drawer))), 5), isDisplayed()));
    checkableRelativeLayout.perform(click());
    ViewInteraction linearLayout2 = onView(allOf(childAtPosition(allOf(withId(android.R.id.list), withParent(withClassName(is("android.widget.LinearLayout")))), 4), isDisplayed()));
    linearLayout2.perform(click());
    ViewInteraction selectAllInteraction = onView(allOf(withId(R.id.view_preference_checkbox_header_checkbox), isDisplayed()));
    // Let's make sure Archive.org is the only one checked, by deselecting all, archive.org
    // should remain checked.
    selectAllInteraction.check(new ViewAssertion() {

        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            CheckBox checkbox = (CheckBox) view;
            mSelectAllIsChecked = checkbox.isChecked();
        }
    });
    ensureArchiveOrgIsTheOnlyOne(selectAllInteraction);
    ViewInteraction linearLayout3 = onView(allOf(withContentDescription("Search Settings, Navigate up"), withParent(allOf(withClassName(is("com.android.internal.widget.ActionBarView")), withParent(withClassName(is("com.android.internal.widget.ActionBarContainer"))))), isDisplayed()));
    linearLayout3.perform(click());
    ViewInteraction linearLayout4 = onView(allOf(withContentDescription("Settings, Navigate up"), withParent(allOf(withClassName(is("com.android.internal.widget.ActionBarView")), withParent(withClassName(is("com.android.internal.widget.ActionBarContainer"))))), isDisplayed()));
    linearLayout4.perform(click());
    // End muckachina test part one
    // Layout: R.layout.fragment_search
    onView(withId(R.id.fragment_search_input)).check(matches(isDisplayed()));
    /*
         * The textview is in FWAutoCompleteTextView, which is in the layout of the custom view ClearableEditTextView,
         * which is in the custom view SearchInputView which is in the layout R.layout.fragment_search
         */
    onView(allOf(withId(R.id.view_clearable_edit_text_input), isDescendantOfA(withId(R.id.fragment_search_input)))).check(matches(isDisplayed())).perform(typeText("Creative Commons")).perform(pressKey(KeyEvent.KEYCODE_ENTER));
    WaitUntilVisibleIdlingResource resource = new WaitUntilVisibleIdlingResource(activityRule.getActivity().findViewById(R.id.fragment_search_list), activityRule.getActivity().findViewById(R.id.view_search_progress_text_no_results_feedback));
    Espresso.registerIdlingResources(resource);
    // Layout: R.layout.view_searchinput_radiogroup
    onView(allOf(withId(R.id.view_search_input_radio_audio), isDescendantOfA(withId(R.id.fragment_search_input)))).check(matches(isDisplayed())).perform(click());
    FirstFileSearchResultMatcher matchFirstFileSearchResult = new FirstFileSearchResultMatcher();
    // Layout for items in the search results: R.layout.view_bittorrent_search_result_list_item
    // Check that the file name contains "SoundCloud" and "Creative Commons"
    onData(matchFirstFileSearchResult).inAdapterView(withId(R.id.fragment_search_list)).onChildView(withId(R.id.view_bittorrent_search_result_list_item_download_icon)).perform(click());
    // The dialog should show asking us to confirm (NewTransferDialog)
    // Layout: R.layout.dialog_default_checkbox
    onView(withId(R.id.dialog_default_checkbox_button_yes)).check(matches(isDisplayed())).perform(click());
    Espresso.unregisterIdlingResources(resource);
    // Layout: R.layout.fragment_transfers
    // Switch to the downloading list
    onView(withId(R.id.fragment_transfers_button_select_downloading)).check(matches(isDisplayed())).perform(click());
    // Layout of list item in list view inside of fragment_transfers: R.layout.view_transfer_item_list_item
    // Make sure we're downloading the file we chose from the search
    // Switch to the completed list
    onView(withId(R.id.fragment_transfers_button_select_completed)).check(matches(isDisplayed())).perform(click());
    // Register the idling resource to wait for the download to finish
    WaitUntilListViewNotEmptyIdlingResource idlingResource = new WaitUntilListViewNotEmptyIdlingResource((ListView) activityRule.getActivity().findViewById(R.id.fragment_transfers_list));
    Espresso.registerIdlingResources(idlingResource);
    ExactFileSearchResultMatcher downloadingChosenResultMatcher = new ExactFileSearchResultMatcher(matchFirstFileSearchResult.mSearchResult);
    onData(downloadingChosenResultMatcher).inAdapterView(withId(R.id.fragment_transfers_list)).check(matches(isDisplayed()));
    onData(downloadingChosenResultMatcher).inAdapterView(withId(R.id.fragment_transfers_list)).check(matches(isDisplayed()));
    Espresso.unregisterIdlingResources(idlingResource);
}
Also used : WaitUntilVisibleIdlingResource(com.frostwire.android.test.utils.WaitUntilVisibleIdlingResource) ViewAssertion(android.support.test.espresso.ViewAssertion) CheckBox(android.widget.CheckBox) ViewInteraction(android.support.test.espresso.ViewInteraction) NoMatchingViewException(android.support.test.espresso.NoMatchingViewException) WaitUntilListViewNotEmptyIdlingResource(com.frostwire.android.test.utils.WaitUntilListViewNotEmptyIdlingResource) View(android.view.View) TextView(android.widget.TextView) Espresso.onView(android.support.test.espresso.Espresso.onView) ListView(android.widget.ListView) LargeTest(android.test.suitebuilder.annotation.LargeTest) Test(org.junit.Test)

Example 8 with NoMatchingViewException

use of android.support.test.espresso.NoMatchingViewException in project android_frameworks_base by crdroidandroid.

the class SuggestionsPopupWindowTest method testTextAppearanceInSuggestionsPopup.

@SmallTest
public void testTextAppearanceInSuggestionsPopup() {
    final String text = "abc def ghi";
    final String[] singleWordCandidates = { "DEF", "Def" };
    final SuggestionSpan suggestionSpan = new SuggestionSpan(getActivity(), singleWordCandidates, SuggestionSpan.FLAG_MISSPELLED);
    final String[] multiWordCandidates = { "ABC DEF GHI", "Abc Def Ghi" };
    final SuggestionSpan multiWordSuggestionSpan = new SuggestionSpan(getActivity(), multiWordCandidates, SuggestionSpan.FLAG_MISSPELLED);
    final TypedArray array = getActivity().obtainStyledAttributes(com.android.internal.R.styleable.Theme);
    final int id = array.getResourceId(com.android.internal.R.styleable.Theme_textEditSuggestionHighlightStyle, 0);
    array.recycle();
    final TextAppearanceSpan expectedSpan = new TextAppearanceSpan(getActivity(), id);
    final TextPaint tmpTp = new TextPaint();
    expectedSpan.updateDrawState(tmpTp);
    final int expectedHighlightTextColor = tmpTp.getColor();
    final float expectedHighlightTextSize = tmpTp.getTextSize();
    final TextView textView = (TextView) getActivity().findViewById(R.id.textview);
    // *XX* means that XX is highlighted.
    for (int i = 0; i < 2; i++) {
        onView(withId(R.id.textview)).perform(click());
        onView(withId(R.id.textview)).perform(replaceText(text));
        setSuggestionSpan(suggestionSpan, text.indexOf('d'), text.indexOf('f') + 1);
        setSuggestionSpan(multiWordSuggestionSpan, 0, text.length());
        showSuggestionsPopup();
        assertSuggestionsPopupIsDisplayed();
        assertSuggestionsPopupContainsItem("abc DEF ghi");
        assertSuggestionsPopupContainsItem("abc Def ghi");
        assertSuggestionsPopupContainsItem("ABC DEF GHI");
        assertSuggestionsPopupContainsItem("Abc Def Ghi");
        assertSuggestionsPopupContainsItem(getActivity().getString(com.android.internal.R.string.delete));
        onSuggestionsPopup().check(new ViewAssertion() {

            @Override
            public void check(View view, NoMatchingViewException e) {
                final ListView listView = (ListView) view.findViewById(com.android.internal.R.id.suggestionContainer);
                assertNotNull(listView);
                final int childNum = listView.getChildCount();
                assertEquals(singleWordCandidates.length + multiWordCandidates.length, childNum);
                for (int j = 0; j < childNum; j++) {
                    final TextView suggestion = (TextView) listView.getChildAt(j);
                    assertNotNull(suggestion);
                    final Spanned spanned = (Spanned) suggestion.getText();
                    assertNotNull(spanned);
                    // Check that the suggestion item order is kept.
                    final String expectedText;
                    if (j < singleWordCandidates.length) {
                        expectedText = "abc " + singleWordCandidates[j] + " ghi";
                    } else {
                        expectedText = multiWordCandidates[j - singleWordCandidates.length];
                    }
                    assertEquals(expectedText, spanned.toString());
                    // Check that the text is highlighted with correct color and text size.
                    final TextAppearanceSpan[] taSpan = spanned.getSpans(text.indexOf('d'), text.indexOf('f') + 1, TextAppearanceSpan.class);
                    assertEquals(1, taSpan.length);
                    TextPaint tp = new TextPaint();
                    taSpan[0].updateDrawState(tp);
                    assertEquals(expectedHighlightTextColor, tp.getColor());
                    assertEquals(expectedHighlightTextSize, tp.getTextSize());
                    // Check the correct part of the text is highlighted.
                    final int expectedStart;
                    final int expectedEnd;
                    if (j < singleWordCandidates.length) {
                        expectedStart = text.indexOf('d');
                        expectedEnd = text.indexOf('f') + 1;
                    } else {
                        expectedStart = 0;
                        expectedEnd = text.length();
                    }
                    assertEquals(expectedStart, spanned.getSpanStart(taSpan[0]));
                    assertEquals(expectedEnd, spanned.getSpanEnd(taSpan[0]));
                }
            }
        });
        pressBack();
        onView(withId(R.id.textview)).inRoot(withDecorView(is(getActivity().getWindow().getDecorView()))).perform(clearText());
    }
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan) NoMatchingViewException(android.support.test.espresso.NoMatchingViewException) View(android.view.View) Espresso.onView(android.support.test.espresso.Espresso.onView) RootMatchers.withDecorView(android.support.test.espresso.matcher.RootMatchers.withDecorView) DragHandleUtils.onHandleView(android.widget.espresso.DragHandleUtils.onHandleView) Spanned(android.text.Spanned) TextPaint(android.text.TextPaint) TextPaint(android.text.TextPaint) ViewAssertion(android.support.test.espresso.ViewAssertion) TypedArray(android.content.res.TypedArray) SuggestionSpan(android.text.style.SuggestionSpan) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 9 with NoMatchingViewException

use of android.support.test.espresso.NoMatchingViewException in project android_frameworks_base by crdroidandroid.

the class TextViewAssertions method hasInsertionPointerAtIndex.

/**
     * Returns a {@link ViewAssertion} that asserts that the text view insertion pointer is at
     * a specified index.<br>
     * <br>
     * View constraints:
     * <ul>
     * <li>must be a text view displayed on screen
     * <ul>
     *
     * @param index  A matcher representing the expected index.
     */
public static ViewAssertion hasInsertionPointerAtIndex(final Matcher<Integer> index) {
    return new ViewAssertion() {

        @Override
        public void check(View view, NoMatchingViewException exception) {
            if (view instanceof TextView) {
                TextView textView = (TextView) view;
                int selectionStart = textView.getSelectionStart();
                int selectionEnd = textView.getSelectionEnd();
                try {
                    assertThat(selectionStart, index);
                    assertThat(selectionEnd, index);
                } catch (IndexOutOfBoundsException e) {
                    throw new AssertionFailedError(e.getMessage());
                }
            } else {
                throw new AssertionFailedError("TextView not found");
            }
        }
    };
}
Also used : ViewAssertion(android.support.test.espresso.ViewAssertion) NoMatchingViewException(android.support.test.espresso.NoMatchingViewException) TextView(android.widget.TextView) AssertionFailedError(junit.framework.AssertionFailedError) TextView(android.widget.TextView) View(android.view.View)

Example 10 with NoMatchingViewException

use of android.support.test.espresso.NoMatchingViewException in project appium-espresso-driver by appium.

the class ScrollTo method handle.

@Override
@Nullable
public Void handle(ScrollToParams params) throws AppiumException {
    try {
        ViewInteraction viewInteraction = onView(withText(params.getText()));
        viewInteraction.perform(scrollTo());
    } catch (NoMatchingViewException e) {
        throw new NoSuchElementException("Could not find element with text " + params.getText());
    }
    return null;
}
Also used : ViewInteraction(android.support.test.espresso.ViewInteraction) NoMatchingViewException(android.support.test.espresso.NoMatchingViewException) NoSuchElementException(io.appium.espressoserver.lib.handlers.exceptions.NoSuchElementException) Nullable(javax.annotation.Nullable)

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