Search in sources :

Example 11 with Identifier

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

the class ConditionService method evaluateCondition_ifElementPresent.

private AnswerItem<Boolean> evaluateCondition_ifElementPresent(String conditionOper, String conditionValue1, TestCaseExecution tCExecution) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Checking if Element Present");
    }
    AnswerItem ans = new AnswerItem();
    MessageEvent mes;
    if (StringUtil.isNullOrEmpty(conditionValue1)) {
        mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_IFELEMENTPRESENT_MISSINGPARAMETER);
        mes.setDescription(mes.getDescription().replace("%COND%", conditionOper));
    } else {
        boolean condition_result = false;
        Identifier identifier = identifierService.convertStringToIdentifier(conditionValue1);
        if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
            try {
                if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {
                    condition_result = true;
                    mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTPRESENT);
                    mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));
                } else {
                    condition_result = false;
                    mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTPRESENT);
                    mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));
                }
            } catch (WebDriverException exception) {
                condition_result = false;
                mes = parseWebDriverException(exception);
            }
        } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_SRV)) {
            if (tCExecution.getLastServiceCalled() != null) {
                String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();
                switch(tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {
                    case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:
                        if (xmlUnitService.isElementPresent(responseBody, conditionValue1)) {
                            condition_result = true;
                            mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTPRESENT);
                            mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));
                        } else {
                            condition_result = false;
                            mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTPRESENT);
                            mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));
                        }
                    case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:
                        {
                            try {
                                if (jsonService.getFromJson(responseBody, null, conditionValue1) != null) {
                                    condition_result = true;
                                    mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTPRESENT);
                                    mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));
                                } else {
                                    condition_result = false;
                                    mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTPRESENT);
                                    mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));
                                }
                            } catch (Exception ex) {
                                mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_GENERIC);
                                mes.setDescription(mes.getDescription().replace("%ERROR%", ex.toString()));
                            }
                        }
                    default:
                        condition_result = false;
                        mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_NOTSUPPORTED_FOR_MESSAGETYPE);
                        mes.setDescription(mes.getDescription().replace("%TYPE%", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()));
                        mes.setDescription(mes.getDescription().replace("%CONDITION%", conditionOper));
                }
            } else {
                condition_result = false;
                mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_NOOBJECTINMEMORY);
            }
        } else {
            mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_NOTSUPPORTED_FOR_APPLICATION);
            mes.setDescription(mes.getDescription().replace("%CONDITION%", conditionOper));
            mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
        }
    }
    ans.setResultMessage(mes);
    return ans;
}
Also used : Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent) AnswerItem(org.cerberus.util.answer.AnswerItem) WebDriverException(org.openqa.selenium.WebDriverException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 12 with Identifier

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

the class ActionService method doActionDoubleClick.

private MessageEvent doActionDoubleClick(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, "doubleClick", tCExecution);
        /**
         * Get Identifier (identifier, locator)
         */
        Identifier identifier = identifierService.convertStringToIdentifier(element);
        if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {
            if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {
                return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), identifier.getLocator(), "");
            } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {
                return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), "", identifier.getLocator());
            } else {
                identifierService.checkWebElementIdentifier(identifier.getIdentifier());
                return webdriverService.doSeleniumActionDoubleClick(tCExecution.getSession(), identifier, true, true);
            }
        } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
            identifierService.checkWebElementIdentifier(identifier.getIdentifier());
            return webdriverService.doSeleniumActionDoubleClick(tCExecution.getSession(), identifier, true, false);
        } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {
            identifierService.checkSikuliIdentifier(identifier.getIdentifier());
            if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {
                return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), identifier.getLocator(), "");
            } else {
                return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), "", identifier.getLocator());
            }
        }
        message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
        message.setDescription(message.getDescription().replace("%ACTION%", "doubleClick"));
        message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
        return message;
    } catch (CerberusEventException ex) {
        LOG.fatal("Error doing Action DoubleClick :" + ex);
        return ex.getMessageError();
    }
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent)

Example 13 with Identifier

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

the class ActionService method doActionMouseOverAndWait.

private MessageEvent doActionMouseOverAndWait(TestCaseExecution tCExecution, String object, String property) {
    MessageEvent message;
    try {
        /**
         * Check object is not null
         */
        if (object == null) {
            return new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVERANDWAIT_GENERIC);
        }
        /**
         * Get Identifier (identifier, locator)
         */
        Identifier identifier = identifierService.convertStringToIdentifier(object);
        identifierService.checkWebElementIdentifier(identifier.getIdentifier());
        if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {
            if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {
                message = sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), identifier.getLocator(), "");
            } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {
                message = sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), "", identifier.getLocator());
            } else {
                message = webdriverService.doSeleniumActionMouseOver(tCExecution.getSession(), identifier);
            }
            if (message.getCodeString().equals("OK")) {
                message = this.doActionWait(tCExecution, property, null);
            }
            return message;
        }
        message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
        message.setDescription(message.getDescription().replace("%ACTION%", "mouseOverAndWait"));
        message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
        return message;
    } catch (CerberusEventException ex) {
        LOG.fatal("Error doing Action MouseOverAndWait :" + ex);
        return ex.getMessageError();
    }
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent)

Example 14 with Identifier

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

the class ActionService method doActionClickWait.

private MessageEvent doActionClickWait(TestCaseExecution tCExecution, String string1, String string2) {
    MessageEvent message;
    try {
        Identifier identifier = identifierService.convertStringToIdentifier(string1);
        identifierService.checkWebElementIdentifier(identifier.getIdentifier());
        if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {
            message = webdriverService.doSeleniumActionClick(tCExecution.getSession(), identifier, true, true);
            if (message.getCodeString().equals("OK")) {
                message = this.doActionWait(tCExecution, string2, null);
            }
            return message;
        }
        message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
        message.setDescription(message.getDescription().replace("%ACTION%", "ClickAndWait"));
        message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", string1));
        return message;
    } catch (CerberusEventException ex) {
        LOG.fatal("Error doing Action ClickAndWait :" + ex);
        return ex.getMessageError();
    }
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent)

Example 15 with Identifier

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

the class ActionService method doActionSelect.

private MessageEvent doActionSelect(TestCaseExecution tCExecution, String value1, String value2) {
    MessageEvent message;
    try {
        /**
         * Check object and property are not null
         */
        if (StringUtil.isNullOrEmpty(value1) || StringUtil.isNullOrEmpty(value2)) {
            return new MessageEvent(MessageEventEnum.ACTION_FAILED_SELECT);
        }
        /**
         * Get Identifier (identifier, locator)
         */
        Identifier identifierObject = identifierService.convertStringToIdentifier(value1);
        Identifier identifierValue = identifierService.convertStringToSelectIdentifier(value2);
        identifierService.checkWebElementIdentifier(identifierObject.getIdentifier());
        identifierService.checkSelectOptionsIdentifier(identifierValue.getIdentifier());
        if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
            return webdriverService.doSeleniumActionSelect(tCExecution.getSession(), identifierObject, identifierValue);
        }
        message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
        message.setDescription(message.getDescription().replace("%ACTION%", "Select"));
        message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
        return message;
    } catch (CerberusEventException ex) {
        LOG.fatal("Error doing Action Select :" + ex);
        return ex.getMessageError();
    }
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent)

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