Search in sources :

Example 26 with Identifier

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

the class ControlService method verifyElementNotVisible.

private MessageEvent verifyElementNotVisible(TestCaseExecution tCExecution, String html) {
    LOG.debug("Control : verifyElementNotVisible on : " + html);
    MessageEvent mes;
    if (!StringUtil.isNull(html)) {
        if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
            try {
                Identifier identifier = identifierService.convertStringToIdentifier(html);
                if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {
                    if (this.webdriverService.isElementNotVisible(tCExecution.getSession(), identifier)) {
                        mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTVISIBLE);
                        mes.setDescription(mes.getDescription().replace("%STRING1%", html));
                        return mes;
                    } else {
                        mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTVISIBLE);
                        mes.setDescription(mes.getDescription().replace("%STRING1%", html));
                        return mes;
                    }
                } else {
                    mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);
                    mes.setDescription(mes.getDescription().replace("%STRING1%", 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%", "verifyElementNotVisible"));
            mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
            return mes;
        }
    } else {
        return new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTVISIBLE_NULL);
    }
}
Also used : Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent) WebDriverException(org.openqa.selenium.WebDriverException)

Example 27 with Identifier

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

the class PropertyService method property_getFromHtmlVisible.

private TestCaseExecutionData property_getFromHtmlVisible(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {
    try {
        Identifier identifier = identifierService.convertStringToIdentifier(testCaseExecutionData.getValue1());
        String valueFromHTML = this.webdriverService.getValueFromHTMLVisible(tCExecution.getSession(), identifier);
        if (valueFromHTML != null) {
            testCaseExecutionData.setValue(valueFromHTML);
            MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_HTMLVISIBLE);
            res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));
            res.setDescription(res.getDescription().replace("%VALUE%", valueFromHTML));
            testCaseExecutionData.setPropertyResultMessage(res);
        } else {
            MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTMLVISIBLE_ELEMENTDONOTEXIST);
            res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));
            testCaseExecutionData.setPropertyResultMessage(res);
        }
    } catch (NoSuchElementException exception) {
        LOG.debug(exception.toString());
        MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTMLVISIBLE_ELEMENTDONOTEXIST);
        res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));
        testCaseExecutionData.setPropertyResultMessage(res);
    }
    return testCaseExecutionData;
}
Also used : Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 28 with Identifier

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

the class PropertyService method property_getFromHtml.

private TestCaseExecutionData property_getFromHtml(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {
    if (tCExecution.getApplicationObj().getType().equals(Application.TYPE_APK) || tCExecution.getApplicationObj().getType().equals(Application.TYPE_IPA) || tCExecution.getApplicationObj().getType().equals(Application.TYPE_GUI)) {
        try {
            Identifier identifier = identifierService.convertStringToIdentifier(testCaseExecutionData.getValue1());
            String valueFromHTML = this.webdriverService.getValueFromHTML(tCExecution.getSession(), identifier);
            if (valueFromHTML != null) {
                testCaseExecutionData.setValue(valueFromHTML);
                MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_HTML);
                res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));
                res.setDescription(res.getDescription().replace("%VALUE%", valueFromHTML));
                testCaseExecutionData.setPropertyResultMessage(res);
            }
        } catch (NoSuchElementException exception) {
            LOG.debug(exception.toString());
            MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTML_ELEMENTDONOTEXIST);
            res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));
            testCaseExecutionData.setPropertyResultMessage(res);
        }
    } else {
        MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_FEATURENOTSUPPORTED);
        res.setDescription(res.getDescription().replace("%APPTYPE%", tCExecution.getApplicationObj().getType()));
        res.setDescription(res.getDescription().replace("%PROPTYPE%", testCaseExecutionData.getType()));
    }
    return testCaseExecutionData;
}
Also used : Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 29 with Identifier

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

the class PropertyService method property_getAttributeFromHtml.

private TestCaseExecutionData property_getAttributeFromHtml(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {
    MessageEvent res;
    try {
        Identifier identifier = identifierService.convertStringToIdentifier(testCaseExecutionData.getValue1());
        String valueFromHTML = this.webdriverService.getAttributeFromHtml(tCExecution.getSession(), identifier, testCaseExecutionData.getValue2());
        if (valueFromHTML != null) {
            testCaseExecutionData.setValue(valueFromHTML);
            res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETATTRIBUTEFROMHTML);
            res.setDescription(res.getDescription().replace("%VALUE%", valueFromHTML));
        } else {
            res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTML_ATTRIBUTEDONOTEXIST);
        }
        res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));
        res.setDescription(res.getDescription().replace("%ATTRIBUTE%", testCaseExecutionData.getValue2()));
    } catch (NoSuchElementException exception) {
        LOG.debug(exception.toString());
        res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_HTMLVISIBLE_ELEMENTDONOTEXIST);
        res.setDescription(res.getDescription().replace("%ELEMENT%", testCaseExecutionData.getValue1()));
    }
    testCaseExecutionData.setPropertyResultMessage(res);
    return testCaseExecutionData;
}
Also used : Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 30 with Identifier

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

the class ConditionService method evaluateCondition_ifElementNotPresent.

private AnswerItem<Boolean> evaluateCondition_ifElementNotPresent(String conditionOper, String conditionValue1, TestCaseExecution tCExecution) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Checking if Element is Not Present");
    }
    AnswerItem ans = new AnswerItem();
    MessageEvent mes;
    if (StringUtil.isNullOrEmpty(conditionValue1)) {
        mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_IFELEMENTNOTPRESENT_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 (identifier.getIdentifier().equals("picture")) {
                    mes = sikuliService.doSikuliVerifyElementNotPresent(tCExecution.getSession(), identifier.getLocator());
                    if (mes.equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTPRESENT))) {
                        condition_result = true;
                    } else {
                        condition_result = false;
                    }
                } else if (!this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {
                    condition_result = true;
                    mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFELEMENTNOTPRESENT);
                    mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));
                } else {
                    condition_result = false;
                    mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTNOTPRESENT);
                    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_IFELEMENTNOTPRESENT);
                            mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));
                        } else {
                            condition_result = false;
                            mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTNOTPRESENT);
                            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_IFELEMENTNOTPRESENT);
                                    mes.setDescription(mes.getDescription().replace("%ELEMENT%", conditionValue1));
                                } else {
                                    condition_result = false;
                                    mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFELEMENTNOTPRESENT);
                                    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)

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