Search in sources :

Example 1 with IProcessExecutor

use of com.axway.ats.core.process.model.IProcessExecutor in project ats-framework by Axway.

the class MobileDriver method startIOSApplication.

/**
     * <pre>
     * Start iOS application using <b>ios-sim</b> command: ios-sim launch &lt;PATH TO APPLICATION.APP&gt; --timeout 60 --exit<br/>
     * for example: <i>ios-sim launch /tmp/test/MobileAccessPlus.app --timeout 60 --exit</i>
     * <br/>
     * This command also starts the iOS Simulator if it's not already started.
     * <br/>
     * Check here how to install <b>ios-sim</b>: <a href="https://github.com/phonegap/ios-sim#installation">https://github.com/phonegap/ios-sim#installation</a>
     * </pre>
     * @param appPath path to the application .app file
     */
private void startIOSApplication(String appPath) {
    log.info("Starting application '" + appPath + "' on device: " + getDeviceDescription());
    String[] commandArguments = new String[] { "launch", appPath, "--timeout", "60", "--exit" };
    IProcessExecutor pe = null;
    try {
        pe = getProcessExecutorImpl("ios-sim", commandArguments);
        pe.execute();
    } catch (Exception e) {
        throw new MobileOperationException("Unable to start iOS application '" + appPath + "'", e);
    }
    if (pe.getExitCode() != 0) {
        throw new MobileOperationException("Unable to start iOS application '" + appPath + "'. Start command failed (STDOUT: '" + pe.getStandardOutput() + "', STDERR: '" + pe.getErrorOutput() + "')");
    }
}
Also used : MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) NotSupportedOperationException(com.axway.ats.uiengine.exceptions.NotSupportedOperationException) IProcessExecutor(com.axway.ats.core.process.model.IProcessExecutor)

Example 2 with IProcessExecutor

use of com.axway.ats.core.process.model.IProcessExecutor in project ats-framework by Axway.

the class MobileDriver method startAndroidApplication.

/**
     * Start application using ADB command: ./adb shell am start -W -S -n &lt;ACTIVITY&gt;<br/>
     * for example: ./adb shell am start -W -S -n com.axway.st.mobile/.MobileAccessPlus
     *
     * @param activity application activity name
     */
private void startAndroidApplication(String activity) {
    log.info("Starting application with activity '" + activity + "' on device: " + getDeviceDescription());
    String[] commandArguments = new String[] { "shell", "am", "start", "-W", "-S", "-n", activity };
    int numRetries = 0;
    IProcessExecutor pe = null;
    while (numRetries <= MAX_ADB_RELATED_RETRIES) {
        if (numRetries > 0) {
            log.info("Retrying to start application action as previous try failed");
        }
        try {
            pe = this.mobileDeviceUtils.executeAdbCommand(commandArguments, false);
        } catch (Exception e) {
            throw new MobileOperationException("Unable to start Android application with activity '" + activity + "'", e);
        }
        numRetries++;
        if (pe.getExitCode() == 0) {
            break;
        } else {
            if (numRetries <= MAX_ADB_RELATED_RETRIES) {
                log.error("Unable to start Android application with activity '" + activity + "'. Start command failed (Exit code: " + pe.getExitCode() + ", STDOUT: '" + pe.getStandardOutput() + "', STDERR: '" + pe.getErrorOutput() + "')");
                //try to kill ADB and issue start again
                killAdbServer();
            } else {
                throw new MobileOperationException("Unable to start Android application with activity '" + activity + "'. Start command failed (STDOUT: '" + pe.getStandardOutput() + "', STDERR: '" + pe.getErrorOutput() + "')");
            }
        }
    }
}
Also used : MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) NotSupportedOperationException(com.axway.ats.uiengine.exceptions.NotSupportedOperationException) IProcessExecutor(com.axway.ats.core.process.model.IProcessExecutor)

Example 3 with IProcessExecutor

use of com.axway.ats.core.process.model.IProcessExecutor in project ats-framework by Axway.

the class MobileDriver method killAdbServer.

/**
 * Kill misbehaving ADB server in order to bring it back later to normal state. The server is automatically started on next ADB command.
 * Then failed ADB operation (start/stop/clear cache, etc. should be retried.)
 */
private void killAdbServer() {
    log.info("Trying to restart ADB server on device: " + getDeviceDescription());
    String[] commandArguments = new String[] { "kill-server" };
    IProcessExecutor pe = null;
    try {
        pe = this.mobileDeviceUtils.executeAdbCommand(commandArguments, false);
    } catch (Exception e) {
        throw new MobileOperationException("Unable to stop ADB server. 'adb kill-server' failed", e);
    }
    if (pe.getExitCode() != 0) {
        log.warn("Unable to stop gracefully the ADB server. Command failed (Exit code: " + pe.getExitCode() + ", STDOUT: '" + pe.getStandardOutput() + "', STDERR: '" + pe.getErrorOutput() + "')");
        log.info("Trying to forcefully terminate ADB process");
        // fallback to taskkill
        try {
            if (OperatingSystemType.getCurrentOsType().isWindows()) {
                pe = new LocalProcessExecutor(HostUtils.LOCAL_HOST_NAME, "taskkill.exe", new String[] { "/IM", "adb.exe", "/F", "/T" });
            } else {
                pe = new LocalProcessExecutor(HostUtils.LOCAL_HOST_NAME, "killall", new String[] { "adb" });
            }
            pe.execute();
        } catch (Exception e) {
            log.info("Unable to kill ADB server. Command failed (Exit code: " + pe.getExitCode() + ", STDOUT: '" + pe.getStandardOutput() + "', STDERR: '" + pe.getErrorOutput() + "')");
            throw new MobileOperationException("Unable to stop ADB server with taskkill/killall", e);
        }
        if (pe.getExitCode() != 0) {
            // TODO - research possible error codes for non-existing process to kill
            log.error("Unable to kill ADB server. Command failed (Exit code: " + pe.getExitCode() + ", STDOUT: '" + pe.getStandardOutput() + "', STDERR: '" + pe.getErrorOutput() + "')");
        }
    }
}
Also used : MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) LocalProcessExecutor(com.axway.ats.core.process.LocalProcessExecutor) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) NotSupportedOperationException(com.axway.ats.uiengine.exceptions.NotSupportedOperationException) IProcessExecutor(com.axway.ats.core.process.model.IProcessExecutor)

Example 4 with IProcessExecutor

use of com.axway.ats.core.process.model.IProcessExecutor in project ats-framework by Axway.

the class RealHtmlFileBrowse method setValueUsingNativeDialog.

/**
 * This method allows you to type in dialog windows. This option is available only for Windows OS
 *
 * @param path add the location of the file, you want to type in the dialog window
 * @throws Exception
 */
@PublicAtsApi
public void setValueUsingNativeDialog(String path) throws Exception {
    if (!OperatingSystemType.getCurrentOsType().isWindows()) {
        throw new RuntimeException("This method is only available for Windows machines!");
    }
    // check if the file exist
    if (!new File(path).exists()) {
        throw new FileNotFoundException("File path \"" + path + "\" is wrong or does not exist!");
    }
    // ats_file_upload.exe location
    String uploadFileDestination = System.getProperty("user.dir") + "\\ats_file_upload.exe";
    // native window name
    String windowName;
    log.info("Using native " + path + " to work with native browser dialogs");
    // check if the ats_file_upload.exe file is already created
    if (!new File(uploadFileDestination).exists()) {
        OutputStream os = null;
        InputStream is = null;
        try {
            // get the ats_file_upload.exe file, located in the ats-uiengine.jar
            is = getClass().getClassLoader().getResourceAsStream("binaries/ats_file_upload.exe");
            if (is == null) {
                throw new FileNotFoundException("The 'ats_file_upload.exe' file is not found in ats-uiengine.jar!");
            }
            File uploadFile = new File(uploadFileDestination);
            os = new FileOutputStream(uploadFile);
            IOUtils.copy(is, os);
        } finally {
            IoUtils.closeStream(is);
            IoUtils.closeStream(os);
        }
    }
    if (webDriver instanceof FirefoxDriver) {
        windowName = " \"File Upload\" ";
    } else if (webDriver instanceof ChromeDriver) {
        windowName = " \"Open\" ";
    } else {
        throw new RobotException("Not Implemented for your browser! Currently Firefox and " + "Chrome are supported.");
    }
    // add the browse button properties
    ((AbstractRealBrowserDriver) super.getUiDriver()).getHtmlEngine().getElement(properties).click();
    // run the ats_file_upload.exe file
    IProcessExecutor proc = new LocalProcessExecutor(HostUtils.LOCAL_HOST_IPv4, uploadFileDestination + windowName + path);
    proc.execute();
    // check if there is any error, while executing the ats_file_upload.exe file
    if (proc.getExitCode() != 0) {
        log.error("AutoIT process for native browser interaction failed with exit code: " + proc.getExitCode() + ";");
        log.error("Output stream data: " + proc.getStandardOutput() + ";");
        log.error("Error stream data: " + proc.getErrorOutput());
        throw new RobotException("AutoIT process for native browser interaction failed.");
    }
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) RobotException(com.axway.ats.uiengine.exceptions.RobotException) AbstractRealBrowserDriver(com.axway.ats.uiengine.AbstractRealBrowserDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FileOutputStream(java.io.FileOutputStream) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) LocalProcessExecutor(com.axway.ats.core.process.LocalProcessExecutor) File(java.io.File) IProcessExecutor(com.axway.ats.core.process.model.IProcessExecutor) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 5 with IProcessExecutor

use of com.axway.ats.core.process.model.IProcessExecutor in project ats-framework by Axway.

the class MobileDeviceUtils method getMD5Sum.

/**
 * @param filePath file absolute path
 * <br>
 * <b>Note for iOS:</b> You can specify relative path too, by skipping the root slash '/' at the beginning
 *   and pass the path relative to the application data folder<br>
 * For example: <i>"Documents/MyAppFiles/IMG_0001.PNG"</i><br>
 * and we'll internally search for:
 *  <i>"/Users/&lt;username&gt;/Library/Developer/CoreSimulator/Devices/&lt;device_id&gt;/data/Containers/Data/Application/&lt;app_id&gt;/Documents/MyAppFiles/IMG_0001.PNG"</i><br>
 * which is the iOS Simulator application data folder path
 *
 * @return the MD5 sum of the specified file
 */
public String getMD5Sum(String filePath) {
    if (this.mobileDriver.isAndroidAgent()) {
        String[] commandArguments = new String[] { "shell", "md5", filePath };
        try {
            IProcessExecutor processExecutor = executeAdbCommand(commandArguments, true);
            String result = processExecutor.getStandardOutput();
            if (!StringUtils.isNullOrEmpty(result)) {
                result = result.trim();
                return result.substring(0, result.indexOf(' '));
            }
        } catch (Exception e) {
            throw new MobileOperationException("Unable to calculate md5 sum of file '" + filePath + "'", e);
        }
    } else {
        if (!filePath.startsWith("/")) {
            filePath = getiOSApplicationDataPath() + filePath;
        }
        return getFileSystemOperatoinsImpl().computeMd5Sum(filePath, Md5SumMode.BINARY);
    }
    return null;
}
Also used : MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) NotSupportedOperationException(com.axway.ats.uiengine.exceptions.NotSupportedOperationException) IProcessExecutor(com.axway.ats.core.process.model.IProcessExecutor)

Aggregations

IProcessExecutor (com.axway.ats.core.process.model.IProcessExecutor)11 MobileOperationException (com.axway.ats.uiengine.exceptions.MobileOperationException)9 NotSupportedOperationException (com.axway.ats.uiengine.exceptions.NotSupportedOperationException)9 PublicAtsApi (com.axway.ats.common.PublicAtsApi)3 LocalProcessExecutor (com.axway.ats.core.process.LocalProcessExecutor)2 IFileSystemOperations (com.axway.ats.core.filesystem.model.IFileSystemOperations)1 AbstractRealBrowserDriver (com.axway.ats.uiengine.AbstractRealBrowserDriver)1 RobotException (com.axway.ats.uiengine.exceptions.RobotException)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)1 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)1