Frage

Ich schreibe einen UI-Test mit UI Automator und bin auf ein Problem gestoßen, bei dem ich versuche, zum Anfang eines Numberpickers zu scrollen. Wenn ich jedoch entweder ScrollToBeginning oder FlingToBeginning mit einer unterschiedlichen Anzahl von Schritten verwende, scrollt der NumberPicker nur zwei Elemente nach oben und stoppt dann den Bildlauf.Gibt es einen Grund dafür, dass dieses Verhalten konsistent auftritt, und gibt es eine Möglichkeit, es zu beheben oder zu umgehen?

War es hilfreich?

Lösung

Ja, das ist bekannt Bug von UI Automator und unten ist die Problemumgehung dafür:

Verknüpfen

Ausschnitt aus dem obigen Artikel:

Fehler abgelegt: https://groups.google.com/forum/?fromgroups =#!Thema/adt-dev/TjeewtpNWf8

Problemumgehung mithilfe einer Hilfsmethode unten:

/**
 * Launches an app by it's name. 
 * 
 * @param nameOfAppToLaunch the localized name, an exact match is required to launch it.
 */
protected static void launchAppCalled(String nameOfAppToLaunch) throws UiObjectNotFoundException {
    UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
      // Set the swiping mode to horizontal (the default is vertical)
      appViews.setAsHorizontalList();
      appViews.scrollToBeginning(10);  // Otherwise the Apps may be on a later page of apps.
      int maxSearchSwipes = appViews.getMaxSearchSwipes();

      UiSelector selector;
      selector = new UiSelector().className(android.widget.TextView.class.getName());

      UiObject appToLaunch;

      // The following loop is to workaround a bug in Android 4.2.2 which
      // fails to scroll more than once into view.
      for (int i = 0; i < maxSearchSwipes; i++) {

          try {
              appToLaunch = appViews.getChildByText(selector, nameOfAppToLaunch);
              if (appToLaunch != null) {
                  // Create a UiSelector to find the Settings app and simulate      
                  // a user click to launch the app.
                  appToLaunch.clickAndWaitForNewWindow();
                  break;
              }
          } catch (UiObjectNotFoundException e) {
              System.out.println("Did not find match for " + e.getLocalizedMessage());
          }

          for (int j = 0; j < i; j++) {
              appViews.scrollForward();
              System.out.println("scrolling forward 1 page of apps.");
          }
      }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top