Search in sources :

Example 1 with MobileOperationException

use of com.axway.ats.uiengine.exceptions.MobileOperationException 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 MobileOperationException

use of com.axway.ats.uiengine.exceptions.MobileOperationException in project ats-framework by Axway.

the class MobileDriver method start.

/**
     * Start session to device and load the application <br/>
     * @param appPath the absolute path to the application:
     * <pre>
     *       <b>iOS</b>: absolute path to simulator-compiled .app file or the bundle_id of the desired target on device
     *       <b>Android</b>: absolute path to .apk file
     * </pre>
     */
@PublicAtsApi
public void start(String appPath) {
    log.info("Starting mobile testing session to device: " + getDeviceDescription());
    try {
        // http://appium.io/slate/en/master/?java#appium-server-capabilities
        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
        desiredCapabilities.setCapability("automationName", "Appium");
        if (isAndroidAgent) {
            if (this.adbLocation == null) {
                // try to set Android home and adb location from the ANDROID_HOME environment variable
                readAndroidHomeFromEnvironment();
                if (this.adbLocation == null) {
                    throw new MobileOperationException("You must specify a valid Android home location or define " + ANDROID_HOME_ENV_VAR + " environment variable. The ADB executable must be located in a 'platform-tools/' subfolder");
                }
            }
            desiredCapabilities.setCapability("platformName", "Android");
        } else {
            desiredCapabilities.setCapability("platformName", "iOS");
        }
        desiredCapabilities.setCapability("deviceName", deviceName);
        desiredCapabilities.setCapability("platformVersion", this.platformVersion);
        if (!StringUtils.isNullOrEmpty(this.udid)) {
            desiredCapabilities.setCapability("udid", this.udid);
        }
        desiredCapabilities.setCapability("app", appPath);
        desiredCapabilities.setCapability("autoLaunch", true);
        desiredCapabilities.setCapability("newCommandTimeout", 30 * 60);
        // don’t reset settings and app state before this session
        desiredCapabilities.setCapability("noReset", true);
        // desiredCapabilities.setCapability( "fullReset", true ); // clean all Android/iOS settings (iCloud settings), close and uninstall the app
        URL url = new URL("http://" + this.host + ":" + this.port + "/wd/hub");
        if (isAndroidAgent) {
            driver = new AndroidDriver<WebElement>(url, desiredCapabilities);
        } else {
            driver = new IOSDriver<WebElement>(url, desiredCapabilities);
        }
        driver.setLogLevel(Level.ALL);
        // the following timeout only works for NATIVE context, but we will handle it in MobileElementState.
        // Also there is a problem when != 0. In some reason, for iOS only(maybe), this timeout acts as session timeout ?!?
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS);
        // driver.manage().timeouts().pageLoadTimeout( 30000, TimeUnit.MILLISECONDS ); // UnsupportedCommandException
        // driver.manage().timeouts().setScriptTimeout( 10000, TimeUnit.MILLISECONDS ); // WebDriverException: Not yet implemented
        driver.context(NATIVE_CONTEXT);
        // must be called in NATIVE context
        this.screenDimensions = driver.manage().window().getSize();
        mobileEngine = new MobileEngine(this, this.mobileDeviceUtils);
    } catch (Exception e) {
        throw new MobileOperationException("Error starting connection to device and application under test." + " Check if there is connection to device and the Appium server is running.", e);
    }
}
Also used : DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) WebElement(org.openqa.selenium.WebElement) MobileEngine(com.axway.ats.uiengine.engine.MobileEngine) URL(java.net.URL) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) NotSupportedOperationException(com.axway.ats.uiengine.exceptions.NotSupportedOperationException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 3 with MobileOperationException

use of com.axway.ats.uiengine.exceptions.MobileOperationException 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 4 with MobileOperationException

use of com.axway.ats.uiengine.exceptions.MobileOperationException 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 5 with MobileOperationException

use of com.axway.ats.uiengine.exceptions.MobileOperationException 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

MobileOperationException (com.axway.ats.uiengine.exceptions.MobileOperationException)18 PublicAtsApi (com.axway.ats.common.PublicAtsApi)11 NotSupportedOperationException (com.axway.ats.uiengine.exceptions.NotSupportedOperationException)10 IProcessExecutor (com.axway.ats.core.process.model.IProcessExecutor)9 MobileElementState (com.axway.ats.uiengine.utilities.mobile.MobileElementState)7 VerificationException (com.axway.ats.uiengine.exceptions.VerificationException)6 WebElement (org.openqa.selenium.WebElement)6 VerifyEqualityException (com.axway.ats.uiengine.exceptions.VerifyEqualityException)2 VerifyNotEqualityException (com.axway.ats.uiengine.exceptions.VerifyNotEqualityException)2 AndroidDriver (io.appium.java_client.android.AndroidDriver)2 Actions (org.openqa.selenium.interactions.Actions)2 IFileSystemOperations (com.axway.ats.core.filesystem.model.IFileSystemOperations)1 LocalProcessExecutor (com.axway.ats.core.process.LocalProcessExecutor)1 MobileDriver (com.axway.ats.uiengine.MobileDriver)1 MobileEngine (com.axway.ats.uiengine.engine.MobileEngine)1 MobileElement (io.appium.java_client.MobileElement)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Dimension (org.openqa.selenium.Dimension)1