Search in sources :

Example 11 with CerberusEventException

use of org.cerberus.exception.CerberusEventException 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 12 with CerberusEventException

use of org.cerberus.exception.CerberusEventException in project cerberus-source by cerberustesting.

the class ControlService method doControl.

@Override
public TestCaseStepActionControlExecution doControl(TestCaseStepActionControlExecution testCaseStepActionControlExecution) {
    MessageEvent res;
    TestCaseExecution tCExecution = testCaseStepActionControlExecution.getTestCaseStepActionExecution().getTestCaseStepExecution().gettCExecution();
    AnswerItem<String> answerDecode = new AnswerItem();
    /**
     * Decode the 2 fields property and values before doing the control.
     */
    try {
        // then the execution of this control should not performed
        if (testCaseStepActionControlExecution.getValue1().contains("%")) {
            // When starting a new control, we reset the property list that was already calculated.
            tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList());
            answerDecode = variableService.decodeStringCompletly(testCaseStepActionControlExecution.getValue1(), tCExecution, testCaseStepActionControlExecution.getTestCaseStepActionExecution(), false);
            testCaseStepActionControlExecution.setValue1((String) answerDecode.getItem());
            if (!(answerDecode.isCodeStringEquals("OK"))) {
                // If anything wrong with the decode --> we stop here with decode message in the control result.
                testCaseStepActionControlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Value1"));
                testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));
                testCaseStepActionControlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());
                testCaseStepActionControlExecution.setEnd(new Date().getTime());
                LOG.debug("Control interupted due to decode 'Control Value1' Error.");
                return testCaseStepActionControlExecution;
            }
        }
        if (testCaseStepActionControlExecution.getValue2().contains("%")) {
            // When starting a new control, we reset the property list that was already calculated.
            tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList());
            answerDecode = variableService.decodeStringCompletly(testCaseStepActionControlExecution.getValue2(), tCExecution, testCaseStepActionControlExecution.getTestCaseStepActionExecution(), false);
            testCaseStepActionControlExecution.setValue2((String) answerDecode.getItem());
            if (!(answerDecode.isCodeStringEquals("OK"))) {
                // If anything wrong with the decode --> we stop here with decode message in the control result.
                testCaseStepActionControlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Value2"));
                testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));
                testCaseStepActionControlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());
                testCaseStepActionControlExecution.setEnd(new Date().getTime());
                LOG.debug("Control interupted due to decode 'Control Value2' Error.");
                return testCaseStepActionControlExecution;
            }
        }
    } catch (CerberusEventException cex) {
        testCaseStepActionControlExecution.setControlResultMessage(cex.getMessageError());
        testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(cex.getMessageError().getMessage()));
        return testCaseStepActionControlExecution;
    }
    /**
     * Timestamp starts after the decode. TODO protect when property is
     * null.
     */
    testCaseStepActionControlExecution.setStart(new Date().getTime());
    // When starting a new control, we reset the property list that was already calculated.
    tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList());
    try {
        switch(testCaseStepActionControlExecution.getControl()) {
            case TestCaseStepActionControl.CONTROL_VERIFYSTRINGEQUAL:
                res = this.verifyStringEqual(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYSTRINGDIFFERENT:
                res = this.verifyStringDifferent(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYSTRINGGREATER:
                res = this.verifyStringGreater(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYSTRINGMINOR:
                res = this.verifyStringMinor(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYSTRINGCONTAINS:
                res = this.verifyStringContains(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYNUMERICEQUALS:
            case TestCaseStepActionControl.CONTROL_VERIFYNUMERICDIFFERENT:
            case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATER:
            case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATEROREQUAL:
            case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOR:
            case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOROREQUAL:
                res = this.evaluateControl_ifNumericXXX(testCaseStepActionControlExecution.getControl(), testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYELEMENTPRESENT:
                // TODO validate properties
                res = this.verifyElementPresent(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTPRESENT:
                // TODO validate properties
                res = this.verifyElementNotPresent(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYELEMENTVISIBLE:
                // TODO validate properties
                res = this.verifyElementVisible(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTVISIBLE:
                // TODO validate properties
                res = this.verifyElementNotVisible(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYELEMENTEQUALS:
                res = this.verifyElementEquals(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYELEMENTDIFFERENT:
                res = this.verifyElementDifferent(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYELEMENTINELEMENT:
                // TODO validate properties
                res = this.verifyElementInElement(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYELEMENTCLICKABLE:
                res = this.verifyElementClickable(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTCLICKABLE:
                res = this.verifyElementNotClickable(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYTEXTINELEMENT:
                res = this.verifyTextInElement(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYTEXTNOTINELEMENT:
                res = this.verifyTextNotInElement(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYREGEXINELEMENT:
                res = this.VerifyRegexInElement(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYTEXTINPAGE:
                res = this.VerifyTextInPage(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYTEXTNOTINPAGE:
                res = this.VerifyTextNotInPage(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYTITLE:
                res = this.verifyTitle(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYURL:
                res = this.verifyUrl(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYTEXTINDIALOG:
                res = this.verifyTextInDialog(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYXMLTREESTRUCTURE:
                res = this.verifyXmlTreeStructure(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_TAKESCREENSHOT:
                res = this.takeScreenshot(tCExecution, testCaseStepActionControlExecution.getTestCaseStepActionExecution(), testCaseStepActionControlExecution);
                break;
            case TestCaseStepActionControl.CONTROL_GETPAGESOURCE:
                res = this.getPageSource(tCExecution, testCaseStepActionControlExecution.getTestCaseStepActionExecution(), testCaseStepActionControlExecution);
                break;
            default:
                res = new MessageEvent(MessageEventEnum.CONTROL_FAILED_UNKNOWNCONTROL);
                res.setDescription(res.getDescription().replace("%CONTROL%", testCaseStepActionControlExecution.getControl()));
        }
    } catch (final CerberusEventException exception) {
        res = exception.getMessageError();
    } catch (final Exception unexpected) {
        LOG.error("Unexpected exception: " + unexpected.getMessage(), unexpected);
        res = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC).resolveDescription("ERROR", unexpected.getMessage());
    }
    testCaseStepActionControlExecution.setControlResultMessage(res);
    /**
     * Updating Control result message only if control is not successful.
     * This is to keep the last KO information and preventing KO to be
     * transformed to OK.
     */
    if (!(res.equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS)))) {
        testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(res.getMessage()));
    }
    /**
     * We only stop the test if Control Event message is in stop status AND
     * the control is FATAL. If control is not fatal, we continue the test
     * but refresh the Execution status.
     */
    if (res.isStopTest()) {
        if (testCaseStepActionControlExecution.getFatal().equals("Y")) {
            testCaseStepActionControlExecution.setStopExecution(true);
        }
    }
    testCaseStepActionControlExecution.setEnd(new Date().getTime());
    return testCaseStepActionControlExecution;
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) AnswerItem(org.cerberus.util.answer.AnswerItem) Date(java.util.Date) WebDriverException(org.openqa.selenium.WebDriverException) PatternSyntaxException(java.util.regex.PatternSyntaxException) CerberusEventException(org.cerberus.exception.CerberusEventException) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 13 with CerberusEventException

use of org.cerberus.exception.CerberusEventException in project cerberus-source by cerberustesting.

the class PropertyService method calculateProperty.

@Override
public void calculateProperty(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceRecalculation) {
    testCaseExecutionData.setStart(new Date().getTime());
    MessageEvent res;
    String test = tCExecution.getTest();
    String testCase = tCExecution.getTestCase();
    AnswerItem<String> answerDecode = new AnswerItem();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Starting to calculate Property : '" + testCaseCountryProperty.getProperty() + "'");
    }
    // Checking recursive decode.
    if ((tCExecution.getRecursiveAlreadyCalculatedPropertiesList() != null) && (tCExecution.getRecursiveAlreadyCalculatedPropertiesList().contains(testCaseCountryProperty.getProperty()))) {
        res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_RECURSIVE);
        res.setDescription(res.getDescription().replace("%PROPERTY%", testCaseCountryProperty.getProperty()).replace("%HISTO%", tCExecution.getRecursiveAlreadyCalculatedPropertiesList().toString()));
        testCaseExecutionData.setPropertyResultMessage(res);
        testCaseExecutionData.setEnd(new Date().getTime());
        LOG.debug("Finished to calculate Property (interupted) : '" + testCaseCountryProperty.getProperty() + "' : " + testCaseExecutionData.getPropertyResultMessage().getDescription());
        return;
    }
    if (tCExecution.getRecursiveAlreadyCalculatedPropertiesList() != null) {
        tCExecution.getRecursiveAlreadyCalculatedPropertiesList().add(testCaseCountryProperty.getProperty());
    }
    try {
        // Check if cache activated and cache entry exist.
        int cacheValue = testCaseCountryProperty.getCacheExpire();
        boolean useCache = false;
        AnswerItem<TestCaseExecutionData> answerData = null;
        if (cacheValue > 0) {
            answerData = testCaseExecutionDataService.readLastCacheEntry(tCExecution.getApplicationObj().getSystem(), tCExecution.getEnvironment(), tCExecution.getCountry(), testCaseCountryProperty.getProperty(), cacheValue);
            if (answerData.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerData.getItem() != null) {
                useCache = true;
            }
        }
        if (!useCache) {
            /**
             * Decode Property replacing properties encapsulated with %
             */
            if (testCaseCountryProperty.getValue1().contains("%")) {
                answerDecode = variableService.decodeStringCompletly(testCaseCountryProperty.getValue1(), tCExecution, null, false);
                testCaseExecutionData.setValue1((String) answerDecode.getItem());
                if (!(answerDecode.isCodeStringEquals("OK"))) {
                    // If anything wrong with the decode --> we stop here with decode message in the property result.
                    testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Property Value1"));
                    testCaseExecutionData.setEnd(new Date().getTime());
                    testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());
                    LOG.debug("Finished to calculate Property (interupted) : '" + testCaseCountryProperty.getProperty() + "' : " + testCaseExecutionData.getPropertyResultMessage().getDescription());
                    return;
                }
            }
            if (testCaseCountryProperty.getValue2() != null && testCaseCountryProperty.getValue2().contains("%")) {
                answerDecode = variableService.decodeStringCompletly(testCaseCountryProperty.getValue2(), tCExecution, null, false);
                testCaseExecutionData.setValue2((String) answerDecode.getItem());
                if (!(answerDecode.isCodeStringEquals("OK"))) {
                    // If anything wrong with the decode --> we stop here with decode message in the property result.
                    testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Property Value2"));
                    testCaseExecutionData.setEnd(new Date().getTime());
                    testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());
                    LOG.debug("Finished to calculate Property (interupted) : '" + testCaseCountryProperty.getProperty() + "' : " + testCaseExecutionData.getPropertyResultMessage().getDescription());
                    return;
                }
            }
            // cache not activated or no entry exist.
            int execution_count = 0;
            int retries = testCaseCountryProperty.getRetryNb();
            int periodms = testCaseCountryProperty.getRetryPeriod();
            LOG.debug("Init Retries : " + retries + " Period : " + periodms);
            /**
             * Controling that retrynb and retryperiod are correctly feeded.
             * <br>
             * This is to avoid that <br>
             * 1/ retry is greater than cerberus_property_maxretry <br>
             * 2/ total duration of property calculation is longuer than
             * cerberus_property_maxretrytotalduration
             */
            boolean forced_retry = false;
            String forced_retry_message = "";
            if (!(retries == 0)) {
                int maxretry = parameterService.getParameterIntegerByKey("cerberus_property_maxretry", "", 50);
                if (retries > maxretry) {
                    retries = maxretry;
                    forced_retry = true;
                }
                int maxtotalduration = parameterService.getParameterIntegerByKey("cerberus_property_maxretrytotalduration", "", 1800000);
                if (periodms > maxtotalduration) {
                    periodms = maxtotalduration;
                    forced_retry = true;
                }
                if (retries * periodms > maxtotalduration) {
                    retries = (int) maxtotalduration / periodms;
                    forced_retry = true;
                }
                if (forced_retry) {
                    forced_retry_message = "WARNING : Forced Retries : " + testCaseCountryProperty.getRetryNb() + "-->" + retries + " and Period : " + testCaseCountryProperty.getRetryPeriod() + "-->" + periodms + " (in order to respect the constrains cerberus_property_maxretry " + maxretry + " & cerberus_property_maxtotalduration " + maxtotalduration + ")";
                    LOG.debug("Forced Retries : " + retries + " Period : " + periodms + " in order to respect the constrains cerberus_property_maxretry " + maxretry + " & cerberus_property_maxtotalduration " + maxtotalduration);
                }
            }
            /**
             * Looping on calculating the action until result is OK or reach
             * the max retry.
             */
            while (execution_count <= retries && !(testCaseExecutionData.getPropertyResultMessage().getCodeString().equals("OK"))) {
                LOG.debug("Attempt #" + execution_count + " " + testCaseCountryProperty.getProperty() + " " + testCaseCountryProperty.getValue1());
                if (execution_count >= 1) {
                    // We only wait the period if not on the very first calculation.
                    try {
                        Thread.sleep(periodms);
                        LOG.debug("Attempt #" + execution_count + " " + testCaseCountryProperty.getProperty() + " " + testCaseCountryProperty.getValue1() + " Waiting " + periodms + " ms");
                    } catch (InterruptedException ex) {
                        LOG.error(ex.toString());
                    }
                }
                /**
                 * Calculate Property regarding the type
                 */
                switch(testCaseCountryProperty.getType()) {
                    case TestCaseCountryProperties.TYPE_TEXT:
                        testCaseExecutionData = this.property_calculateText(testCaseExecutionData, testCaseCountryProperty, forceRecalculation);
                        break;
                    case TestCaseCountryProperties.TYPE_GETFROMDATALIB:
                        testCaseExecutionData = this.property_getFromDataLib(testCaseExecutionData, tCExecution, testCaseStepActionExecution, testCaseCountryProperty, forceRecalculation);
                        break;
                    case TestCaseCountryProperties.TYPE_GETFROMSQL:
                        testCaseExecutionData = this.property_getFromSql(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);
                        break;
                    case TestCaseCountryProperties.TYPE_GETFROMHTML:
                        testCaseExecutionData = this.property_getFromHtml(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);
                        break;
                    case TestCaseCountryProperties.TYPE_GETFROMHTMLVISIBLE:
                        testCaseExecutionData = this.property_getFromHtmlVisible(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);
                        break;
                    case TestCaseCountryProperties.TYPE_GETFROMJS:
                        testCaseExecutionData = this.property_getFromJS(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);
                        break;
                    case TestCaseCountryProperties.TYPE_GETATTRIBUTEFROMHTML:
                        testCaseExecutionData = this.property_getAttributeFromHtml(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);
                        break;
                    case TestCaseCountryProperties.TYPE_GETFROMCOOKIE:
                        testCaseExecutionData = this.property_getFromCookie(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);
                        break;
                    case TestCaseCountryProperties.TYPE_GETFROMXML:
                        testCaseExecutionData = this.property_getFromXml(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);
                        break;
                    case TestCaseCountryProperties.TYPE_GETDIFFERENCESFROMXML:
                        testCaseExecutionData = this.property_getDifferencesFromXml(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);
                        break;
                    case TestCaseCountryProperties.TYPE_GETFROMJSON:
                        testCaseExecutionData = this.property_getFromJson(testCaseExecutionData, tCExecution, forceRecalculation);
                        break;
                    case TestCaseCountryProperties.TYPE_GETFROMGROOVY:
                        testCaseExecutionData = this.property_getFromGroovy(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceRecalculation);
                        break;
                    case // DEPRECATED
                    TestCaseCountryProperties.TYPE_EXECUTESOAPFROMLIB:
                        testCaseExecutionData = this.property_executeSoapFromLib(testCaseExecutionData, tCExecution, testCaseStepActionExecution, testCaseCountryProperty, forceRecalculation);
                        res = testCaseExecutionData.getPropertyResultMessage();
                        res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());
                        testCaseExecutionData.setPropertyResultMessage(res);
                        logEventService.createForPrivateCalls("ENGINE", TestCaseCountryProperties.TYPE_EXECUTESOAPFROMLIB, MESSAGE_DEPRECATED + " Deprecated Property triggered by TestCase : ['" + test + "|" + testCase + "']");
                        LOG.warn(MESSAGE_DEPRECATED + " Deprecated Property " + TestCaseCountryProperties.TYPE_EXECUTESOAPFROMLIB + " triggered by TestCase : ['" + test + "'|'" + testCase + "']");
                        break;
                    case // DEPRECATED
                    TestCaseCountryProperties.TYPE_EXECUTESQLFROMLIB:
                        testCaseExecutionData = this.property_executeSqlFromLib(testCaseExecutionData, testCaseCountryProperty, tCExecution, forceRecalculation);
                        res = testCaseExecutionData.getPropertyResultMessage();
                        res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());
                        testCaseExecutionData.setPropertyResultMessage(res);
                        logEventService.createForPrivateCalls("ENGINE", TestCaseCountryProperties.TYPE_EXECUTESQLFROMLIB, MESSAGE_DEPRECATED + " Deprecated Property triggered by TestCase : ['" + test + "|" + testCase + "']");
                        LOG.warn(MESSAGE_DEPRECATED + " Deprecated Property " + TestCaseCountryProperties.TYPE_EXECUTESQLFROMLIB + " triggered by TestCase : ['" + test + "'|'" + testCase + "']");
                        break;
                    default:
                        res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_UNKNOWNPROPERTY);
                        res.setDescription(res.getDescription().replace("%PROPERTY%", testCaseCountryProperty.getType()));
                        testCaseExecutionData.setPropertyResultMessage(res);
                }
                execution_count++;
            }
            if (execution_count >= 2) {
                // If there were at least 1 retry, we notify it in the result message.
                res = testCaseExecutionData.getPropertyResultMessage();
                res.setDescription("Retried " + (execution_count - 1) + " time(s) with " + periodms + "ms period - " + res.getDescription());
                testCaseExecutionData.setPropertyResultMessage(res);
            }
            if (forced_retry) {
                // If the retry and period parameter was changed, we notify it in the result message.
                res = testCaseExecutionData.getPropertyResultMessage();
                res.setDescription(forced_retry_message + " - " + res.getDescription());
                testCaseExecutionData.setPropertyResultMessage(res);
            }
        } else {
            // cache activated and entry exist. We set the current value with cache entry data and notify the result from the messsage.
            TestCaseExecutionData testCaseExecutionDataFromCache = (TestCaseExecutionData) answerData.getItem();
            testCaseExecutionData.setFromCache("Y");
            testCaseExecutionData.setDataLib(testCaseExecutionDataFromCache.getDataLib());
            testCaseExecutionData.setValue(testCaseExecutionDataFromCache.getValue());
            testCaseExecutionData.setJsonResult(testCaseExecutionDataFromCache.getJsonResult());
            DateFormat df = new SimpleDateFormat(DateUtil.DATE_FORMAT_DISPLAY);
            res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_FROMCACHE).resolveDescription("ID", String.valueOf(testCaseExecutionDataFromCache.getId())).resolveDescription("DATE", df.format(testCaseExecutionDataFromCache.getStart()));
            testCaseExecutionData.setPropertyResultMessage(res);
            if (!StringUtil.isNullOrEmpty(testCaseExecutionDataFromCache.getJsonResult())) {
                // Convert json to HashMap.
                List<HashMap<String, String>> result = null;
                result = new ArrayList();
                try {
                    LOG.debug("Converting Json : " + testCaseExecutionDataFromCache.getJsonResult());
                    JSONArray json = new JSONArray(testCaseExecutionDataFromCache.getJsonResult());
                    for (int i = 0; i < json.length(); i++) {
                        JSONObject explrObject = json.getJSONObject(i);
                        LOG.debug(explrObject.toString());
                        HashMap<String, String> resultHash = new HashMap<String, String>();
                        Iterator<String> nameItr = explrObject.keys();
                        while (nameItr.hasNext()) {
                            String name = nameItr.next();
                            if (name.equals("KEY")) {
                                resultHash.put("", explrObject.getString(name));
                            } else {
                                resultHash.put(name, explrObject.getString(name));
                            }
                        }
                        result.add(resultHash);
                    }
                } catch (JSONException ex) {
                    java.util.logging.Logger.getLogger(PropertyService.class.getName()).log(Level.SEVERE, null, ex);
                    LOG.error(ex);
                }
                testCaseExecutionData.setDataLibRawData(result);
                // Record result in filessytem.
                recorderService.recordTestDataLibProperty(tCExecution.getId(), testCaseCountryProperty.getProperty(), 1, result);
            }
        }
    } catch (CerberusEventException ex) {
        LOG.error(ex.toString());
        testCaseExecutionData.setEnd(new Date().getTime());
        testCaseExecutionData.setPropertyResultMessage(ex.getMessageError());
    }
    testCaseExecutionData.setEnd(new Date().getTime());
    if (LOG.isDebugEnabled()) {
        LOG.debug("Finished to calculate Property : '" + testCaseCountryProperty.getProperty() + "'");
    }
}
Also used : HashMap(java.util.HashMap) MessageEvent(org.cerberus.engine.entity.MessageEvent) TestCaseExecutionData(org.cerberus.crud.entity.TestCaseExecutionData) IFactoryTestCaseExecutionData(org.cerberus.crud.factory.IFactoryTestCaseExecutionData) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) AnswerItem(org.cerberus.util.answer.AnswerItem) Date(java.util.Date) CerberusEventException(org.cerberus.exception.CerberusEventException) JSONObject(org.json.JSONObject) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) IPropertyService(org.cerberus.engine.gwt.IPropertyService) SimpleDateFormat(java.text.SimpleDateFormat)

Example 14 with CerberusEventException

use of org.cerberus.exception.CerberusEventException in project cerberus-source by cerberustesting.

the class ExecutionRunService method executeStep.

private TestCaseStepExecution executeStep(TestCaseStepExecution testCaseStepExecution, TestCaseExecution tcExecution) {
    long runID = testCaseStepExecution.getId();
    String logPrefix = runID + " - ";
    AnswerItem<String> answerDecode = new AnswerItem();
    // Initialise the Step Data List.
    List<TestCaseExecutionData> myStepDataList = new ArrayList<TestCaseExecutionData>();
    testCaseStepExecution.setTestCaseExecutionDataList(myStepDataList);
    // Initialise the Data List used to enter the action.
    /**
     * Iterate Actions
     */
    List<TestCaseStepAction> testCaseStepActionList = testCaseStepExecution.getTestCaseStep().getTestCaseStepAction();
    LOG.debug("Getting list of actions of the step. " + testCaseStepActionList.size() + " action(s) to perform.");
    for (TestCaseStepAction testCaseStepAction : testCaseStepActionList) {
        /**
         * Start Execution of TestCaseStepAction
         */
        long startAction = new Date().getTime();
        /**
         * Create and Register TestCaseStepActionExecution.
         */
        TestCaseStepActionExecution testCaseStepActionExecution = factoryTestCaseStepActionExecution.create(testCaseStepExecution.getId(), testCaseStepAction.getTest(), testCaseStepAction.getTestCase(), testCaseStepAction.getStep(), testCaseStepExecution.getIndex(), testCaseStepAction.getSequence(), testCaseStepAction.getSort(), null, null, testCaseStepAction.getConditionOper(), testCaseStepAction.getConditionVal1(), testCaseStepAction.getConditionVal2(), testCaseStepAction.getConditionVal1(), testCaseStepAction.getConditionVal2(), testCaseStepAction.getAction(), testCaseStepAction.getValue1(), testCaseStepAction.getValue2(), testCaseStepAction.getValue1(), testCaseStepAction.getValue2(), testCaseStepAction.getForceExeStatus(), startAction, 0, startAction, 0, new MessageEvent(MessageEventEnum.ACTION_PENDING), testCaseStepAction.getDescription(), testCaseStepAction, testCaseStepExecution);
        this.testCaseStepActionExecutionService.insertTestCaseStepActionExecution(testCaseStepActionExecution);
        /**
         * We populate the TestCase Action List
         */
        testCaseStepExecution.addTestCaseStepActionExecutionList(testCaseStepActionExecution);
        /**
         * If execution is not manual, evaluate the condition at the action
         * level
         */
        AnswerItem<Boolean> conditionAnswer;
        boolean conditionDecodeError = false;
        if (!tcExecution.getManualExecution().equals("Y")) {
            try {
                answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getConditionVal1(), tcExecution, null, false);
                testCaseStepActionExecution.setConditionVal1((String) answerDecode.getItem());
                if (!(answerDecode.isCodeStringEquals("OK"))) {
                    // If anything wrong with the decode --> we stop here with decode message in the action result.
                    testCaseStepActionExecution.setActionResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Action Condition Value1"));
                    testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));
                    testCaseStepActionExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());
                    testCaseStepActionExecution.setEnd(new Date().getTime());
                    LOG.debug("Action interupted due to decode 'Action Condition Value1' Error.");
                    conditionDecodeError = true;
                }
            } catch (CerberusEventException cex) {
                LOG.warn(cex);
            }
            try {
                answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getConditionVal2(), tcExecution, null, false);
                testCaseStepActionExecution.setConditionVal2((String) answerDecode.getItem());
                if (!(answerDecode.isCodeStringEquals("OK"))) {
                    // If anything wrong with the decode --> we stop here with decode message in the action result.
                    testCaseStepActionExecution.setActionResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Action Condition Value2"));
                    testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));
                    testCaseStepActionExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());
                    testCaseStepActionExecution.setEnd(new Date().getTime());
                    LOG.debug("Action interupted due to decode 'Action Condition Value2' Error.");
                    conditionDecodeError = true;
                }
            } catch (CerberusEventException cex) {
                LOG.warn(cex);
            }
        }
        if (!(conditionDecodeError)) {
            conditionAnswer = this.conditionService.evaluateCondition(testCaseStepActionExecution.getConditionOper(), testCaseStepActionExecution.getConditionVal1(), testCaseStepActionExecution.getConditionVal2(), tcExecution);
            boolean execute_Action = (boolean) conditionAnswer.getItem();
            /**
             * If condition OK or if manual execution, then execute the
             * action
             */
            if (conditionAnswer.getResultMessage().getMessage().getCodeString().equals("PE") || tcExecution.getManualExecution().equals("Y")) {
                // Execute or not the action here.
                if (execute_Action || tcExecution.getManualExecution().equals("Y")) {
                    LOG.debug("Executing action : " + testCaseStepActionExecution.getAction() + " with val1 : " + testCaseStepActionExecution.getValue1() + " and val2 : " + testCaseStepActionExecution.getValue2());
                    /**
                     * We execute the Action
                     */
                    testCaseStepActionExecution = this.executeAction(testCaseStepActionExecution, tcExecution);
                    /**
                     * If Action or property reported to stop the testcase,
                     * we stop it and update the step with the message.
                     */
                    testCaseStepExecution.setStopExecution(testCaseStepActionExecution.isStopExecution());
                    if ((!(testCaseStepActionExecution.getExecutionResultMessage().equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_OK)))) && (!(testCaseStepActionExecution.getExecutionResultMessage().equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_TESTEXECUTING))))) {
                        testCaseStepExecution.setExecutionResultMessage(testCaseStepActionExecution.getExecutionResultMessage());
                        testCaseStepExecution.setStepResultMessage(testCaseStepActionExecution.getActionResultMessage());
                    }
                    if (testCaseStepActionExecution.isStopExecution()) {
                        break;
                    }
                } else {
                    // We don't execute the action and record a generic execution.
                    /**
                     * Record Screenshot, PageSource
                     */
                    testCaseStepActionExecution.addFileList(recorderService.recordExecutionInformationAfterStepActionandControl(testCaseStepActionExecution, null));
                    LOG.debug("Registering Action : " + testCaseStepActionExecution.getAction());
                    // We change the Action message only if the action is not executed due to condition.
                    MessageEvent actionMes = new MessageEvent(MessageEventEnum.CONDITION_TESTCASEACTION_NOTEXECUTED);
                    testCaseStepActionExecution.setActionResultMessage(actionMes);
                    testCaseStepActionExecution.setReturnMessage(testCaseStepActionExecution.getReturnMessage().replace("%COND%", testCaseStepActionExecution.getConditionOper()).replace("%MESSAGE%", conditionAnswer.getResultMessage().getDescription()));
                    testCaseStepActionExecution.setEnd(new Date().getTime());
                    this.testCaseStepActionExecutionService.updateTestCaseStepActionExecution(testCaseStepActionExecution);
                    LOG.debug("Registered Action");
                }
            } else {
                // Error when performing the condition evaluation. We force no execution (false)
                MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_CONDITION);
                mes.setDescription(mes.getDescription().replace("%COND%", testCaseStepActionExecution.getConditionOper()).replace("%AREA%", "action ").replace("%MES%", conditionAnswer.getResultMessage().getDescription()));
                testCaseStepActionExecution.setExecutionResultMessage(mes);
                testCaseStepExecution.setExecutionResultMessage(testCaseStepActionExecution.getExecutionResultMessage());
                testCaseStepExecution.setStopExecution(testCaseStepActionExecution.isStopExecution());
                testCaseStepActionExecution.setActionResultMessage(new MessageEvent(MessageEventEnum.CONDITION_TESTCASEACTION_FAILED).resolveDescription("AREA", "").resolveDescription("COND", testCaseStepActionExecution.getConditionOper()).resolveDescription("MESSAGE", conditionAnswer.getResultMessage().getDescription()));
                testCaseStepExecution.setStepResultMessage(new MessageEvent(MessageEventEnum.CONDITION_TESTCASESTEP_FAILED).resolveDescription("AREA", "action ").resolveDescription("COND", testCaseStepActionExecution.getConditionOper()).resolveDescription("MESSAGE", conditionAnswer.getResultMessage().getDescription()));
                testCaseStepActionExecution.setEnd(new Date().getTime());
                this.testCaseStepActionExecutionService.updateTestCaseStepActionExecution(testCaseStepActionExecution);
                LOG.debug("Action interupted due to condition error.");
                // We stop any further Action execution.
                break;
            }
        } else {
            testCaseStepActionExecution.setEnd(new Date().getTime());
            testCaseStepExecution.setExecutionResultMessage(testCaseStepActionExecution.getExecutionResultMessage());
            testCaseStepExecution.setStepResultMessage(testCaseStepActionExecution.getActionResultMessage());
            testCaseStepExecution.setStopExecution(testCaseStepActionExecution.isStopExecution());
            this.testCaseStepActionExecutionService.updateTestCaseStepActionExecution(testCaseStepActionExecution);
            LOG.debug("Registered Action");
            if (testCaseStepActionExecution.isStopExecution()) {
                break;
            }
        }
        /**
         * Log TestCaseStepActionExecution
         */
        if (tcExecution.getVerbose() > 0) {
            LOG.info(testCaseStepActionExecution.toJson(false, true));
        }
    }
    testCaseStepExecution.setEnd(new Date().getTime());
    this.testCaseStepExecutionService.updateTestCaseStepExecution(testCaseStepExecution);
    // Websocket --> we refresh the corresponding Detail Execution pages attached to this execution.
    if (tcExecution.isCerberus_featureflipping_activatewebsocketpush()) {
        TestCaseExecutionEndPoint.getInstance().send(tcExecution, false);
    }
    return testCaseStepExecution;
}
Also used : TestCaseStepAction(org.cerberus.crud.entity.TestCaseStepAction) MessageEvent(org.cerberus.engine.entity.MessageEvent) TestCaseExecutionData(org.cerberus.crud.entity.TestCaseExecutionData) ArrayList(java.util.ArrayList) TestCaseStepActionExecution(org.cerberus.crud.entity.TestCaseStepActionExecution) IFactoryTestCaseStepActionExecution(org.cerberus.crud.factory.IFactoryTestCaseStepActionExecution) AnswerItem(org.cerberus.util.answer.AnswerItem) Date(java.util.Date) CerberusEventException(org.cerberus.exception.CerberusEventException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral)

Example 15 with CerberusEventException

use of org.cerberus.exception.CerberusEventException in project cerberus-source by cerberustesting.

the class ExecutionRunService method executeAction.

private TestCaseStepActionExecution executeAction(TestCaseStepActionExecution testCaseStepActionExecution, TestCaseExecution tcExecution) {
    LOG.debug("Starting execute Action : " + testCaseStepActionExecution.getAction());
    AnswerItem<String> answerDecode = new AnswerItem();
    /**
     * If execution is not manual, do action and record files
     */
    if (!tcExecution.getManualExecution().equals("Y")) {
        testCaseStepActionExecution = this.actionService.doAction(testCaseStepActionExecution);
        /**
         * Record Screenshot, PageSource
         */
        try {
            testCaseStepActionExecution.addFileList(recorderService.recordExecutionInformationAfterStepActionandControl(testCaseStepActionExecution, null));
        } catch (Exception ex) {
            LOG.warn("Unable to record Screenshot/PageSource : " + ex.toString());
        }
    } else {
        /**
         * If execution manual, set Action result message as notExecuted
         */
        testCaseStepActionExecution.setActionResultMessage(new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED));
        testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_NE));
        testCaseStepActionExecution.setEnd(new Date().getTime());
    }
    /**
     * Register Action in database
     */
    LOG.debug("Registering Action : " + testCaseStepActionExecution.getAction());
    this.testCaseStepActionExecutionService.updateTestCaseStepActionExecution(testCaseStepActionExecution);
    LOG.debug("Registered Action");
    if (testCaseStepActionExecution.isStopExecution()) {
        return testCaseStepActionExecution;
    }
    // As controls are associated with an action, the current state for the action is stored in order to restore it
    // if some property is not defined for the country
    MessageEvent actionMessage = testCaseStepActionExecution.getActionResultMessage();
    MessageGeneral excutionResultMessage = testCaseStepActionExecution.getExecutionResultMessage();
    /**
     * Iterate Control
     */
    List<TestCaseStepActionControl> tcsacList = testCaseStepActionExecution.getTestCaseStepAction().getTestCaseStepActionControl();
    for (TestCaseStepActionControl testCaseStepActionControl : tcsacList) {
        /**
         * Start Execution of TestCAseStepActionControl
         */
        long startControl = new Date().getTime();
        /**
         * Create and Register TestCaseStepActionControlExecution
         */
        LOG.debug("Creating TestCaseStepActionControlExecution");
        TestCaseStepActionControlExecution testCaseStepActionControlExecution = factoryTestCaseStepActionControlExecution.create(testCaseStepActionExecution.getId(), testCaseStepActionControl.getTest(), testCaseStepActionControl.getTestCase(), testCaseStepActionControl.getStep(), testCaseStepActionExecution.getIndex(), testCaseStepActionControl.getSequence(), testCaseStepActionControl.getControlSequence(), testCaseStepActionControl.getSort(), null, null, testCaseStepActionControl.getConditionOper(), testCaseStepActionControl.getConditionVal1(), testCaseStepActionControl.getConditionVal2(), testCaseStepActionControl.getConditionVal1(), testCaseStepActionControl.getConditionVal2(), testCaseStepActionControl.getControl(), testCaseStepActionControl.getValue1(), testCaseStepActionControl.getValue2(), testCaseStepActionControl.getValue1(), testCaseStepActionControl.getValue2(), testCaseStepActionControl.getFatal(), startControl, 0, 0, 0, testCaseStepActionControl.getDescription(), testCaseStepActionExecution, new MessageEvent(MessageEventEnum.CONTROL_PENDING));
        this.testCaseStepActionControlExecutionService.insertTestCaseStepActionControlExecution(testCaseStepActionControlExecution);
        LOG.debug("Executing control : " + testCaseStepActionControlExecution.getControlSequence() + " type : " + testCaseStepActionControlExecution.getControl());
        /**
         * We populate the TestCase Control List
         */
        testCaseStepActionExecution.addTestCaseStepActionExecutionList(testCaseStepActionControlExecution);
        // Evaluate the condition at the control level.
        AnswerItem<Boolean> conditionAnswer;
        boolean conditionDecodeError = false;
        if (!tcExecution.getManualExecution().equals("Y")) {
            try {
                answerDecode = variableService.decodeStringCompletly(testCaseStepActionControlExecution.getConditionVal1(), tcExecution, null, false);
                testCaseStepActionControlExecution.setConditionVal1((String) answerDecode.getItem());
                if (!(answerDecode.isCodeStringEquals("OK"))) {
                    // If anything wrong with the decode --> we stop here with decode message in the action result.
                    testCaseStepActionControlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Condition Value1"));
                    testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));
                    testCaseStepActionControlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());
                    testCaseStepActionControlExecution.setEnd(new Date().getTime());
                    LOG.debug("Control interupted due to decode 'Control Condition Value1' Error.");
                    conditionDecodeError = true;
                }
            } catch (CerberusEventException cex) {
                LOG.warn(cex);
            }
            try {
                answerDecode = variableService.decodeStringCompletly(testCaseStepActionControlExecution.getConditionVal2(), tcExecution, null, false);
                testCaseStepActionControlExecution.setConditionVal2((String) answerDecode.getItem());
                if (!(answerDecode.isCodeStringEquals("OK"))) {
                    // If anything wrong with the decode --> we stop here with decode message in the action result.
                    testCaseStepActionControlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Condition Value2"));
                    testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));
                    testCaseStepActionControlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());
                    testCaseStepActionControlExecution.setEnd(new Date().getTime());
                    LOG.debug("Control interupted due to decode 'Control Condition Value2' Error.");
                    conditionDecodeError = true;
                }
            } catch (CerberusEventException cex) {
                LOG.warn(cex);
            }
        }
        if (!(conditionDecodeError)) {
            conditionAnswer = this.conditionService.evaluateCondition(testCaseStepActionControlExecution.getConditionOper(), testCaseStepActionControlExecution.getConditionVal1(), testCaseStepActionControlExecution.getConditionVal2(), tcExecution);
            boolean execute_Control = (boolean) conditionAnswer.getItem();
            /**
             * If condition OK or if manual execution, then execute the
             * control
             */
            if (conditionAnswer.getResultMessage().getMessage().getCodeString().equals("PE") || tcExecution.getManualExecution().equals("Y")) {
                if (execute_Control || tcExecution.getManualExecution().equals("Y")) {
                    /**
                     * We execute the control
                     */
                    testCaseStepActionControlExecution = executeControl(testCaseStepActionControlExecution, tcExecution);
                    /**
                     * We update the Action with the execution message and
                     * stop flag from the control. We update the status only
                     * if the control is not OK. This is to prevent moving
                     * the status to OK when it should stay KO when a
                     * control failed previously.
                     */
                    testCaseStepActionExecution.setStopExecution(testCaseStepActionControlExecution.isStopExecution());
                    if (!(testCaseStepActionControlExecution.getControlResultMessage().equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS)))) {
                        // NA is a special case of not having success while calculating the property; the action shouldn't be stopped
                        if (testCaseStepActionControlExecution.getControlResultMessage().equals(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_NO_PROPERTY_DEFINITION))) {
                            // restores the messages information if the property is not defined for the country
                            testCaseStepActionExecution.setActionResultMessage(actionMessage);
                            testCaseStepActionExecution.setExecutionResultMessage(excutionResultMessage);
                        } else {
                            testCaseStepActionExecution.setExecutionResultMessage(testCaseStepActionControlExecution.getExecutionResultMessage());
                            testCaseStepActionExecution.setActionResultMessage(testCaseStepActionControlExecution.getControlResultMessage());
                        }
                    }
                    /**
                     * If Control reported to stop the testcase, we stop it.
                     */
                    if (testCaseStepActionControlExecution.isStopExecution()) {
                        break;
                    }
                } else {
                    // We don't execute the control and record a generic execution.
                    /**
                     * Record Screenshot, PageSource
                     */
                    testCaseStepActionControlExecution.addFileList(recorderService.recordExecutionInformationAfterStepActionandControl(testCaseStepActionControlExecution.getTestCaseStepActionExecution(), testCaseStepActionControlExecution));
                    /**
                     * Register Control in database
                     */
                    LOG.debug("Registering Control : " + testCaseStepActionControlExecution.getControlSequence());
                    // We change the Action message only if the action is not executed due to condition.
                    MessageEvent controlMes = new MessageEvent(MessageEventEnum.CONDITION_TESTCASECONTROL_NOTEXECUTED);
                    testCaseStepActionControlExecution.setControlResultMessage(controlMes);
                    testCaseStepActionControlExecution.setReturnMessage(testCaseStepActionControlExecution.getReturnMessage().replace("%COND%", testCaseStepActionControlExecution.getConditionOper()).replace("%MESSAGE%", conditionAnswer.getResultMessage().getDescription()));
                    testCaseStepActionControlExecution.setEnd(new Date().getTime());
                    this.testCaseStepActionControlExecutionService.updateTestCaseStepActionControlExecution(testCaseStepActionControlExecution);
                    LOG.debug("Registered Control");
                    // Websocket --> we refresh the corresponding Detail Execution pages attached to this execution.
                    if (tcExecution.isCerberus_featureflipping_activatewebsocketpush()) {
                        TestCaseExecutionEndPoint.getInstance().send(tcExecution, false);
                    }
                }
            } else {
                // Error when performing the condition evaluation. We force no execution (false)
                MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_CONDITION);
                mes.setDescription(mes.getDescription().replace("%COND%", testCaseStepActionControlExecution.getConditionOper()).replace("%AREA%", "control ").replace("%MES%", conditionAnswer.getResultMessage().getDescription()));
                testCaseStepActionControlExecution.setExecutionResultMessage(mes);
                testCaseStepActionExecution.setExecutionResultMessage(mes);
                testCaseStepActionControlExecution.setControlResultMessage(new MessageEvent(MessageEventEnum.CONDITION_TESTCASECONTROL_FAILED).resolveDescription("AREA", "").resolveDescription("COND", testCaseStepActionControlExecution.getConditionOper()).resolveDescription("MESSAGE", conditionAnswer.getResultMessage().getDescription()));
                testCaseStepActionExecution.setActionResultMessage(new MessageEvent(MessageEventEnum.CONDITION_TESTCASEACTION_FAILED).resolveDescription("AREA", "control ").resolveDescription("COND", testCaseStepActionControlExecution.getConditionOper()).resolveDescription("MESSAGE", conditionAnswer.getResultMessage().getDescription()));
                testCaseStepActionControlExecution.setEnd(new Date().getTime());
                this.testCaseStepActionControlExecutionService.updateTestCaseStepActionControlExecution(testCaseStepActionControlExecution);
                LOG.debug("Control interupted due to condition error.");
                // We stop any further Control execution.
                break;
            }
        } else {
            testCaseStepActionControlExecution.setEnd(new Date().getTime());
            testCaseStepActionExecution.setExecutionResultMessage(testCaseStepActionControlExecution.getExecutionResultMessage());
            testCaseStepActionExecution.setActionResultMessage(testCaseStepActionControlExecution.getControlResultMessage());
            this.testCaseStepActionControlExecutionService.updateTestCaseStepActionControlExecution(testCaseStepActionControlExecution);
            LOG.debug("Registered Control");
            // Websocket --> we refresh the corresponding Detail Execution pages attached to this execution.
            if (tcExecution.isCerberus_featureflipping_activatewebsocketpush()) {
                TestCaseExecutionEndPoint.getInstance().send(tcExecution, false);
            }
        }
        /**
         * Log TestCaseStepActionControlExecution
         */
        if (tcExecution.getVerbose() > 0) {
            LOG.info(testCaseStepActionControlExecution.toJson(false, true));
        }
    }
    // Websocket --> we refresh the corresponding Detail Execution pages attached to this execution.
    if (tcExecution.isCerberus_featureflipping_activatewebsocketpush()) {
        TestCaseExecutionEndPoint.getInstance().send(tcExecution, false);
    }
    LOG.debug("Finished execute Action : " + testCaseStepActionExecution.getAction());
    return testCaseStepActionExecution;
}
Also used : MessageEvent(org.cerberus.engine.entity.MessageEvent) AnswerItem(org.cerberus.util.answer.AnswerItem) CerberusEventException(org.cerberus.exception.CerberusEventException) CerberusException(org.cerberus.exception.CerberusException) WebDriverException(org.openqa.selenium.WebDriverException) Date(java.util.Date) CerberusEventException(org.cerberus.exception.CerberusEventException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) TestCaseStepActionControlExecution(org.cerberus.crud.entity.TestCaseStepActionControlExecution) IFactoryTestCaseStepActionControlExecution(org.cerberus.crud.factory.IFactoryTestCaseStepActionControlExecution) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl)

Aggregations

CerberusEventException (org.cerberus.exception.CerberusEventException)36 MessageEvent (org.cerberus.engine.entity.MessageEvent)35 Identifier (org.cerberus.engine.entity.Identifier)15 AnswerItem (org.cerberus.util.answer.AnswerItem)11 ArrayList (java.util.ArrayList)7 CerberusException (org.cerberus.exception.CerberusException)7 Date (java.util.Date)6 MessageGeneral (org.cerberus.engine.entity.MessageGeneral)6 HashMap (java.util.HashMap)3 AppService (org.cerberus.crud.entity.AppService)3 CountryEnvironmentDatabase (org.cerberus.crud.entity.CountryEnvironmentDatabase)3 JSONException (org.json.JSONException)3 NoSuchElementException (org.openqa.selenium.NoSuchElementException)3 WebDriverException (org.openqa.selenium.WebDriverException)3 List (java.util.List)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 TestCase (org.cerberus.crud.entity.TestCase)2 TestCaseExecution (org.cerberus.crud.entity.TestCaseExecution)2 TestCaseExecutionData (org.cerberus.crud.entity.TestCaseExecutionData)2 AnswerList (org.cerberus.util.answer.AnswerList)2