PinEntryView icon indicating copy to clipboard operation
PinEntryView copied to clipboard

Instrumentation tests

Open carlbenson opened this issue 8 years ago • 5 comments

How can I do instrumentation tests using for instance Espresso and hamcrest view matchers if the PinEntry view does not support any input?

Caused by: 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)) Target view: "PinEntryView{id=2131427464, res-name=pin_entry, visibility=VISIBLE, width=570, height=120, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=207.0, y=154.0, child-count=5}" at android.support.test.espresso.ViewInteraction$1.run(ViewInteraction.java:138)

carlbenson avatar Feb 16 '16 09:02 carlbenson

If it doesn't meet the constraint is displayed on the screen to the user then the view must not be visible? Could you provide some code?

Philio avatar Feb 16 '16 12:02 Philio

It's visible, but apparently it does not support any input methods.

EnterPinActivityInstrumentationTest.java.txt

carlbenson avatar Feb 16 '16 13:02 carlbenson

The view itself is just a view group with an EditText inside which it delegates focus to. It doesn't accept input directly so that might be the issue.

Philio avatar Feb 16 '16 14:02 Philio

So would it be possible to expose the EditText somehow so this view can be used in instrumentation tests?

carlbenson avatar Feb 17 '16 07:02 carlbenson

I'm testing using a work-around now where I simply set the text in an observable and do the check when the observable has completed (Kotlin code)

@Test                                                                                               
fun enterPinCode() {                                                                                
    val view = mActivityRule.activity.findViewById(R.id.pin_entry) as PinEntryView                  
    observable<Unit> {                                                                              
        view.setText("123")                                                                         
    }.subscribeOn(AndroidSchedulers.mainThread())                                                   
            .doOnCompleted {                                                                        
                onView(ViewMatchers.withId(R.id.pin_next_button)).check(matches(not(isDisplayed())))
            }.subscribe()                                                                           

carlbenson avatar Feb 17 '16 08:02 carlbenson