Search in sources :

Example 1 with CerberusEventException

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

the class WebDriverService method doSeleniumActionSelect.

@Override
public MessageEvent doSeleniumActionSelect(Session session, Identifier object, Identifier property) {
    MessageEvent message;
    try {
        Select select;
        try {
            AnswerItem answer = this.getSeleniumElement(session, object, true, true);
            if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {
                WebElement webElement = (WebElement) answer.getItem();
                if (webElement != null) {
                    select = new Select(webElement);
                    this.selectRequestedOption(select, property, object.getIdentifier() + "=" + object.getLocator());
                    message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SELECT);
                    message.setDescription(message.getDescription().replace("%ELEMENT%", object.getIdentifier() + "=" + object.getLocator()));
                    message.setDescription(message.getDescription().replace("%DATA%", property.getIdentifier() + "=" + property.getLocator()));
                    return message;
                }
            }
            return answer.getResultMessage();
        } catch (NoSuchElementException exception) {
            message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELECT_NO_SUCH_ELEMENT);
            message.setDescription(message.getDescription().replace("%ELEMENT%", object.getIdentifier() + "=" + object.getLocator()));
            LOG.debug(exception.toString());
            return message;
        } catch (TimeoutException exception) {
            message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);
            message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));
            LOG.warn(exception.toString());
            return message;
        }
    } catch (CerberusEventException ex) {
        LOG.warn(ex);
        return ex.getMessageError();
    }
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Select(org.openqa.selenium.support.ui.Select) WebElement(org.openqa.selenium.WebElement) AnswerItem(org.cerberus.util.answer.AnswerItem) NoSuchElementException(org.openqa.selenium.NoSuchElementException) TimeoutException(org.openqa.selenium.TimeoutException)

Example 2 with CerberusEventException

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

the class WebDriverService method selectRequestedOption.

private void selectRequestedOption(Select select, Identifier property, String element) throws CerberusEventException {
    MessageEvent message;
    try {
        if (property.getIdentifier().equalsIgnoreCase("value")) {
            select.selectByValue(property.getLocator());
        } else if (property.getIdentifier().equalsIgnoreCase("label")) {
            select.selectByVisibleText(property.getLocator());
        } else if (property.getIdentifier().equalsIgnoreCase("index") && StringUtil.isInteger(property.getLocator())) {
            select.selectByIndex(Integer.parseInt(property.getLocator()));
        } else if (property.getIdentifier().equalsIgnoreCase("regexValue") || property.getIdentifier().equalsIgnoreCase("regexIndex") || property.getIdentifier().equalsIgnoreCase("regexLabel")) {
            java.util.List<WebElement> list = select.getOptions();
            if (property.getIdentifier().equalsIgnoreCase("regexValue")) {
                for (WebElement option : list) {
                    String optionValue = option.getAttribute("value");
                    Pattern pattern = Pattern.compile(property.getLocator());
                    Matcher matcher = pattern.matcher(optionValue);
                    if (matcher.find()) {
                        select.selectByValue(optionValue);
                    }
                }
            } else if (property.getIdentifier().equalsIgnoreCase("regexLabel")) {
                for (WebElement option : list) {
                    String optionLabel = option.getText();
                    Pattern pattern = Pattern.compile(property.getLocator());
                    Matcher matcher = pattern.matcher(optionLabel);
                    if (matcher.find()) {
                        select.selectByVisibleText(optionLabel);
                    }
                }
            } else if (property.getIdentifier().equalsIgnoreCase("regexIndex") && StringUtil.isInteger(property.getLocator())) {
                for (WebElement option : list) {
                    Integer id = 0;
                    Pattern pattern = Pattern.compile(property.getLocator());
                    Matcher matcher = pattern.matcher(id.toString());
                    if (matcher.find()) {
                        select.selectByIndex(Integer.parseInt(property.getLocator()));
                    }
                    id++;
                }
            }
        } else {
            message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELECT_NO_IDENTIFIER);
            message.setDescription(message.getDescription().replace("%IDENTIFIER%", property.getIdentifier()));
            throw new CerberusEventException(message);
        }
    } catch (NoSuchElementException exception) {
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELECT_NO_SUCH_VALUE);
        message.setDescription(message.getDescription().replace("%ELEMENT%", element));
        message.setDescription(message.getDescription().replace("%DATA%", property.getIdentifier() + "=" + property.getLocator()));
        throw new CerberusEventException(message);
    } catch (WebDriverException exception) {
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELENIUM_CONNECTIVITY);
        message.setDescription(message.getDescription().replace("%ERROR%", exception.getMessage().split("\n")[0]));
        LOG.warn(exception.toString());
        throw new CerberusEventException(message);
    } catch (PatternSyntaxException e) {
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELECT_REGEX_INVALIDPATERN);
        message.setDescription(message.getDescription().replace("%PATERN%", property.getLocator()));
        message.setDescription(message.getDescription().replace("%ERROR%", e.getMessage()));
        throw new CerberusEventException(message);
    }
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) MessageEvent(org.cerberus.engine.entity.MessageEvent) List(java.util.List) ArrayList(java.util.ArrayList) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException) WebDriverException(org.openqa.selenium.WebDriverException) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 3 with CerberusEventException

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

the class DataLibService method getFromDataLib.

@Override
public AnswerList<HashMap<String, String>> getFromDataLib(TestDataLib lib, TestCaseCountryProperties testCaseCountryProperty, TestCaseExecution tCExecution, TestCaseExecutionData testCaseExecutionData) {
    AnswerItem<HashMap<String, String>> resultColumns;
    AnswerList<HashMap<String, String>> resultData;
    AnswerList<HashMap<String, String>> result;
    MessageEvent msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS);
    // Length contains the nb of rows that the result must fetch. If defined at 0 we force at 1.
    Integer nbRowsRequested = 0;
    try {
        nbRowsRequested = Integer.parseInt(testCaseExecutionData.getLength());
        if (nbRowsRequested < 1) {
            nbRowsRequested = 1;
        }
    } catch (NumberFormatException e) {
        LOG.error(e.toString());
    }
    /**
     * Gets the list of columns (subdata) to get from TestDataLibData.
     */
    resultColumns = getSubDataFromType(lib);
    HashMap<String, String> columnList = null;
    // Manage error message.
    if (resultColumns.getResultMessage().getCode() == MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_SUBDATA.getCode()) {
        AnswerItem answerDecode = new AnswerItem();
        columnList = resultColumns.getItem();
        // Now that we have the list of column with subdata and value, we can try to decode it.
        if (columnList != null) {
            for (Map.Entry<String, String> entry : columnList.entrySet()) {
                // Loop on all Column in order to decode all values.
                // SubData
                String eKey = entry.getKey();
                // Parsing Answer
                String eValue = entry.getValue();
                try {
                    answerDecode = variableService.decodeStringCompletly(eValue, tCExecution, null, false);
                    columnList.put(eKey, (String) answerDecode.getItem());
                    if (!(answerDecode.isCodeStringEquals("OK"))) {
                        // If anything wrong with the decode --> we stop here with decode message in the action result.
                        result = new AnswerList();
                        result.setDataList(null);
                        msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_SUBDATAISSUE);
                        msg.setDescription(msg.getDescription().replace("%SUBDATAMESSAGE%", answerDecode.getMessageDescription().replace("%FIELD%", "Column value '" + eValue + "'")));
                        result.setResultMessage(msg);
                        LOG.debug("Datalib interupted due to decode 'column value' Error.");
                        return result;
                    }
                } catch (CerberusEventException cex) {
                    LOG.warn(cex);
                }
            }
        }
    } else if (resultColumns.getResultMessage().getCode() == MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SUBDATA.getCode()) {
        result = new AnswerList();
        result.setDataList(null);
        msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_SUBDATAISSUE);
        msg.setDescription(msg.getDescription().replace("%SUBDATAMESSAGE%", resultColumns.getMessageDescription()));
        result.setResultMessage(msg);
        return result;
    }
    /**
     * Get List of DataObject in a format List<Map<String>> - 1 item per row
     * with key = column and value = content
     */
    int rowLimit = testCaseCountryProperty.getRowLimit();
    if (testCaseCountryProperty.getNature().equalsIgnoreCase(TestCaseCountryProperties.NATURE_STATIC)) {
        // If Nature of the property is static, we don't need to getch more than reqested record.
        rowLimit = nbRowsRequested;
    }
    resultData = getDataObjectList(lib, columnList, rowLimit, tCExecution, testCaseExecutionData);
    // Manage error message.
    if (resultData.getResultMessage().getCode() == MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_DATA.getCode()) {
        if (resultData.getDataList().size() < nbRowsRequested) {
            // We check if the data provided is enought to provide the answer.
            result = new AnswerList();
            result.setDataList(null);
            msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_NOTENOUGHTDATA);
            msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription()).replace("%NBREQUEST%", Integer.toString(nbRowsRequested)));
            result.setResultMessage(msg);
            return result;
        }
    } else if (resultData.getResultMessage().getCode() == MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GENERIC_NODATA.getCode()) {
        result = new AnswerList();
        result.setDataList(null);
        msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_NODATA);
        msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription()));
        result.setResultMessage(msg);
        return result;
    } else {
        result = new AnswerList();
        result.setDataList(null);
        msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_DATAISSUE);
        msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription()));
        result.setResultMessage(msg);
        return result;
    }
    /**
     * Filter out the result from requested rows depending on the nature
     */
    result = filterWithNature(testCaseCountryProperty.getNature(), resultData, tCExecution, testCaseCountryProperty, nbRowsRequested);
    // Manage error message.
    if (result.getResultMessage().getCode() == MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_NATURE.getCode()) {
        msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB_GLOBAL);
        msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription()).replace("%FILTERNATUREMESSAGE%", result.getMessageDescription()));
        result.setResultMessage(msg);
    } else if (result.getResultMessage().getCode() == MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GENERIC_NATURENOMORERECORD.getCode()) {
        // if the script does not return
        result.setDataList(null);
        msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_NODATALEFT);
        msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription()).replace("%FILTERNATUREMESSAGE%", result.getMessageDescription()));
        result.setResultMessage(msg);
    } else {
        // other error had occured
        result.setDataList(null);
        msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_GLOBAL_GENERIC);
        msg.setDescription(msg.getDescription().replace("%DATAMESSAGE%", resultData.getMessageDescription()).replace("%FILTERNATUREMESSAGE%", result.getMessageDescription()));
        result.setResultMessage(msg);
    }
    return result;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) HashMap(java.util.HashMap) MessageEvent(org.cerberus.engine.entity.MessageEvent) AnswerItem(org.cerberus.util.answer.AnswerItem) CerberusEventException(org.cerberus.exception.CerberusEventException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with CerberusEventException

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

the class ActionService method doAction.

@Override
public TestCaseStepActionExecution doAction(TestCaseStepActionExecution testCaseStepActionExecution) {
    MessageEvent res;
    TestCaseExecution tCExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();
    AnswerItem<String> answerDecode = new AnswerItem();
    /**
     * Decode the object field before doing the action.
     */
    try {
        // When starting a new action, we reset the property list that was already calculated.
        tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList());
        answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getValue1(), tCExecution, testCaseStepActionExecution, false);
        testCaseStepActionExecution.setValue1((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 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 Value1' Error.");
            return testCaseStepActionExecution;
        }
    } catch (CerberusEventException cex) {
        testCaseStepActionExecution.setActionResultMessage(cex.getMessageError());
        testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(cex.getMessageError().getMessage()));
        testCaseStepActionExecution.setEnd(new Date().getTime());
        return testCaseStepActionExecution;
    }
    try {
        // When starting a new action, we reset the property list that was already calculated.
        tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList());
        answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getValue2(), tCExecution, testCaseStepActionExecution, false);
        testCaseStepActionExecution.setValue2((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 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 Value2' Error.");
            return testCaseStepActionExecution;
        }
    } catch (CerberusEventException cex) {
        testCaseStepActionExecution.setActionResultMessage(cex.getMessageError());
        testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(cex.getMessageError().getMessage()));
        testCaseStepActionExecution.setEnd(new Date().getTime());
        return testCaseStepActionExecution;
    }
    /**
     * Timestamp starts after the decode. TODO protect when property is
     * null.
     */
    testCaseStepActionExecution.setStart(new Date().getTime());
    String value1 = testCaseStepActionExecution.getValue1();
    String value2 = testCaseStepActionExecution.getValue2();
    String propertyName = testCaseStepActionExecution.getPropertyName();
    LOG.debug("Doing Action : " + testCaseStepActionExecution.getAction() + " with value1 : " + value1 + " and value2 : " + value2);
    // When starting a new action, we reset the property list that was already calculated.
    tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList());
    try {
        switch(testCaseStepActionExecution.getAction()) {
            case TestCaseStepAction.ACTION_CLICK:
                res = this.doActionClick(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_MOUSELEFTBUTTONPRESS:
                res = this.doActionMouseLeftButtonPress(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_MOUSELEFTBUTTONRELEASE:
                res = this.doActionMouseLeftButtonRelease(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_DOUBLECLICK:
                res = this.doActionDoubleClick(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_RIGHTCLICK:
                res = this.doActionRightClick(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_MOUSEOVER:
                res = this.doActionMouseOver(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_FOCUSTOIFRAME:
                res = this.doActionFocusToIframe(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_FOCUSDEFAULTIFRAME:
                res = this.doActionFocusDefaultIframe(tCExecution);
                break;
            case TestCaseStepAction.ACTION_SWITCHTOWINDOW:
                res = this.doActionSwitchToWindow(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_MANAGEDIALOG:
                res = this.doActionManageDialog(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_OPENURLWITHBASE:
                res = this.doActionOpenURL(tCExecution, value1, value2, true);
                break;
            case TestCaseStepAction.ACTION_OPENURLLOGIN:
                testCaseStepActionExecution.setValue1(testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getCountryEnvironmentParameters().getUrlLogin());
                res = this.doActionUrlLogin(tCExecution);
                break;
            case TestCaseStepAction.ACTION_OPENURL:
                res = this.doActionOpenURL(tCExecution, value1, value2, false);
                break;
            case TestCaseStepAction.ACTION_EXECUTEJS:
                res = this.doActionExecuteJS(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_OPENAPP:
                res = this.doActionOpenApp(tCExecution, value1);
                break;
            case TestCaseStepAction.ACTION_CLOSEAPP:
                res = this.doActionCloseApp(tCExecution, value1);
                break;
            case TestCaseStepAction.ACTION_SELECT:
                res = this.doActionSelect(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_KEYPRESS:
                res = this.doActionKeyPress(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_TYPE:
                res = this.doActionType(tCExecution, value1, value2, propertyName);
                break;
            case TestCaseStepAction.ACTION_HIDEKEYBOARD:
                res = this.doActionHideKeyboard(tCExecution);
                break;
            case TestCaseStepAction.ACTION_SWIPE:
                res = this.doActionSwipe(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_WAIT:
                res = this.doActionWait(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_WAITVANISH:
                res = this.doActionWaitVanish(tCExecution, value1);
                break;
            case TestCaseStepAction.ACTION_CALLSERVICE:
                res = this.doActionCallService(testCaseStepActionExecution, value1);
                break;
            case TestCaseStepAction.ACTION_EXECUTESQLUPDATE:
                res = this.doActionExecuteSQLUpdate(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_EXECUTESQLSTOREPROCEDURE:
                res = this.doActionExecuteSQLStoredProcedure(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_CALCULATEPROPERTY:
                res = this.doActionCalculateProperty(testCaseStepActionExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_DONOTHING:
                res = new MessageEvent(MessageEventEnum.ACTION_SUCCESS);
                break;
            // DEPRECATED ACTIONS FROM HERE.
            case TestCaseStepAction.ACTION_MOUSEOVERANDWAIT:
                res = this.doActionMouseOverAndWait(tCExecution, value1, value2);
                res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());
                logEventService.createForPrivateCalls("ENGINE", "mouseOverAndWait", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");
                LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action mouseOverAndWait triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");
                break;
            case TestCaseStepAction.ACTION_REMOVEDIFFERENCE:
                res = this.doActionRemoveDifference(testCaseStepActionExecution, value1, value2);
                res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());
                logEventService.createForPrivateCalls("ENGINE", "removeDifference", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");
                LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action removeDifference triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");
                break;
            case TestCaseStepAction.ACTION_GETPAGESOURCE:
                res = this.doActionGetPageSource(testCaseStepActionExecution);
                res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());
                logEventService.createForPrivateCalls("ENGINE", "getPageSource", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");
                LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action getPageSource triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");
                break;
            case TestCaseStepAction.ACTION_TAKESCREENSHOT:
                res = this.doActionTakeScreenshot(testCaseStepActionExecution);
                res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());
                logEventService.createForPrivateCalls("ENGINE", "takeScreenshot", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");
                LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action takeScreenshot triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");
                break;
            case TestCaseStepAction.ACTION_CLICKANDWAIT:
                res = this.doActionClickWait(tCExecution, value1, value2);
                res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());
                logEventService.createForPrivateCalls("ENGINE", "clickAndWait", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");
                LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action clickAndWait triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");
                break;
            case TestCaseStepAction.ACTION_ENTER:
                res = this.doActionKeyPress(tCExecution, value1, "RETURN");
                res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());
                logEventService.createForPrivateCalls("ENGINE", "enter", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");
                LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action enter triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");
                break;
            case TestCaseStepAction.ACTION_SELECTANDWAIT:
                res = this.doActionSelect(tCExecution, value1, value2);
                this.doActionWait(tCExecution, StringUtil.NULL, StringUtil.NULL);
                res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());
                logEventService.createForPrivateCalls("ENGINE", "selectAndWait", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");
                LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action selectAndWait triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");
                break;
            default:
                res = new MessageEvent(MessageEventEnum.ACTION_FAILED_UNKNOWNACTION);
                res.setDescription(res.getDescription().replace("%ACTION%", testCaseStepActionExecution.getAction()));
        }
    } catch (final Exception unexpected) {
        LOG.error("Unexpected exception: " + unexpected.getMessage(), unexpected);
        res = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC).resolveDescription("DETAIL", unexpected.getMessage());
    }
    LOG.debug("Result of the action : " + res.getCodeString() + " " + res.getDescription());
    /**
     * In case 1/ the action is flaged as being Forced with a specific
     * return code = PE and 2/ the return of the action is stoping the test
     * --> whatever the return of the action is, we force the return to move
     * forward the test with no screenshot, pagesource.
     */
    if (testCaseStepActionExecution.getForceExeStatus().equals("PE") && res.isStopTest()) {
        res.setDescription(res.getDescription() + " -- Execution forced to continue.");
        res.setDoScreenshot(false);
        res.setGetPageSource(false);
        res.setStopTest(false);
        res.setMessage(MessageGeneralEnum.EXECUTION_PE_TESTEXECUTING);
    }
    testCaseStepActionExecution.setActionResultMessage(res);
    /**
     * Determine here the impact of the Action on the full test return code
     * from the ResultMessage of the Action.
     */
    testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(res.getMessage()));
    /**
     * Determine here if we stop the test from the ResultMessage of the
     * Action.
     */
    testCaseStepActionExecution.setStopExecution(res.isStopTest());
    testCaseStepActionExecution.setEnd(new Date().getTime());
    return testCaseStepActionExecution;
}
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) CerberusEventException(org.cerberus.exception.CerberusEventException) CerberusException(org.cerberus.exception.CerberusException)

Example 5 with CerberusEventException

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

the class ActionService method doActionManageDialog.

private MessageEvent doActionManageDialog(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, "manageDialog", tCExecution);
        /**
         * Get Identifier (identifier, locator)
         */
        Identifier identifier = identifierService.convertStringToIdentifier(element);
        identifierService.checkWebElementIdentifier(identifier.getIdentifier());
        if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {
            return webdriverService.doSeleniumActionManageDialog(tCExecution.getSession(), identifier);
        }
        message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
        message.setDescription(message.getDescription().replace("%ACTION%", "ManageDialog"));
        message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
        return message;
    } catch (CerberusEventException ex) {
        LOG.fatal("Error doing Action ManageDialog :" + ex);
        return ex.getMessageError();
    }
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent)

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