Skip to content

Instantly share code, notes, and snippets.

@esmasui
Created February 29, 2016 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esmasui/f00e255e60a69e20a1c0 to your computer and use it in GitHub Desktop.
Save esmasui/f00e255e60a69e20a1c0 to your computer and use it in GitHub Desktop.
Androidのテストでクリップボードから貼り付ける
// ペーストのショートカットCtrl+Vを打鍵すればおk
// Espresso
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
instrumentation.sendKeySync(new KeyEvent(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_V, 0, KeyEvent.META_CTRL_ON));
instrumentation.sendKeySync(new KeyEvent(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), KeyEvent.ACTION_UP, KeyEvent.KEYCODE_V, 0, KeyEvent.META_CTRL_ON));

//uiautomator
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
device.pressKeyCode(KeyEvent.KEYCODE_V, KeyEvent.META_CTRL_ON);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment