Search in sources :

Example 1 with NotSupportedOperationException

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

the class SwingTable method setFieldValue.

/**
 * Set table field value
 *
 * @param value the value to set
 * @param row the row number
 * @param column the column number
 * @throws VerificationException if the element doesn't exist
 */
@Override
@PublicAtsApi
public void setFieldValue(String value, int row, int column) {
    new SwingElementState(this).waitToBecomeExisting();
    JTableFixture tableFixture = (JTableFixture) SwingElementLocator.findFixture(this);
    try {
        TableCell tableCell = new TableCell(row, column) {
        };
        // if the cell coordinates are wrong, the exception will be thrown
        tableFixture.selectCell(tableCell);
        if (tableFixture.component().isCellEditable(row, column)) {
            tableFixture.enterValue(tableCell, value);
        } else {
            throw new NotSupportedOperationException("The table cell [" + row + "," + column + "] is not editable. " + toString());
        }
    } catch (IndexOutOfBoundsException ioobe) {
        throw new UiElementException(ioobe.getMessage(), this);
    }
}
Also used : JTableFixture(org.fest.swing.fixture.JTableFixture) TableCell(org.fest.swing.data.TableCell) SwingElementState(com.axway.ats.uiengine.utilities.swing.SwingElementState) UiElementException(com.axway.ats.uiengine.exceptions.UiElementException) NotSupportedOperationException(com.axway.ats.uiengine.exceptions.NotSupportedOperationException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 2 with NotSupportedOperationException

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

the class MobileDriver method clearAppCache.

/**
 * Clear application cache
 *
 * @param applicationPackage application package name
 */
@PublicAtsApi
public void clearAppCache(String applicationPackage) {
    if (isAndroidAgent) {
        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");
        }
        String[] commandArguments = new String[] { "shell", "pm", "clear", applicationPackage };
        IProcessExecutor pe = null;
        int numRetries = 0;
        while (numRetries <= MAX_ADB_RELATED_RETRIES) {
            if (numRetries > 0) {
                log.warn("Retrying to start application action as previous try failed");
            }
            try {
                pe = this.mobileDeviceUtils.executeAdbCommand(commandArguments, false);
            } catch (Exception e) {
                throw new MobileOperationException("Unable to clear application cache of '" + applicationPackage + "'", e);
            }
            numRetries++;
            if (pe.getExitCode() == 0) {
                break;
            } else {
                if (numRetries <= MAX_ADB_RELATED_RETRIES) {
                    log.error("Unable to clear application cache of '" + applicationPackage + "'. 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 clear application cache of '" + applicationPackage + "'. Clear cache command failed (Exit code: " + pe.getExitCode() + ", STDOUT: '" + pe.getStandardOutput() + "', STDERR: '" + pe.getErrorOutput() + "')");
                }
            }
        }
    } else {
        // TODO: Find solution. Note that "this.driver.resetApp();" doesn't reset app cache.
        throw new NotSupportedOperationException("Currently clear application cache operation for iOS is not implemented. Hint: check with resetApp");
    }
}
Also used : MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) NotSupportedOperationException(com.axway.ats.uiengine.exceptions.NotSupportedOperationException) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) NotSupportedOperationException(com.axway.ats.uiengine.exceptions.NotSupportedOperationException) IProcessExecutor(com.axway.ats.core.process.model.IProcessExecutor) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 3 with NotSupportedOperationException

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

the class UiEngineUtilities method createScreenshot.

/**
 * Create a screenshot image (supported image format/type is PNG).<br>
 * If the screenshot image file already exists it will be automatically replaced by the new one.<br>
 * <br>
 * Currently the supported UI drivers are {@link AbstractRealBrowserDriver} and {@link MobileDriver}:
 * <ul>
 *     <li>{@link AbstractRealBrowserDriver} - the method makes a best effort to create a screenshot,
 *     depending on the browser to return the following in order of preference:
 *          <ul>
 *              <li>Entire page</li>
 *              <li>Current window</li>
 *              <li>Visible portion of the current frame</li>
 *              <li>The screenshot of the entire display containing the browser</li>
 *          </ul>
 *     </li>
 *     <li>{@link MobileDriver} - creates a screenshot of the mobile device screen.<br>
 *          <b>NOTE:</b> There is a <a href="https://github.com/selendroid/selendroid/issues/325">known issue</a> on Android Virtual Device with <b>"Use Host GPU"</b> enabled option.
 *          So in order to get a screenshot it should be disabled. Keep in mind that it will affect the performance, because
 *          it is a performance acceleration option.
 *     </li>
 * </ul>
 *
 * @param filePath the screenshot image file path
 * @param uiDriver {@link UiDriver} instance
 */
@PublicAtsApi
public static void createScreenshot(String filePath, UiDriver uiDriver) {
    WebDriver webDriver = null;
    if (uiDriver instanceof AbstractRealBrowserDriver) {
        AbstractRealBrowserDriver browserDriver = (AbstractRealBrowserDriver) uiDriver;
        webDriver = (WebDriver) browserDriver.getInternalObject(InternalObjectsEnum.WebDriver.toString());
    } else if (uiDriver instanceof MobileDriver) {
        MobileDriver mobileDriver = (MobileDriver) uiDriver;
        webDriver = (WebDriver) mobileDriver.getInternalObject(InternalObjectsEnum.WebDriver.toString());
        ((AppiumDriver) webDriver).context(MobileDriver.NATIVE_CONTEXT);
    } else {
        throw new NotSupportedOperationException("Currently it is not possible to create a screenshot with driver: " + uiDriver.getClass().getSimpleName());
    }
    File scrTmpFile = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
    File scrFile = new File(filePath);
    if (scrFile.exists() && !scrFile.delete()) {
        log.warn("The Screenshot image file '" + filePath + "' already exists, but couldn't be deleted. You can find the current Screenshot image here: " + scrTmpFile.getAbsolutePath());
    } else if (!scrTmpFile.renameTo(scrFile)) {
        // if renameTo() fails we will try to copy the file
        try {
            new LocalFileSystemOperations().copyFile(scrTmpFile.getCanonicalPath(), scrFile.getCanonicalPath(), true);
            scrTmpFile.delete();
        } catch (Exception e) {
            log.warn("Unable to create Screenshot image file: " + filePath);
        }
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) AbstractRealBrowserDriver(com.axway.ats.uiengine.AbstractRealBrowserDriver) LocalFileSystemOperations(com.axway.ats.core.filesystem.LocalFileSystemOperations) MobileDriver(com.axway.ats.uiengine.MobileDriver) NotSupportedOperationException(com.axway.ats.uiengine.exceptions.NotSupportedOperationException) File(java.io.File) NotSupportedOperationException(com.axway.ats.uiengine.exceptions.NotSupportedOperationException) TakesScreenshot(org.openqa.selenium.TakesScreenshot) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

PublicAtsApi (com.axway.ats.common.PublicAtsApi)3 NotSupportedOperationException (com.axway.ats.uiengine.exceptions.NotSupportedOperationException)3 LocalFileSystemOperations (com.axway.ats.core.filesystem.LocalFileSystemOperations)1 IProcessExecutor (com.axway.ats.core.process.model.IProcessExecutor)1 AbstractRealBrowserDriver (com.axway.ats.uiengine.AbstractRealBrowserDriver)1 MobileDriver (com.axway.ats.uiengine.MobileDriver)1 MobileOperationException (com.axway.ats.uiengine.exceptions.MobileOperationException)1 UiElementException (com.axway.ats.uiengine.exceptions.UiElementException)1 SwingElementState (com.axway.ats.uiengine.utilities.swing.SwingElementState)1 File (java.io.File)1 TableCell (org.fest.swing.data.TableCell)1 JTableFixture (org.fest.swing.fixture.JTableFixture)1 TakesScreenshot (org.openqa.selenium.TakesScreenshot)1 WebDriver (org.openqa.selenium.WebDriver)1