I am testing an Android app with Espresso. I have an EditText
widget with androidInputType=date
. When I touch this control with my finger, a calendar pops up for me to select the date.
How do I automate this in Espresso? I've looked all over the place and I can't figure it out. typeText()
certainly does not work.
Original answered by me here, but in the scope of another question: Recording an Espresso test with a DatePicker - so I repost my adapted answer from there:
Use this line to set the date in a datepicker:
This uses the
PickerActions
which is part of the espresso support library - theespresso-contrib
. To use it, add it like this to your gradle file (You need several excludes to prevent compile errors due to mismatching support library version):Then you could create a helper method which clicks the view that opens the datepicker, sets the date and confirms it by clicking the ok button:
And then use it like this in your tests: