Search in sources :

Example 1 with MobileApp

use of com.testsigma.automator.mobile.MobileApp in project testsigma by testsigmahq.

the class AppInstaller method checkIfInstalled.

public boolean checkIfInstalled(String deviceName, String deviceUniqueId, String bundleId) throws AutomatorException {
    try {
        log.info("Checking if a mobile app with bundle id - " + bundleId + " is installed in device - " + deviceName);
        boolean installed = false;
        int i = 0;
        while (i < 12) {
            List<MobileApp> apps = getMobileApps(deviceName, deviceUniqueId);
            for (MobileApp app : apps) {
                if (app.getBundleId().equals(bundleId)) {
                    installed = true;
                    break;
                }
            }
            if (installed)
                break;
            log.info("Looks like app is not installed yet...retrying in 5 seconds...");
            Thread.sleep(5000);
            i++;
        }
        if (!installed) {
            log.info("Looks like some issue app installation. For now assuming its installed and proceeding");
            installed = true;
        }
        return installed;
    } catch (Exception e) {
        throw new AutomatorException(e.getMessage(), e);
    }
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) MobileApp(com.testsigma.automator.mobile.MobileApp) AutomatorException(com.testsigma.automator.exceptions.AutomatorException)

Example 2 with MobileApp

use of com.testsigma.automator.mobile.MobileApp in project testsigma by testsigmahq.

the class AppInstaller method getMobileApps.

public List<MobileApp> getMobileApps(String deviceName, String deviceUniqueId) throws AutomatorException {
    List<MobileApp> apps = new ArrayList<>();
    log.info("Fetching list of mobile apps on device - " + deviceName);
    try {
        Process p = iosDeviceCommandExecutor.runDeviceCommand(new String[] { "-u", deviceUniqueId, "applist" });
        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while ((line = br.readLine()) != null) {
            String[] tokens = line.split(" ");
            if (tokens.length >= 3) {
                MobileApp app = new MobileApp();
                app.setBundleId(tokens[0]);
                StringBuilder appName = new StringBuilder();
                for (int i = 1; i < (tokens.length - 1); i++) {
                    appName.append(tokens[i]);
                }
                app.setName(appName.toString());
                app.setVersion(tokens[tokens.length - 1]);
                app.setAppType(MobileAppType.iOS);
                apps.add(app);
            }
        }
    } catch (Exception e) {
        throw new AutomatorException(e.getMessage(), e);
    }
    log.info("List of mobile apps for device - " + deviceName + ". App list - " + apps);
    return apps;
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) InputStreamReader(java.io.InputStreamReader) MobileApp(com.testsigma.automator.mobile.MobileApp) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) AutomatorException(com.testsigma.automator.exceptions.AutomatorException)

Aggregations

AutomatorException (com.testsigma.automator.exceptions.AutomatorException)2 MobileApp (com.testsigma.automator.mobile.MobileApp)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1