Search in sources :

Example 16 with MobileOperationException

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

the class MobileDeviceUtils method executeAdbCommand.

public IProcessExecutor executeAdbCommand(String[] commandArguments, boolean verifyExitCode) {
    IProcessExecutor pe = null;
    try {
        if (getSystemOperationsImpl().getOperatingSystemType().isWindows()) {
            pe = getProcessExecutorImpl(this.mobileDriver.getAdbLocation() + "adb.exe", commandArguments);
        } else {
            pe = getProcessExecutorImpl(this.mobileDriver.getAdbLocation() + "adb", commandArguments);
        }
        pe.setWorkDirectory(this.mobileDriver.getAdbLocation());
        pe.execute();
        if (verifyExitCode && pe.getExitCode() != 0) {
            throw new MobileOperationException("Adb command failed (STDOUT: '" + pe.getStandardOutput() + "', STDERR: '" + pe.getErrorOutput() + "')");
        }
    } catch (Exception e) {
        throw new MobileOperationException("Adb command failed", e);
    }
    return pe;
}
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 17 with MobileOperationException

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

the class MobileDeviceUtils method listFiles.

/**
    *
    * @param path a path on the mobile device. It can be a directory or file (if you want to check
    * for specific file existence)
    * <br/>
    * <b>Note for iOS:</b> You have to specify a relative path to the application data folder<br/>
    * For example: <i>"Documents/MyAppFiles"</i><br/>
    * and we'll internally search for files in:
    *  <i>"/Users/&lt;username&gt;/Library/Developer/CoreSimulator/Devices/&lt;device_id&gt;/data/Containers/Data/Application/&lt;app_id&gt;/Documents/MyAppFiles/"</i><br/>
    * which is the iOS Simulator application data folder path
    *
    * @return {@link FileInfo} array with all the files and folders from the target path
    */
public FileInfo[] listFiles(String path) {
    List<FileInfo> files = new ArrayList<FileInfo>();
    if (this.mobileDriver.isAndroidAgent()) {
        String[] commandArguments = new String[] { "shell", "ls", "-lan", path };
        try {
            IProcessExecutor processExecutor = executeAdbCommand(commandArguments, true);
            String result = processExecutor.getStandardOutput();
            if (!StringUtils.isNullOrEmpty(result)) {
                String[] lines = result.split("[\r\n]+");
                for (String line : lines) {
                    Matcher m = LS_ENTRY_PATTERN.matcher(line);
                    if (m.matches()) {
                        /*
                             * group 1 -> file size
                             * group 2 -> modification date and time
                             * group 3 -> file name
                             */
                        String fileName = m.group(3);
                        String absolutePath = new String(IoUtils.normalizeUnixDir(path) + fileName).replace("//", "/");
                        if (line.startsWith("l") && line.contains("->")) {
                            // a link
                            // after '->'
                            absolutePath = fileName.substring(fileName.lastIndexOf("->") + 2).trim();
                            // before '->'
                            fileName = fileName.substring(0, fileName.indexOf("->")).trim();
                        }
                        String fileSize = m.group(1);
                        FileInfo file = new FileInfo(fileName, absolutePath, line.startsWith("d") || fileSize.isEmpty());
                        if (!fileSize.isEmpty()) {
                            file.setSize(Long.parseLong(fileSize));
                        }
                        file.setModificationDate(LS_DATE_FORMAT.parse(m.group(2)));
                        files.add(file);
                    }
                }
            }
        } catch (Exception e) {
            throw new MobileOperationException("Unable to list files for path '" + path + "'", e);
        }
    } else {
        // iOS case supposed
        IFileSystemOperations fileSystemOperations = getFileSystemOperatoinsImpl();
        String[] filePaths = fileSystemOperations.findFiles(getiOSApplicationDataPath() + path, ".*", true, true, false);
        for (String filePath : filePaths) {
            boolean isDirectory = filePath.endsWith("/");
            if (isDirectory) {
                filePath = filePath.substring(0, filePath.length() - 1);
            }
            String fileName = filePath.substring(filePath.lastIndexOf('/') + 1);
            FileInfo file = new FileInfo(fileName, filePath, isDirectory);
            file.setSize(fileSystemOperations.getFileSize(filePath));
            files.add(file);
        }
    }
    return files.toArray(new FileInfo[files.size()]);
}
Also used : Matcher(java.util.regex.Matcher) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) ArrayList(java.util.ArrayList) IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) NotSupportedOperationException(com.axway.ats.uiengine.exceptions.NotSupportedOperationException) IProcessExecutor(com.axway.ats.core.process.model.IProcessExecutor)

Example 18 with MobileOperationException

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

the class MobileElementState method focus.

/**
     * Moves the focus to the specified element. Currently issued with tap
     */
@PublicAtsApi
public void focus() {
    try {
        MobileElement mobileElement = (MobileElement) MobileElementFinder.findElement(appiumDriver, element);
        mobileElement.tap(1, 100);
    } catch (Exception se) {
        throw new MobileOperationException("Error trying to set the focus to " + getElementDescription(), se);
    }
}
Also used : MobileElement(io.appium.java_client.MobileElement) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) UnreachableBrowserException(org.openqa.selenium.remote.UnreachableBrowserException) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) VerificationException(com.axway.ats.uiengine.exceptions.VerificationException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

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