Code example for Instrumentation

Methods: runOnMainSyncwaitForIdleSync

0
  public static final int UI_ACTION_EFFECT_TIMEOUT_MILLIS = 5000;
 
  private TestUtilities() { } 
 
  public static void clickView(Instrumentation instr, final View view) {
    instr.runOnMainSync(new Runnable() {
      @Override 
      public void run() { 
        view.performClick();
      } 
    }); 
    // this shouldn't be needed but without it or sleep, there isn't time for view refresh, etc. 
    instr.waitForIdleSync();
  } 
 
  public static void longClickView(Instrumentation instr, final View view) {
    instr.runOnMainSync(new Runnable() {
      @Override 
      public void run() { 
        view.performLongClick();
      }