I used this code (inspired by this such answer )
class MainMenuActivityTest { @Test fun textInputDialog_opens_on_button_clicked() { onView(withId(R.id.text_input_button)) .perform(betterScrollTo()) .perform(click()) } }
and now it works
I first used this answer here , but used the following code for my test:
class MainMenuActivityTest { @Test fun textInputDialog_opens_on_button_clicked() { onView(withId(R.id.text_input_button)) .perform(betterScrollTo()) .perform(click()) } }
but I got the following exceptions ...
E/TestRunner: failed: textInputDialog_opens_on_button_clicked(com.github.ericytsang.example.app.android.MainMenuActivityTest) ----- begin exception ----- E/TestRunner: androidx.test.espresso.PerformException: Error performing 'scroll to' on view 'Animations or transitions are enabled on the target device. For more info check: https://developer.android.com/training/testing/espresso/setup#set-up-environment with id: com.github.ericytsang.app.example.android:id/text_input_button'. ............ at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2196) Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints: (view has effective visibility=VISIBLE and is descendant of a: (is assignable from class: class android.widget.ScrollView or is assignable from class: class android.widget.HorizontalScrollView or is assignable from class: class android.widget.ListView)) Target view: "AppCompatButton{id=2131296521, res-name=text_input_button, visibility=VISIBLE, width=1008, height=107, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-p arams=androidx.appcompat.widget.LinearLayoutCompat$LayoutParams@ cec11da, tag=null, root-is-layout-requested=false, has-input-connection=false, x=18.0, y=516.0, text=text input dialog, input-type=0, ime-target=false, has-links=false}" at androidx.test.espresso.ViewInteraction.doPerform(ViewInterac ----- end exception -----
E/TestRunner: failed: textInputDialog_opens_on_button_clicked(com.github.ericytsang.example.app.android.MainMenuActivityTest) ----- begin exception ----- E/TestRunner: androidx.test.espresso.PerformException: Error performing 'scroll to' on view 'with id: com.github.ericytsang.app.example.android:id/text_input_button'. ........ Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints: (view has effective visibility=VISIBLE and is descendant of a: (is assignable from class: class android.widget.ScrollView or is assignable from class: class android.widget.HorizontalScrollView or is assignable from class: class android.widget.ListView)) Target view: "AppCompatButton{id=2131296521, res-name=text_input_button, visibility=VISIBLE, width=1008, height=107, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-p arams=androidx.appcompat.widget.LinearLayoutCompat$LayoutParams@ 3e84212, tag=null, root-is-layout-requested=false, has-input-connection=false, x=18.0, y=516.0, text=text input dialog, input-type=0, ime-target=false, has-links=false}" at androidx.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:252) at androidx.test.espresso.ViewInteraction.access$100(ViewInteraction.java:65) at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.jav ----- end exception -----