Search in sources :

Example 1 with AbstractRealBrowserDriver

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

the class RealHtmlElementLocator method findElement.

public static WebElement findElement(UiElement uiElement, String xpathSuffix, boolean verbose) {
    AbstractRealBrowserDriver browserDriver = (AbstractRealBrowserDriver) uiElement.getUiDriver();
    WebDriver webDriver = (WebDriver) browserDriver.getInternalObject(InternalObjectsEnum.WebDriver.name());
    HtmlNavigator.getInstance().navigateToFrame(webDriver, uiElement);
    String xpath = uiElement.getElementProperties().getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR);
    String css = uiElement.getElementProperty("_css");
    if (xpathSuffix != null) {
        xpath += xpathSuffix;
    }
    List<WebElement> elements = null;
    if (!StringUtils.isNullOrEmpty(css)) {
        elements = webDriver.findElements(By.cssSelector(css));
    } else {
        elements = webDriver.findElements(By.xpath(xpath));
    }
    if (elements.size() == 0) {
        throw new ElementNotFoundException(uiElement.toString() + " not found.");
    } else if (elements.size() > 1) {
        if (verbose) {
            log.warn("More than one HTML elements were found having properties " + uiElement.toString() + ".Only the first HTML element will be used.");
        }
    }
    WebElement element = (WebElement) elements.get(0);
    if (verbose) {
        log.debug("Found element: " + element.toString());
    }
    return element;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) AbstractRealBrowserDriver(com.axway.ats.uiengine.AbstractRealBrowserDriver) ElementNotFoundException(com.axway.ats.uiengine.exceptions.ElementNotFoundException) WebElement(org.openqa.selenium.WebElement)

Example 2 with AbstractRealBrowserDriver

use of com.axway.ats.uiengine.AbstractRealBrowserDriver 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 3 with AbstractRealBrowserDriver

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

the class RealHtmlLink method doClick.

private void doClick() {
    new RealHtmlElementState(this).waitToBecomeExisting();
    RealHtmlElementLocator.findElement(this).click();
    UiEngineUtilities.sleep();
    ((AbstractRealBrowserDriver) super.getUiDriver()).handleExpectedPopups();
}
Also used : RealHtmlElementState(com.axway.ats.uiengine.utilities.realbrowser.html.RealHtmlElementState) AbstractRealBrowserDriver(com.axway.ats.uiengine.AbstractRealBrowserDriver)

Example 4 with AbstractRealBrowserDriver

use of com.axway.ats.uiengine.AbstractRealBrowserDriver 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)

Example 5 with AbstractRealBrowserDriver

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

the class AbstractHtmlEngine method goToPage.

/**
     * Navigate to another URL from within the same already started browser
     * @param url of the page to go
     */
@PublicAtsApi
public void goToPage(String url) {
    AbstractRealBrowserDriver abstractUiDriver = null;
    // only from the main window we have to go to another pages
    goToMainWindow();
    HtmlNavigator.getInstance().navigateToTopFrame(webDriver);
    log.info("Go to URL: " + url);
    try {
        webDriver.get(url);
        if (this.uiDriver instanceof AbstractRealBrowserDriver) {
            abstractUiDriver = (AbstractRealBrowserDriver) uiDriver;
            abstractUiDriver.handleExpectedPopups();
            abstractUiDriver.waitForPageLoaded(webDriver, UiEngineConfigurator.getInstance().getWaitPageToLoadTimeout());
        }
    } finally {
        if (abstractUiDriver != null)
            abstractUiDriver.clearExpectedPopups();
    }
}
Also used : AbstractRealBrowserDriver(com.axway.ats.uiengine.AbstractRealBrowserDriver) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

AbstractRealBrowserDriver (com.axway.ats.uiengine.AbstractRealBrowserDriver)7 PublicAtsApi (com.axway.ats.common.PublicAtsApi)3 WebDriver (org.openqa.selenium.WebDriver)3 RealHtmlElementState (com.axway.ats.uiengine.utilities.realbrowser.html.RealHtmlElementState)2 File (java.io.File)2 WebElement (org.openqa.selenium.WebElement)2 LocalFileSystemOperations (com.axway.ats.core.filesystem.LocalFileSystemOperations)1 LocalProcessExecutor (com.axway.ats.core.process.LocalProcessExecutor)1 IProcessExecutor (com.axway.ats.core.process.model.IProcessExecutor)1 MobileDriver (com.axway.ats.uiengine.MobileDriver)1 ElementNotFoundException (com.axway.ats.uiengine.exceptions.ElementNotFoundException)1 NotSupportedOperationException (com.axway.ats.uiengine.exceptions.NotSupportedOperationException)1 RobotException (com.axway.ats.uiengine.exceptions.RobotException)1 SeleniumOperationException (com.axway.ats.uiengine.exceptions.SeleniumOperationException)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ElementNotVisibleException (org.openqa.selenium.ElementNotVisibleException)1 TakesScreenshot (org.openqa.selenium.TakesScreenshot)1