Philio / PinEntryView

A pin entry view widget for Android.
222 stars 83 forks source link

Instrumentation tests #19

Open carlbenson opened 8 years ago

carlbenson commented 8 years ago

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)

Philio commented 8 years ago

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?

carlbenson commented 8 years ago

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

EnterPinActivityInstrumentationTest.java.txt

Philio commented 8 years ago

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.

carlbenson commented 8 years ago

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

carlbenson commented 8 years ago

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()