Reputation: 310
I'm writing UI tests using Espresso. I need to test a flow on double click but failed to do so on some devices.
onView(withId(R.id.idOfView))
.check(matches(someAssertion()))
.perform(doubleClick())
But this performs single click, (sometimes two single clicks) on my Nexus 5 - API Level 23 emulator. Funny workaround
perform(click(), doubleClick())
it works. But I'm not sure if I can trust this. Is there anything that I'm missing?
Upvotes: 1
Views: 471
Reputation: 58507
For two clicks to be recognized as a double-click, the second click's DOWN event must occur within [min, max]
ms of the first click's UP event. min
and max
may vary across different devices, but values I've seen are 40 ms min, and 300 ms max.
A doubleClick
ViewAction
leads to a GeneralClickAction
with a DOUBLE
Tapper
.
That DOUBLE
Tapper
will wait for the minimum required delay before performing its second tap.
What may be happening on your emulator is that it's not running fast enough for the second click event to be injected before you've passed the maximum allowed delay.
When you do perform(click(), doubleClick())
there might not be any added wait between the click
and the doubleClick
, so the click
and the first click of the doubleClick
may end up being recognized as a double-click on your slow emulator. That doesn't guarantee that it would work on an actual device, or on an emulator running on a faster computer.
Upvotes: 1