Example #1
0
  @Test
  public void testClick() throws UiMultimatorException, IOException {
    UiDevice uiDevice = getUiDevice().any();
    uiDevice.pressHome();

    UiObject messagingButton = uiDevice.newUiObject(new UiSelector().text("Messaging"));
    messagingButton.click();
  }
Example #2
0
  /** Current implementation ignores the exception and continues. */
  public void postHandler() {
    // TODO: Add custom error logging here

    String formatedOutput =
        String.format(
            "UI Exception Message: %-20s\n", UiDevice.getInstance().getCurrentPackageName());
    Log.e(LOG_TAG, formatedOutput);

    UiObject buttonOK = new UiObject(new UiSelector().text("OK").enabled(true));
    // sometimes it takes a while for the OK button to become enabled
    buttonOK.waitForExists(5000);
    try {
      buttonOK.click();
    } catch (UiObjectNotFoundException e) {
      Log.e(LOG_TAG, "Exception", e);
    }
  }
  private void loadXPrivacyConfig(String actionCommand) {
    // There is an intent to open the import configuration screen,
    // however there is a bug on XPrivacy, when that intent is called,
    // after a file is selected its contents are not displayed and no
    // operation is performed
    Log.d(uiaDaemon_logcatTag, "Loading XPrivacy configuration file.");

    // Extract the configuration file name
    String fileName = actionCommand.split("=")[1];
    Log.d(uiaDaemon_logcatTag, "Filename = " + fileName);

    try {
      // launchApp("XPrivacy");

      String XPrivacy = "biz.bokhorst.xprivacy";
      String XPrivacyToolbar = XPrivacy + ":id/widgetToolbar";
      String XPrivacyOkButton = XPrivacy + ":id/btnOk";
      UiObject toolbar = this.device.findObject(new UiSelector().resourceId(XPrivacyToolbar));

      // Locate the toolbar
      UiObject buttonSet = toolbar.getChild(new UiSelector().index(2));
      UiObject menuButton = buttonSet.getChild(new UiSelector().index(1));
      // Click to open the menu
      menuButton.click();
      waitForGuiToStabilize();

      // Select "Operations …" item from menu
      UiObject operationsButton = this.device.findObject(new UiSelector().text("Operations …"));
      operationsButton.click();
      waitForGuiToStabilize();

      // Select "Import"
      UiObject importButton = this.device.findObject(new UiSelector().text("Import"));
      importButton.click();
      waitForGuiToStabilize();

      // Select configuration file
      UiObject fileManagerButton = this.device.findObject(new UiSelector().text("OI File Manager"));
      fileManagerButton.click();
      waitForGuiToStabilize();

      UiObject textInput = this.device.findObject(new UiSelector().text("File name"));
      textInput.setText(fileName);

      UiObject pickFileButton = this.device.findObject(new UiSelector().text("Pick file"));
      pickFileButton.click();
      waitForGuiToStabilize();

      UiObject okButton = this.device.findObject(new UiSelector().resourceId(XPrivacyOkButton));
      okButton.click();

      do {
        okButton = this.device.findObject(new UiSelector().resourceId(XPrivacyOkButton));
        waitForGuiToStabilize();
      } while (!okButton.isEnabled());

      waitForGuiToStabilize();

      okButton.click();
      this.device.waitForIdle();
      waitForGuiToStabilize();

      // Return to home
      this.device.pressHome();
      this.device.waitForIdle();
    } catch (UiObjectNotFoundException ex) {
      Log.e(uiaDaemon_logcatTag, "Failed to import XPrivacy configuration.");
    }
    // catch (UiAutomatorDaemonException ex)
    // {
    //  Log.e(uiaDaemon_logcatTag, "Failed to start XPrivacy.");
    // }

    Log.d(uiaDaemon_logcatTag, "XPrivacy configuration file loaded.");
  }