jxs1211 / android-test-kit

Automatically exported from code.google.com/p/android-test-kit
0 stars 0 forks source link

TypeTextAction not supported for android.support.v7.widget.SearchView #54

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a search interface 
(http://developer.android.com/guide/topics/search/search-dialog.html)
2. Create a test for the search activity
3. public void testSearch() throws Exception {
        Matcher<View> matcherView = withId(R.id.menu_search);

        onView(matcherView)
            .perform(click());

        onView(withParent(matcherView))
            .perform(typeText("test"), pressImeActionButton());
    }

What is the expected output? 

A "Test passed" message.

What do you see instead?

java.lang.RuntimeException: Action will not be performed because the target 
view does not match one or more of the following constraints:
((is displayed on the screen to the user) and (supports input methods or is 
assignable from class: class android.widget.SearchView))

What version of the product are you using? 

espresso-1.1

On what operating system?

OS X Version 10.8.4

Please provide any additional information below.

I have checked TypeTextAction.java class to see what is going wrong and that's 
what I've found:

@SuppressWarnings("unchecked")
  @Override
  public Matcher<View> getConstraints() {
    Matcher<View> matchers = allOf(isDisplayed());
    if (!tapToFocus) {
      matchers = allOf(matchers, hasFocus());
    }

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
       return allOf(matchers, supportsInputMethods());
    } else {
       // SearchView does not support input methods itself (rather it delegates to an internal text
       // view for input).
       return allOf(matchers, anyOf(supportsInputMethods(), isAssignableFrom(SearchView.class)));
    }
  }

Apparently, it's being checked just if the matchers "isAssignabledFrom" 
SearchView.class (android.widget.SearchView).

If I'm using android.support.v7.widget.SearchView, what should I do to match 
this constraint?

Original issue reported on code.google.com by sagui...@gmail.com on 10 Feb 2014 at 8:24

GoogleCodeExporter commented 9 years ago

Original comment by vale...@google.com on 7 May 2014 at 7:10

GoogleCodeExporter commented 9 years ago
Espresso 2.0 codebase includes this sample now:

 public void testAppCompatSearchViewFromActionBar() {
    onView(withId(R.id.menu_search))
        .perform(click());

    // App Compat SearchView widget does not use the same id as in the regular
    // android.widget.SearchView. R.id.search_src_text is the id created by appcompat
    // search widget.
    onView(withId(R.id.search_src_text))
        .perform(typeText("Hello World"));
  }

Original comment by vale...@google.com on 30 Mar 2015 at 8:53