Search in sources :

Example 6 with Identifier

use of org.cerberus.engine.entity.Identifier in project cerberus-source by cerberustesting.

the class ActionService method doActionMouseLeftButtonRelease.

private MessageEvent doActionMouseLeftButtonRelease(TestCaseExecution tCExecution, String object, String property) {
    MessageEvent message;
    String element;
    try {
        /**
         * Get element to use String object if not empty, String property if
         * object empty, throws Exception if both empty)
         */
        element = getElementToUse(object, property, "mouseLeftButtonRelease", tCExecution);
        /**
         * Get Identifier (identifier, locator)
         */
        Identifier identifier = identifierService.convertStringToIdentifier(element);
        identifierService.checkWebElementIdentifier(identifier.getIdentifier());
        if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {
            return webdriverService.doSeleniumActionMouseUp(tCExecution.getSession(), identifier);
        }
        message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
        message.setDescription(message.getDescription().replace("%ACTION%", "MouseUp"));
        message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
        return message;
    } catch (CerberusEventException ex) {
        LOG.fatal("Error doing Action MouseUp :" + ex);
        return ex.getMessageError();
    }
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent)

Example 7 with Identifier

use of org.cerberus.engine.entity.Identifier in project cerberus-source by cerberustesting.

the class ControlService method VerifyRegexInElement.

private MessageEvent VerifyRegexInElement(TestCaseExecution tCExecution, String path, String regex) {
    LOG.debug("Control : verifyRegexInElement on : " + path + " element against value : " + regex);
    MessageEvent mes;
    String pathContent = null;
    try {
        Identifier identifier = identifierService.convertStringToIdentifier(path);
        String applicationType = tCExecution.getApplicationObj().getType();
        // Get value from the path element according to the application type
        if (Application.TYPE_GUI.equalsIgnoreCase(applicationType) || Application.TYPE_APK.equalsIgnoreCase(applicationType) || Application.TYPE_IPA.equalsIgnoreCase(applicationType)) {
            pathContent = this.webdriverService.getValueFromHTML(tCExecution.getSession(), identifier);
        } else if (Application.TYPE_SRV.equalsIgnoreCase(applicationType)) {
            if (tCExecution.getLastServiceCalled() != null) {
                String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();
                switch(tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {
                    case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:
                        if (!xmlUnitService.isElementPresent(responseBody, path)) {
                            mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINELEMENT_NO_SUCH_ELEMENT);
                            mes.setDescription(mes.getDescription().replace("%ELEMENT%", path));
                            return mes;
                        }
                        String newPath = StringUtil.addSuffixIfNotAlready(path, "/text()");
                        pathContent = xmlUnitService.getFromXml(responseBody, newPath);
                        break;
                    case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:
                        try {
                            pathContent = jsonService.getFromJson(responseBody, null, path);
                        } catch (Exception ex) {
                            mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);
                            mes.setDescription(mes.getDescription().replace("%ERROR%", ex.toString()));
                            return mes;
                        }
                        break;
                    default:
                        mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);
                        mes.setDescription(mes.getDescription().replace("%TYPE%", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()));
                        mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyRegexInElement"));
                        return mes;
                }
            // TODO Give the actual element found into the description.
            } else {
                mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);
                return mes;
            }
        } else {
            mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
            mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyRegexInElement"));
            mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
            return mes;
        }
        LOG.debug("Control : verifyRegexInElement element : " + path + " has value : " + StringUtil.sanitize(pathContent));
        if (path != null && pathContent != null) {
            try {
                Pattern pattern = Pattern.compile(regex);
                Matcher matcher = pattern.matcher(pathContent);
                if (matcher.find()) {
                    mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_REGEXINELEMENT);
                    mes.setDescription(mes.getDescription().replace("%STRING1%", path));
                    mes.setDescription(mes.getDescription().replace("%STRING2%", StringUtil.sanitize(pathContent)));
                    mes.setDescription(mes.getDescription().replace("%STRING3%", regex));
                    return mes;
                } else {
                    mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT);
                    mes.setDescription(mes.getDescription().replace("%STRING1%", path));
                    mes.setDescription(mes.getDescription().replace("%STRING2%", StringUtil.sanitize(pathContent)));
                    mes.setDescription(mes.getDescription().replace("%STRING3%", regex));
                    return mes;
                }
            } catch (PatternSyntaxException e) {
                mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_INVALIDPATERN);
                mes.setDescription(mes.getDescription().replace("%PATERN%", regex));
                mes.setDescription(mes.getDescription().replace("%ERROR%", e.getMessage()));
                return mes;
            }
        } else if (pathContent != null) {
            mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_NULL);
            return mes;
        } else {
            mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_NO_SUCH_ELEMENT);
            mes.setDescription(mes.getDescription().replace("%ELEMENT%", path));
            return mes;
        }
    } catch (NoSuchElementException exception) {
        LOG.debug(exception.toString());
        mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_REGEXINELEMENT_NO_SUCH_ELEMENT);
        mes.setDescription(mes.getDescription().replace("%ELEMENT%", path));
        return mes;
    } catch (WebDriverException exception) {
        return parseWebDriverException(exception);
    }
}
Also used : Pattern(java.util.regex.Pattern) Identifier(org.cerberus.engine.entity.Identifier) Matcher(java.util.regex.Matcher) MessageEvent(org.cerberus.engine.entity.MessageEvent) WebDriverException(org.openqa.selenium.WebDriverException) PatternSyntaxException(java.util.regex.PatternSyntaxException) CerberusEventException(org.cerberus.exception.CerberusEventException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) PatternSyntaxException(java.util.regex.PatternSyntaxException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 8 with Identifier

use of org.cerberus.engine.entity.Identifier in project cerberus-source by cerberustesting.

the class ControlService method verifyTextNotInElement.

private MessageEvent verifyTextNotInElement(TestCaseExecution tCExecution, String path, String expected) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Control: verifyTextNotInElement on " + path + " element against value: " + expected);
    }
    // Get value from the path element according to the application type
    String actual = null;
    try {
        Identifier identifier = identifierService.convertStringToIdentifier(path);
        String applicationType = tCExecution.getApplicationObj().getType();
        if (Application.TYPE_GUI.equalsIgnoreCase(applicationType) || Application.TYPE_APK.equalsIgnoreCase(applicationType) || Application.TYPE_IPA.equalsIgnoreCase(applicationType)) {
            actual = webdriverService.getValueFromHTML(tCExecution.getSession(), identifier);
            // In case of null actual value then we alert user
            if (actual == null) {
                MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINELEMENT_NULL);
                mes.setDescription(mes.getDescription().replace("%STRING1%", path));
                return mes;
            }
            // Construct the message from the actual response
            MessageEvent mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINELEMENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTNOTINELEMENT);
            mes.setDescription(mes.getDescription().replace("%STRING1%", path));
            mes.setDescription(mes.getDescription().replace("%STRING2%", actual));
            mes.setDescription(mes.getDescription().replace("%STRING3%", expected));
            return mes;
        } else if (Application.TYPE_SRV.equalsIgnoreCase(applicationType)) {
            if (tCExecution.getLastServiceCalled() != null) {
                String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();
                MessageEvent mes;
                switch(tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {
                    case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:
                        if (!xmlUnitService.isElementPresent(responseBody, path)) {
                            throw new NoSuchElementException("Unable to find element " + path);
                        }
                        String newPath = StringUtil.addSuffixIfNotAlready(path, "/text()");
                        actual = xmlUnitService.getFromXml(responseBody, newPath);
                        // In case of null actual value then we alert user
                        if (actual == null) {
                            mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINELEMENT_NULL);
                            mes.setDescription(mes.getDescription().replace("%STRING1%", path));
                            return mes;
                        }
                        // Construct the message from the actual response
                        mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINELEMENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTNOTINELEMENT);
                        mes.setDescription(mes.getDescription().replace("%STRING1%", path));
                        mes.setDescription(mes.getDescription().replace("%STRING2%", actual));
                        mes.setDescription(mes.getDescription().replace("%STRING3%", expected));
                        return mes;
                    case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:
                        {
                            try {
                                actual = jsonService.getFromJson(responseBody, null, path);
                            } catch (Exception ex) {
                                mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);
                                mes.setDescription(mes.getDescription().replace("%ERROR%", ex.toString()));
                                return mes;
                            }
                        }
                        // In case of null actual value then we alert user
                        if (actual == null) {
                            mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINELEMENT_NO_SUCH_ELEMENT);
                            mes.setDescription(mes.getDescription().replace("%ELEMENT%", path));
                            return mes;
                        }
                        // Construct the message from the actual response
                        mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINELEMENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTNOTINELEMENT);
                        mes.setDescription(mes.getDescription().replace("%STRING1%", path));
                        mes.setDescription(mes.getDescription().replace("%STRING2%", actual));
                        mes.setDescription(mes.getDescription().replace("%STRING3%", expected));
                        return mes;
                    default:
                        mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);
                        mes.setDescription(mes.getDescription().replace("%TYPE%", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()));
                        mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyTextNotInElement"));
                        return mes;
                }
            } else {
                MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);
                return mes;
            }
        } else {
            MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
            mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyTextNotInElement"));
            mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
            return mes;
        }
    } catch (NoSuchElementException exception) {
        MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINELEMENT_NO_SUCH_ELEMENT);
        mes.setDescription(mes.getDescription().replace("%ELEMENT%", path));
        return mes;
    } catch (WebDriverException exception) {
        return parseWebDriverException(exception);
    }
}
Also used : Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent) NoSuchElementException(org.openqa.selenium.NoSuchElementException) WebDriverException(org.openqa.selenium.WebDriverException) PatternSyntaxException(java.util.regex.PatternSyntaxException) CerberusEventException(org.cerberus.exception.CerberusEventException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 9 with Identifier

use of org.cerberus.engine.entity.Identifier in project cerberus-source by cerberustesting.

the class ControlService method verifyElementInElement.

private MessageEvent verifyElementInElement(TestCaseExecution tCExecution, String element, String childElement) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Control : verifyElementInElement on : '" + element + "' is child of '" + childElement + "'");
    }
    MessageEvent mes;
    if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {
        if (!StringUtil.isNull(element) && !StringUtil.isNull(childElement)) {
            try {
                Identifier identifier = identifierService.convertStringToIdentifier(element);
                Identifier childIdentifier = identifierService.convertStringToIdentifier(childElement);
                if (this.webdriverService.isElementInElement(tCExecution.getSession(), identifier, childIdentifier)) {
                    mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_ELEMENTINELEMENT);
                    mes.setDescription(mes.getDescription().replace("%STRING2%", element).replace("%STRING1%", childElement));
                    return mes;
                } else {
                    mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTINELEMENT);
                    mes.setDescription(mes.getDescription().replace("%STRING2%", element).replace("%STRING1%", childElement));
                    return mes;
                }
            } catch (WebDriverException exception) {
                return parseWebDriverException(exception);
            }
        } else {
            mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_ELEMENTINELEMENT);
            mes.setDescription(mes.getDescription().replace("%STRING2%", element).replace("%STRING1%", childElement));
            return mes;
        }
    } else {
        mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
        mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyElementInElement"));
        mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
        return mes;
    }
}
Also used : Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent) WebDriverException(org.openqa.selenium.WebDriverException)

Example 10 with Identifier

use of org.cerberus.engine.entity.Identifier in project cerberus-source by cerberustesting.

the class ControlService method verifyElementNotClickable.

private MessageEvent verifyElementNotClickable(TestCaseExecution tCExecution, String html) {
    LOG.debug("Control : verifyElementNotClickable on : " + html);
    MessageEvent mes;
    if (!StringUtil.isNull(html)) {
        Identifier identifier = identifierService.convertStringToIdentifier(html);
        if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {
            try {
                if (this.webdriverService.isElementNotClickable(tCExecution.getSession(), identifier)) {
                    mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTCLICKABLE);
                    mes.setDescription(mes.getDescription().replace("%ELEMENT%", html));
                    return mes;
                } else {
                    mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTCLICKABLE);
                    mes.setDescription(mes.getDescription().replace("%ELEMENT%", html));
                    return mes;
                }
            } catch (WebDriverException exception) {
                return parseWebDriverException(exception);
            }
        } else {
            mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
            mes.setDescription(mes.getDescription().replace("%CONTROL%", "VerifyElementNotClickable"));
            mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
            return mes;
        }
    } else {
        return new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTCLICKABLE_NULL);
    }
}
Also used : Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent) WebDriverException(org.openqa.selenium.WebDriverException)

Aggregations

Identifier (org.cerberus.engine.entity.Identifier)31 MessageEvent (org.cerberus.engine.entity.MessageEvent)30 CerberusEventException (org.cerberus.exception.CerberusEventException)20 WebDriverException (org.openqa.selenium.WebDriverException)12 NoSuchElementException (org.openqa.selenium.NoSuchElementException)8 PatternSyntaxException (java.util.regex.PatternSyntaxException)5 AnswerItem (org.cerberus.util.answer.AnswerItem)2 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1