Search in sources :

Example 31 with PublicAtsApi

use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.

the class AbstractHtmlEngine method reloadFrames.

@PublicAtsApi
public void reloadFrames() {
    // real browsers reloads the frames automatically
    if (webDriver instanceof HtmlUnitDriver) {
        Field webClientField = null;
        boolean fieldAccessibleState = false;
        try {
            // Retrieve current WebClient instance (with the current page) from the Selenium WebDriver
            TargetLocator targetLocator = webDriver.switchTo();
            webClientField = targetLocator.getClass().getDeclaringClass().getDeclaredField("webClient");
            fieldAccessibleState = webClientField.isAccessible();
            webClientField.setAccessible(true);
            WebClient webClient = (WebClient) webClientField.get(targetLocator.defaultContent());
            HtmlPage page = (HtmlPage) webClient.getCurrentWindow().getEnclosedPage();
            for (final FrameWindow frameWindow : page.getFrames()) {
                final BaseFrameElement frame = frameWindow.getFrameElement();
                // use == and not equals(...) to identify initial content (versus URL set to "about:blank")
                if (frame.getEnclosedPage().getWebResponse().getWebRequest().getUrl() == WebClient.URL_ABOUT_BLANK) {
                    String src = frame.getSrcAttribute();
                    if (src != null && !src.isEmpty()) {
                        final URL url;
                        try {
                            url = ((HtmlPage) frame.getEnclosedPage()).getFullyQualifiedUrl(src);
                        } catch (final MalformedURLException e) {
                            String message = "Invalid src attribute of " + frame.getTagName() + ": url=[" + src + "]. Ignored.";
                            final IncorrectnessListener incorrectnessListener = webClient.getIncorrectnessListener();
                            incorrectnessListener.notify(message, this);
                            return;
                        }
                        if (isAlreadyLoadedByAncestor(url, ((HtmlPage) frame.getEnclosedPage()))) {
                            String message = "Recursive src attribute of " + frame.getTagName() + ": url=[" + src + "]. Ignored.";
                            final IncorrectnessListener incorrectnessListener = webClient.getIncorrectnessListener();
                            incorrectnessListener.notify(message, this);
                            log.info("Frame already loaded: " + frame.toString());
                            return;
                        }
                        try {
                            final WebRequest request = new WebRequest(url);
                            request.setAdditionalHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9, text/*;q=0.7, */*;q=0.5");
                            if (frameWindow.getName() == null || frameWindow.getName().isEmpty()) {
                                frameWindow.setName("frame_" + page.getFrames().indexOf(frameWindow));
                            }
                            webClient.loadWebResponseInto(webClient.loadWebResponse(request), frameWindow);
                            log.info("Frame loaded: " + frame.toString());
                        } catch (IOException e) {
                            log.error("Error when getting content for " + frame.getTagName() + " with src=" + url, e);
                        }
                    }
                } else {
                    log.info("Frame already loaded: " + frame.toString());
                }
            }
        } catch (Exception e) {
            throw new SeleniumOperationException("Error retrieving internal Selenium web client", e);
        } finally {
            if (webClientField != null) {
                webClientField.setAccessible(fieldAccessibleState);
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) BaseFrameElement(com.gargoylesoftware.htmlunit.html.BaseFrameElement) IOException(java.io.IOException) FrameWindow(com.gargoylesoftware.htmlunit.html.FrameWindow) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) WebClient(com.gargoylesoftware.htmlunit.WebClient) IncorrectnessListener(com.gargoylesoftware.htmlunit.IncorrectnessListener) URL(java.net.URL) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) Field(java.lang.reflect.Field) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) TargetLocator(org.openqa.selenium.WebDriver.TargetLocator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 32 with PublicAtsApi

use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.

the class RealHtmlElementState method focus.

/**
     * Moves the focus to the specified element.
     * <b>Note:</b> This is somewhat breakable as
     * the browser window needs to be the active system window, otherwise the keyboard
     * events will go to another application.
     */
@PublicAtsApi
public void focus() {
    // retrieve browser focus
    webDriver.switchTo().window(webDriver.getWindowHandle());
    // now focus the target element
    WebElement webElement = RealHtmlElementLocator.findElement(element);
    if ("input".equals(webElement.getTagName())) {
        webElement.sendKeys("");
    } else {
        new Actions(webDriver).moveToElement(webElement).perform();
    }
}
Also used : Actions(org.openqa.selenium.interactions.Actions) WebElement(org.openqa.selenium.WebElement) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 33 with PublicAtsApi

use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.

the class AbstractHtmlEngine method setCookie.

/**
     *
     * @param name the name of the cookie. May not be null or an empty string.
     * @param value the cookie value. May not be null.
     * @param domain the domain the cookie is visible to.
     * @param path the path the cookie is visible to. If left blank or set to null, will be set to
     *        "/".
     * @param expiry the cookie's expiration date; may be null.
     * @param isSecure whether this cookie requires a secure connection.
     */
@PublicAtsApi
public void setCookie(String name, String value, String domain, String path, Date expiry, boolean isSecure) {
    Cookie cookie = new Cookie(name, value, domain, path, expiry, isSecure);
    webDriver.manage().addCookie(cookie);
}
Also used : Cookie(org.openqa.selenium.Cookie) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 34 with PublicAtsApi

use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.

the class SwingEngine method goToContainer.

/**
     * Set active container under the <strong>current</strong> window
     *
     * @param containerMapId container element mapId. The element requires 'name' or 'title' property.
     * @throws ElementNotFoundException if the container element is not found
     */
@PublicAtsApi
public void goToContainer(String containerMapId) {
    UiElementProperties containerProperties = ElementsMap.getInstance().getElementProperties(containerMapId);
    goToContainer(containerProperties);
}
Also used : UiElementProperties(com.axway.ats.uiengine.elements.UiElementProperties) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 35 with PublicAtsApi

use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.

the class SwingTable method clickHeader.

/**
     * Click table header by column index
     *
     * @param columnIndex the column index
     * @throws VerificationException if the table element doesn't exist
     */
@PublicAtsApi
public void clickHeader(int columnIndex) {
    new SwingElementState(this).waitToBecomeExisting();
    JTableFixture tableFixture = (JTableFixture) SwingElementLocator.findFixture(this);
    JTableHeaderFixture tableHeaderFixture = tableFixture.tableHeader();
    try {
        tableHeaderFixture.clickColumn(columnIndex);
    } catch (Exception e) {
        throw new UiElementException(e.getMessage(), this);
    }
}
Also used : JTableFixture(org.fest.swing.fixture.JTableFixture) SwingElementState(com.axway.ats.uiengine.utilities.swing.SwingElementState) UiElementException(com.axway.ats.uiengine.exceptions.UiElementException) JTableHeaderFixture(org.fest.swing.fixture.JTableHeaderFixture) VerifyNotEqualityException(com.axway.ats.uiengine.exceptions.VerifyNotEqualityException) VerifyEqualityException(com.axway.ats.uiengine.exceptions.VerifyEqualityException) VerificationException(com.axway.ats.uiengine.exceptions.VerificationException) UiElementException(com.axway.ats.uiengine.exceptions.UiElementException) NotSupportedOperationException(com.axway.ats.uiengine.exceptions.NotSupportedOperationException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

PublicAtsApi (com.axway.ats.common.PublicAtsApi)409 Validator (com.axway.ats.core.validation.Validator)66 SwingElementState (com.axway.ats.uiengine.utilities.swing.SwingElementState)60 WebElement (org.openqa.selenium.WebElement)57 IFileSystemOperations (com.axway.ats.core.filesystem.model.IFileSystemOperations)44 HiddenHtmlElementState (com.axway.ats.uiengine.utilities.hiddenbrowser.HiddenHtmlElementState)32 NoSuchMimePackageException (com.axway.ats.action.objects.model.NoSuchMimePackageException)31 PackageException (com.axway.ats.action.objects.model.PackageException)31 RealHtmlElementState (com.axway.ats.uiengine.utilities.realbrowser.html.RealHtmlElementState)31 MessagingException (javax.mail.MessagingException)31 VerificationException (com.axway.ats.uiengine.exceptions.VerificationException)24 ArrayList (java.util.ArrayList)18 SeleniumOperationException (com.axway.ats.uiengine.exceptions.SeleniumOperationException)16 UiElementException (com.axway.ats.uiengine.exceptions.UiElementException)16 IOException (java.io.IOException)16 JTableFixture (org.fest.swing.fixture.JTableFixture)16 Actions (org.openqa.selenium.interactions.Actions)16 NotSupportedOperationException (com.axway.ats.uiengine.exceptions.NotSupportedOperationException)15 VerifyNotEqualityException (com.axway.ats.uiengine.exceptions.VerifyNotEqualityException)15 XMLException (com.axway.ats.common.xml.XMLException)14