Search in sources :

Example 26 with HiddenHtmlElementState

use of com.axway.ats.uiengine.utilities.hiddenbrowser.HiddenHtmlElementState in project ats-framework by Axway.

the class HiddenHtmlTable method getAllValues.

/**
     * Get the values of all table cells.</br>
     * 
     * <b>Note:</b> If a table cell contains a checkbox - we will return 'checked' or 'notchecked' value.
     * 
     * @return a two dimensional array containing all table cell values
     */
@PublicAtsApi
public String[][] getAllValues() {
    new HiddenHtmlElementState(this).waitToBecomeExisting();
    WebElement table = HiddenHtmlElementLocator.findElement(this);
    String scriptForHtml = generateScriptForGettingTableContent(".innerHTML");
    Object returnedHtmlValue = ((JavascriptExecutor) webDriver).executeScript(scriptForHtml, table);
    String scriptForObjects = generateScriptForGettingTableContent("");
    Object returnedObjectsValue = ((JavascriptExecutor) webDriver).executeScript(scriptForObjects, table);
    String[][] tableData = null;
    if (returnedHtmlValue != null && returnedHtmlValue instanceof List && returnedObjectsValue != null && returnedObjectsValue instanceof List) {
        List<?> htmlTable = (List<?>) returnedHtmlValue;
        List<?> objectsTable = (List<?>) returnedObjectsValue;
        // allocate space for a number of rows
        tableData = new String[htmlTable.size()][];
        for (int iRow = 0; iRow < htmlTable.size(); iRow++) {
            if (htmlTable.get(iRow) instanceof List) {
                List<?> htmlRow = (List<?>) htmlTable.get(iRow);
                List<?> objectsRow = (List<?>) objectsTable.get(iRow);
                // allocate space for the cells of the current row
                tableData[iRow] = new String[htmlRow.size()];
                for (int iColumn = 0; iColumn < htmlRow.size(); iColumn++) {
                    Object htmlWebElement = htmlRow.get(iColumn);
                    Object objectWebElement = objectsRow.get(iColumn);
                    // some data cannot be presented in textual way - for example a checkbox 
                    String htmlValueString = htmlWebElement.toString().toLowerCase().replace("\r", "").replace("\n", "");
                    if (htmlValueString.matches(".*<input.*type=.*[\"|']checkbox[\"|'].*>.*")) {
                        // We assume this is a checkbox inside a table cell.
                        // We will return either 'checked' or 'notchecked'
                        tableData[iRow][iColumn] = htmlValueString.contains("checked") ? "checked" : "notchecked";
                    } else if (objectWebElement instanceof WebElement) {
                        // proceed in the regular way by returning the data visible to the user
                        tableData[iRow][iColumn] = ((WebElement) objectWebElement).getText().trim();
                    } else {
                        tableData[iRow][iColumn] = null;
                    }
                }
            }
        }
    } else {
        log.warn("We could not get the content of table declared as: " + this.toString());
    }
    return tableData;
}
Also used : HiddenHtmlElementState(com.axway.ats.uiengine.utilities.hiddenbrowser.HiddenHtmlElementState) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) List(java.util.List) WebElement(org.openqa.selenium.WebElement) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 27 with HiddenHtmlElementState

use of com.axway.ats.uiengine.utilities.hiddenbrowser.HiddenHtmlElementState in project ats-framework by Axway.

the class HiddenHtmlTable method getColumnCount.

/**
     * @return how many columns this table has
     */
@PublicAtsApi
public int getColumnCount() {
    new HiddenHtmlElementState(this).waitToBecomeExisting();
    String css = this.getElementProperty("_css");
    try {
        if (!StringUtils.isNullOrEmpty(css)) {
            StringBuilder sb = new StringBuilder(css);
            sb.append(" tr:nth-child(1) td");
            int count = webDriver.findElements(By.cssSelector(sb.toString())).size();
            sb = new StringBuilder(css);
            sb.append(" tr:nth-child(1) th");
            count += webDriver.findElements(By.cssSelector(sb.toString())).size();
            return count;
        } else {
            // get elements matching the following xpath
            return this.webDriver.findElements(By.xpath("(" + properties.getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR) + "//tr[th or td])[1]/*")).size();
        }
    } catch (Exception e) {
        throw new SeleniumOperationException(this, "getColumnsCount", e);
    }
}
Also used : HiddenHtmlElementState(com.axway.ats.uiengine.utilities.hiddenbrowser.HiddenHtmlElementState) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) VerifyNotEqualityException(com.axway.ats.uiengine.exceptions.VerifyNotEqualityException) VerifyEqualityException(com.axway.ats.uiengine.exceptions.VerifyEqualityException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 28 with HiddenHtmlElementState

use of com.axway.ats.uiengine.utilities.hiddenbrowser.HiddenHtmlElementState in project ats-framework by Axway.

the class HiddenHtmlTable method getFieldValue.

/**
     * Get the value of the specified table field
     *
     * @param row the field row starting at 0
     * @param column the field column starting at 0
     * @return the value
     */
@Override
@PublicAtsApi
public String getFieldValue(int row, int column) {
    new HiddenHtmlElementState(this).waitToBecomeExisting();
    WebElement table = HiddenHtmlElementLocator.findElement(this);
    String script = "var table = arguments[0]; var row = arguments[1]; var col = arguments[2];" + "if (row > table.rows.length) { return \"Cannot access row \" + row + \" - table has \" + table.rows.length + \" rows\"; }" + "if (col > table.rows[row].cells.length) { return \"Cannot access column \" + col + \" - table row has \" + table.rows[row].cells.length + \" columns\"; }" + "return table.rows[row].cells[col];";
    JavascriptExecutor jsExecutor = (JavascriptExecutor) webDriver;
    Object value = jsExecutor.executeScript(script, table, row, column);
    if (value instanceof WebElement) {
        return ((WebElement) value).getText().trim();
    }
    return null;
}
Also used : HiddenHtmlElementState(com.axway.ats.uiengine.utilities.hiddenbrowser.HiddenHtmlElementState) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) WebElement(org.openqa.selenium.WebElement) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 29 with HiddenHtmlElementState

use of com.axway.ats.uiengine.utilities.hiddenbrowser.HiddenHtmlElementState in project ats-framework by Axway.

the class HiddenHtmlTable method getRowCount.

/**
     * @return how many rows this table has
     */
@Override
@PublicAtsApi
public int getRowCount() {
    new HiddenHtmlElementState(this).waitToBecomeExisting();
    String css = this.getElementProperty("_css");
    List<WebElement> elements = null;
    if (!StringUtils.isNullOrEmpty(css)) {
        css += " tr";
        elements = webDriver.findElements(By.cssSelector(css));
    } else {
        // get elements matching the following xpath
        elements = webDriver.findElements(By.xpath(properties.getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR) + "/tr | " + properties.getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR) + "/*/tr"));
    }
    return elements.size();
}
Also used : HiddenHtmlElementState(com.axway.ats.uiengine.utilities.hiddenbrowser.HiddenHtmlElementState) WebElement(org.openqa.selenium.WebElement) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 30 with HiddenHtmlElementState

use of com.axway.ats.uiengine.utilities.hiddenbrowser.HiddenHtmlElementState in project ats-framework by Axway.

the class HiddenHtmlTable method setFieldValue.

/**
     * Set value of specified table field
     *
     * @param value the new table cell value
     * @param row the field row starting at 0
     * @param column the field column starting at 0
     */
@Override
@PublicAtsApi
public void setFieldValue(String value, int row, int column) {
    new HiddenHtmlElementState(this).waitToBecomeExisting();
    WebElement table = HiddenHtmlElementLocator.findElement(this);
    String script = "var table = arguments[0]; var row = arguments[1]; var col = arguments[2];" + "if (row > table.rows.length) { return \"Cannot access row \" + row + \" - table has \" + table.rows.length + \" rows\"; }" + "if (col > table.rows[row].cells.length) { return \"Cannot access column \" + col + \" - table row has \" + table.rows[row].cells.length + \" columns\"; }" + "table.rows[row].cells[col].textContent = '" + value + "';";
    ((JavascriptExecutor) webDriver).executeScript(script, table, row, column);
}
Also used : HiddenHtmlElementState(com.axway.ats.uiengine.utilities.hiddenbrowser.HiddenHtmlElementState) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) WebElement(org.openqa.selenium.WebElement) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

PublicAtsApi (com.axway.ats.common.PublicAtsApi)32 HiddenHtmlElementState (com.axway.ats.uiengine.utilities.hiddenbrowser.HiddenHtmlElementState)32 WebElement (org.openqa.selenium.WebElement)19 HtmlUnitWebElement (org.openqa.selenium.htmlunit.HtmlUnitWebElement)12 Actions (org.openqa.selenium.interactions.Actions)9 SeleniumOperationException (com.axway.ats.uiengine.exceptions.SeleniumOperationException)7 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)3 UiElementProperties (com.axway.ats.uiengine.elements.UiElementProperties)2 ArrayList (java.util.ArrayList)2 VerifyEqualityException (com.axway.ats.uiengine.exceptions.VerifyEqualityException)1 VerifyNotEqualityException (com.axway.ats.uiengine.exceptions.VerifyNotEqualityException)1 List (java.util.List)1 Action (org.openqa.selenium.interactions.Action)1