4

I'm really new with esspresso issues and I have a little question, I need to emulate that users click on a button, tree times, but with some delay. A Human, takes some time to click a button, maybe with one second delay.

Whats the better way to made that on an esspresso test? othere frameworks have sleep, and so on... but I think that espresso hasen't. Any idea?

--Edited: I made this, but don't know if it's correct:

try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Another way, but more clear, if you don't use thread.interrupt() is this:

SystemClock.sleep(millis)
jfcogato
  • 3,359
  • 3
  • 19
  • 19
  • Can't you use `Handler` to achieve this? – Spring Breaker Mar 12 '14 at 11:55
  • Yeah, but I don't know if is the better way to made it. I see some sourceCode from google team[1]. And I have to check how they are doing ... I don't know if someone has an easy way example. [1] https://code.google.com/p/android-test-kit/source/browse/espresso/libtests/src/main/java/com/google/android/apps/common/testing/ui/espresso/action/EventActionIntegrationTest.java?r=6dc2d307927f6afc497a1fb0292f42d8e725d227 – jfcogato Mar 12 '14 at 13:19
  • http://stackoverflow.com/a/22563297/349681 - i wrote a class that can simplify this. Try it. – Oleksandr Kucherenko Apr 07 '14 at 13:02

1 Answers1

21
for (int = i; i < numOfClicks; i++) {
  onView(<matcher for your view>).perform(click());
  SystemClock.sleep(1000);
}
ValeraZakharov
  • 3,767
  • 2
  • 15
  • 12