public static void openOptionsMenuAndInvokeItem(
      Instrumentation instrumentation, final Activity activity, final int itemId) {
    if (!instrumentation.invokeMenuActionSync(activity, itemId, 0)) {
      throw new RuntimeException("Failed to invoke options menu item ID " + itemId);
    }
    instrumentation.waitForIdleSync();
  }
Opens the options menu of the provided {@link Activity} and invokes the menu item with the
provided ID.

<p>Note: This method cannot be invoked on the main thread.
javatests/com/google/android/apps/authenticator/testing/TestUtilities.java