Search in sources :

Example 11 with PublicAtsApi

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

the class XmlText method getAttributes.

/**
     * @param xpath XPath , pointing to a XML element
     * @return a HashMap , containing the attributes and their values
     * @throws XMLException
     */
@PublicAtsApi
public Map<String, String> getAttributes(String xpath) throws XMLException {
    if (StringUtils.isNullOrEmpty(xpath)) {
        throw new XMLException("Null/empty xpath is not allowed.");
    }
    Element element = findElement(xpath);
    if (element == null) {
        throw new XMLException("'" + xpath + "' is not a valid path");
    }
    HashMap<String, String> attributes = new HashMap<>(1);
    Iterator<Attribute> it = element.attributeIterator();
    while (it.hasNext()) {
        Attribute attr = it.next();
        attributes.put(attr.getName(), attr.getValue());
    }
    return attributes;
}
Also used : XMLException(com.axway.ats.common.xml.XMLException) HashMap(java.util.HashMap) Attribute(org.dom4j.Attribute) Element(org.dom4j.Element) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 12 with PublicAtsApi

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

the class XmlText method setAttribute.

/**
     * Adds attribute to XML element.
     *
     * @param xpath XPath , pointing to a XML element
     * @param name the name of the attribute
     * @param value the value of the attribute
     * @return this instance
     * @throws XMLException
     */
@PublicAtsApi
public XmlText setAttribute(String xpath, String name, String value) throws XMLException {
    if (StringUtils.isNullOrEmpty(xpath)) {
        throw new XMLException("Null/empty xpath is not allowed.");
    }
    if (StringUtils.isNullOrEmpty(name)) {
        throw new XMLException("Null/empty attribute name is not allowed.");
    }
    if (StringUtils.isNullOrEmpty(value)) {
        throw new XMLException("Null/empty attribute value is not allowed.");
    }
    Element element = findElement(xpath);
    if (element == null) {
        throw new XMLException("'" + xpath + "' is not a valid path");
    }
    element.addAttribute(name, value);
    return this;
}
Also used : XMLException(com.axway.ats.common.xml.XMLException) Element(org.dom4j.Element) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 13 with PublicAtsApi

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

the class XmlText method getFloat.

/**
     * @param xpath XPath , pointing to a XML element
     * @return a float XML value
     * @throws XMLException
     */
@PublicAtsApi
public float getFloat(String xpath) throws XMLException {
    Object object = get(xpath);
    Element root = ((XmlText) object).root;
    if (root.isTextOnly()) {
        object = root.getText().trim();
    } else {
        object = "";
    }
    try {
        return Float.parseFloat(((String) object).trim());
    } catch (NumberFormatException nfe) {
        throw new XMLException("'" + xpath + "' does not point to a float value:\n" + object.toString());
    }
}
Also used : XMLException(com.axway.ats.common.xml.XMLException) Element(org.dom4j.Element) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 14 with PublicAtsApi

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

the class XmlText method getInt.

/**
     * @param xpath XPath , pointing to a XML element
     * @return an Integer XML value
     * @throws XMLException
     */
@PublicAtsApi
public int getInt(String xpath) throws XMLException {
    Object object = get(xpath);
    Element root = ((XmlText) object).root;
    if (root.isTextOnly()) {
        object = root.getText().trim();
    } else {
        object = "";
    }
    try {
        return Integer.parseInt(((String) object).trim());
    } catch (NumberFormatException nfe) {
        throw new XMLException("'" + xpath + "' does not point to an int value:\n" + object.toString());
    }
}
Also used : XMLException(com.axway.ats.common.xml.XMLException) Element(org.dom4j.Element) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 15 with PublicAtsApi

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

the class XmlText method appendText.

/**
     * Append text to a XML element.
     *
     * @param xpath XPath , pointing to a XML element
     * @param text the text , which will be appended to a XML element
     * @return this instance
     * @throws XMLException
     */
@PublicAtsApi
public XmlText appendText(String xpath, String text) throws XMLException {
    if (StringUtils.isNullOrEmpty(xpath)) {
        throw new XMLException("Null/empty xpath is not allowed.");
    }
    if (StringUtils.isNullOrEmpty(text)) {
        throw new XMLException("Null/empty text is not allowed.");
    }
    Element element = findElement(xpath);
    if (element == null) {
        throw new XMLException("'" + xpath + "' is not a valid path");
    }
    element.addText(text);
    return this;
}
Also used : XMLException(com.axway.ats.common.xml.XMLException) Element(org.dom4j.Element) 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