Search in sources :

Example 1 with UiElement

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

the class UiEngineAspect method logAction.

@Before("(execution(* com.axway.ats.uiengine.elements.html.realbrowser..*.*(..)) " + "|| execution(* com.axway.ats.uiengine.elements.html.hiddenbrowser..*.*(..)) " + "|| execution(* com.axway.ats.uiengine.elements.mobile..*.*(..)) " + "|| execution(* com.axway.ats.uiengine.elements.swing..*.*(..)) " + ") && @annotation(com.axway.ats.common.PublicAtsApi)")
public void logAction(JoinPoint point) throws Throwable {
    // initialize logger
    Logger log = null;
    if (point.getThis() != null) {
        // not a static method
        log = Logger.getLogger(point.getThis().getClass());
    } else {
        // in case of MobileButton.click() this method will return MobileElement.class, but not MobileButton.class
        // that is why it is better to use point.getThis().getClass(), but if the method is static point.getThis() is null
        log = Logger.getLogger(point.getSignature().getDeclaringType());
    }
    String methodName = point.getSignature().getName();
    String propertiesString = " ";
    if (point.getThis() != null) {
        // not a static method
        UiElementProperties properties = ((UiElement) point.getThis()).getElementProperties();
        if (properties != null) {
            if (properties.containsInternalProperty(UiElementProperties.MAP_ID_INTERNAL_PARAM)) {
                propertiesString = properties.getInternalProperty(UiElementProperties.MAP_ID_INTERNAL_PARAM);
            } else {
                // get the properties in the form '{key1=value1, key2=value2}'
                propertiesString = properties.toString();
                // remove the leading and trailing brackets
                propertiesString = propertiesString.substring(1);
                propertiesString = propertiesString.substring(0, propertiesString.length() - 1);
            }
        }
    }
    StringBuilder message = new StringBuilder();
    Object[] args = point.getArgs();
    if (args.length > 0) {
        message.append(methodName + "( ");
        for (Object o : args) {
            if (o instanceof String) {
                message.append("\"" + o + "\" ,");
            } else if (o != null && o.getClass().isArray()) {
                if (o instanceof Object[]) {
                    message.append(Arrays.asList((Object[]) o) + " ,");
                } else {
                    message.append("[");
                    int length = Array.getLength(o);
                    for (int i = 0; i < length; i++) {
                        message.append(Array.get(o, i) + " ,");
                    }
                    message.delete(message.length() - 2, message.length());
                    message.append("]  ");
                }
            } else {
                message.append(o + " ,");
            }
        }
        message.deleteCharAt(message.length() - 1);
        message.append(") ");
        if (point.getThis() != null) {
            if (propertiesString.trim().isEmpty()) {
                message.insert(0, "[  ].");
            } else {
                message.insert(0, "[ \"" + propertiesString + "\" ].");
            }
        }
    } else if (point.getThis() == null) {
        // a static method
        message.insert(message.length(), "()");
    } else if (propertiesString.trim().isEmpty()) {
        message.insert(0, "[  ]." + methodName);
    } else {
        message.insert(0, "[ \"" + propertiesString + "\" ]." + methodName);
        message.insert(message.length(), "()");
    }
    log.info(message);
}
Also used : UiElement(com.axway.ats.uiengine.elements.UiElement) UiElementProperties(com.axway.ats.uiengine.elements.UiElementProperties) Logger(org.apache.log4j.Logger) Before(org.aspectj.lang.annotation.Before)

Aggregations

UiElement (com.axway.ats.uiengine.elements.UiElement)1 UiElementProperties (com.axway.ats.uiengine.elements.UiElementProperties)1 Logger (org.apache.log4j.Logger)1 Before (org.aspectj.lang.annotation.Before)1