Search in sources :

Example 6 with TestCaseStepActionExecution

use of org.cerberus.crud.entity.TestCaseStepActionExecution in project cerberus-source by cerberustesting.

the class FactoryTestCaseStepExecution method create.

@Override
public TestCaseStepExecution create(long id, String test, String testCase, int step, int index, int sort, String loop, String conditionOper, String conditionVal1Init, String conditionVal2Init, String conditionVal1, String conditionVal2, String batNumExe, long start, long end, long fullStart, long fullEnd, BigDecimal timeElapsed, String returnCode, MessageEvent stepResultMessage, TestCaseStep testCaseStep, TestCaseExecution tCExecution, String useStep, String useStepTest, String useStepTestCase, int useStepTestCaseStep, String description) {
    TestCaseStepExecution testCaseStepExecution = new TestCaseStepExecution();
    testCaseStepExecution.setBatNumExe(batNumExe);
    testCaseStepExecution.setEnd(end);
    testCaseStepExecution.setFullEnd(fullEnd);
    testCaseStepExecution.setFullStart(fullStart);
    testCaseStepExecution.setId(id);
    testCaseStepExecution.setReturnCode(returnCode);
    testCaseStepExecution.setStart(start);
    testCaseStepExecution.setStep(step);
    testCaseStepExecution.setIndex(index);
    testCaseStepExecution.setSort(sort);
    testCaseStepExecution.setLoop(loop);
    testCaseStepExecution.setConditionOper(conditionOper);
    testCaseStepExecution.setConditionVal1Init(conditionVal1Init);
    testCaseStepExecution.setConditionVal2Init(conditionVal2Init);
    testCaseStepExecution.setConditionVal1(conditionVal1);
    testCaseStepExecution.setConditionVal2(conditionVal2);
    testCaseStepExecution.setTest(test);
    testCaseStepExecution.setTestCase(testCase);
    testCaseStepExecution.setTimeElapsed(timeElapsed);
    testCaseStepExecution.setStepResultMessage(stepResultMessage);
    testCaseStepExecution.setTestCaseStep(testCaseStep);
    testCaseStepExecution.settCExecution(tCExecution);
    testCaseStepExecution.setUseStep(useStep);
    testCaseStepExecution.setUseStepTest(useStepTest);
    testCaseStepExecution.setUseStepTestCase(useStepTestCase);
    testCaseStepExecution.setUseStepTestCaseStep(useStepTestCaseStep);
    testCaseStepExecution.setDescription(description);
    // List objects
    List<TestCaseExecutionFile> objectFileList = new ArrayList<>();
    testCaseStepExecution.setFileList(objectFileList);
    List<TestCaseStepActionExecution> testCaseStepActionExecution = new ArrayList<>();
    testCaseStepExecution.setTestCaseStepActionExecutionList(testCaseStepActionExecution);
    return testCaseStepExecution;
}
Also used : IFactoryTestCaseStepExecution(org.cerberus.crud.factory.IFactoryTestCaseStepExecution) TestCaseStepExecution(org.cerberus.crud.entity.TestCaseStepExecution) ArrayList(java.util.ArrayList) TestCaseStepActionExecution(org.cerberus.crud.entity.TestCaseStepActionExecution) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile)

Example 7 with TestCaseStepActionExecution

use of org.cerberus.crud.entity.TestCaseStepActionExecution 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 8 with TestCaseStepActionExecution

use of org.cerberus.crud.entity.TestCaseStepActionExecution in project cerberus-source by cerberustesting.

the class TestCaseStepActionExecutionService method readByVarious1WithDependency.

@Override
public AnswerList readByVarious1WithDependency(long executionId, String test, String testcase, int step, int index) {
    AnswerList actions = this.readByVarious1(executionId, test, testcase, step, index);
    AnswerList response = null;
    List<TestCaseStepActionExecution> tcsaeList = new ArrayList();
    for (Object action : actions.getDataList()) {
        TestCaseStepActionExecution tcsae = (TestCaseStepActionExecution) action;
        AnswerList controls = testCaseStepActionControlExecutionService.readByVarious1WithDependency(executionId, test, testcase, step, index, tcsae.getSequence());
        tcsae.setTestCaseStepActionControlExecutionList((List<TestCaseStepActionControlExecution>) controls.getDataList());
        AnswerList files = testCaseExecutionFileService.readByVarious(executionId, tcsae.getTest() + "-" + tcsae.getTestCase() + "-" + tcsae.getStep() + "-" + tcsae.getIndex() + "-" + tcsae.getSequence());
        tcsae.setFileList((List<TestCaseExecutionFile>) files.getDataList());
        tcsaeList.add(tcsae);
    }
    response = new AnswerList(tcsaeList, actions.getTotalRows());
    return response;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) TestCaseStepActionControlExecution(org.cerberus.crud.entity.TestCaseStepActionControlExecution) ArrayList(java.util.ArrayList) TestCaseStepActionExecution(org.cerberus.crud.entity.TestCaseStepActionExecution) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile)

Example 9 with TestCaseStepActionExecution

use of org.cerberus.crud.entity.TestCaseStepActionExecution in project cerberus-source by cerberustesting.

the class TestCaseStepExecutionService method readByVarious1WithDependency.

@Override
public AnswerList readByVarious1WithDependency(long executionId, String test, String testcase) {
    AnswerList steps = this.readByVarious1(executionId, test, testcase);
    AnswerList response = null;
    List<TestCaseStepExecution> tcseList = new ArrayList();
    for (Object step : steps.getDataList()) {
        TestCaseStepExecution tces = (TestCaseStepExecution) step;
        AnswerList actions = testCaseStepActionExecutionService.readByVarious1WithDependency(executionId, tces.getTest(), tces.getTestCase(), tces.getStep(), tces.getIndex());
        tces.setTestCaseStepActionExecutionList((List<TestCaseStepActionExecution>) actions.getDataList());
        AnswerList files = testCaseExecutionFileService.readByVarious(executionId, tces.getTest() + "-" + tces.getTestCase() + "-" + tces.getStep() + "-" + tces.getIndex());
        tces.setFileList((List<TestCaseExecutionFile>) files.getDataList());
        tcseList.add(tces);
    }
    response = new AnswerList(tcseList, steps.getTotalRows());
    return response;
}
Also used : TestCaseStepExecution(org.cerberus.crud.entity.TestCaseStepExecution) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) TestCaseStepActionExecution(org.cerberus.crud.entity.TestCaseStepActionExecution) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile)

Example 10 with TestCaseStepActionExecution

use of org.cerberus.crud.entity.TestCaseStepActionExecution in project cerberus-source by cerberustesting.

the class ControlServiceTest method testDoControlStringDifferentWhenFail.

@Test
public void testDoControlStringDifferentWhenFail() {
    String property = "test";
    String value = "test";
    String msg = "'" + value + "' is not different from '" + property + "'.";
    TestCaseStepActionControlExecution tcsace = new TestCaseStepActionControlExecution();
    tcsace.setControl("verifyStringDifferent");
    tcsace.setValue1(property);
    tcsace.setValue2(value);
    tcsace.setFatal("Y");
    TestCaseStepExecution tcse = new TestCaseStepExecution();
    tcse.settCExecution(tCExecution);
    TestCaseStepActionExecution tcsae = new TestCaseStepActionExecution();
    tcsae.setTestCaseStepExecution(tcse);
    tcsace.setTestCaseStepActionExecution(tcsae);
    this.controlService.doControl(tcsace);
    Assert.assertEquals(msg, tcsace.getControlResultMessage().getDescription());
    Assert.assertEquals("KO", tcsace.getReturnCode());
    Assert.assertEquals("Y", tcsace.getFatal());
}
Also used : TestCaseStepExecution(org.cerberus.crud.entity.TestCaseStepExecution) TestCaseStepActionControlExecution(org.cerberus.crud.entity.TestCaseStepActionControlExecution) TestCaseStepActionExecution(org.cerberus.crud.entity.TestCaseStepActionExecution) Test(org.junit.Test)

Aggregations

TestCaseStepActionExecution (org.cerberus.crud.entity.TestCaseStepActionExecution)40 TestCaseStepActionControlExecution (org.cerberus.crud.entity.TestCaseStepActionControlExecution)29 TestCaseStepExecution (org.cerberus.crud.entity.TestCaseStepExecution)28 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)6 IFactoryTestCaseStepActionExecution (org.cerberus.crud.factory.IFactoryTestCaseStepActionExecution)5 TestCaseExecutionFile (org.cerberus.crud.entity.TestCaseExecutionFile)4 MessageEvent (org.cerberus.engine.entity.MessageEvent)4 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 AnswerList (org.cerberus.util.answer.AnswerList)3 JSONObject (org.json.JSONObject)3 FileItem (org.apache.commons.fileupload.FileItem)2 FileUploadException (org.apache.commons.fileupload.FileUploadException)2 DiskFileItemFactory (org.apache.commons.fileupload.disk.DiskFileItemFactory)2 ServletFileUpload (org.apache.commons.fileupload.servlet.ServletFileUpload)2 IRecorderService (org.cerberus.engine.execution.IRecorderService)2 AnswerItem (org.cerberus.util.answer.AnswerItem)2