Search in sources :

Example 1 with TestCaseStepActionControl

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

the class TestCaseStepActionControlDAO method findControlByTestTestCaseStep.

@Override
public List<TestCaseStepActionControl> findControlByTestTestCaseStep(String test, String testcase, int step) {
    List<TestCaseStepActionControl> list = null;
    final String query = "SELECT * FROM testcasestepactioncontrol WHERE test = ? AND testcase = ? AND step = ?";
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query)) {
        preStat.setString(1, test);
        preStat.setString(2, testcase);
        preStat.setInt(3, step);
        try (ResultSet resultSet = preStat.executeQuery()) {
            list = new ArrayList<TestCaseStepActionControl>();
            while (resultSet.next()) {
                int sequence = resultSet.getInt("Sequence");
                int controlSequence = resultSet.getInt("ControlSequence");
                int sort = resultSet.getInt("Sort");
                String conditionOper = resultSet.getString("conditionOper");
                String conditionVal1 = resultSet.getString("conditionVal1");
                String conditionVal2 = resultSet.getString("conditionVal2");
                String control = resultSet.getString("Control");
                String value1 = resultSet.getString("Value1");
                String value2 = resultSet.getString("Value2");
                String fatal = resultSet.getString("Fatal");
                String description = resultSet.getString("Description");
                String screenshotFilename = resultSet.getString("screenshotFilename");
                list.add(factoryTestCaseStepActionControl.create(test, testcase, step, sequence, controlSequence, sort, conditionOper, conditionVal1, conditionVal2, control, value1, value2, fatal, description, screenshotFilename));
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    }
    return list;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl) IFactoryTestCaseStepActionControl(org.cerberus.crud.factory.IFactoryTestCaseStepActionControl) PreparedStatement(java.sql.PreparedStatement)

Example 2 with TestCaseStepActionControl

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

the class TestCaseStepActionControlDAO method findControlByTestTestCaseStepSequence.

@Override
public List<TestCaseStepActionControl> findControlByTestTestCaseStepSequence(String test, String testcase, int stepNumber, int sequence) {
    List<TestCaseStepActionControl> list = null;
    final String query = "SELECT * FROM testcasestepactioncontrol WHERE test = ? AND testcase = ? AND step = ? AND sequence = ? ORDER BY sort";
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query)) {
        preStat.setString(1, test);
        preStat.setString(2, testcase);
        preStat.setInt(3, stepNumber);
        preStat.setInt(4, sequence);
        try (ResultSet resultSet = preStat.executeQuery()) {
            list = new ArrayList<TestCaseStepActionControl>();
            while (resultSet.next()) {
                int step = resultSet.getInt("Step");
                int controlSequence = resultSet.getInt("ControlSequence");
                int sort = resultSet.getInt("Sort");
                String conditionOper = resultSet.getString("conditionOper");
                String conditionVal1 = resultSet.getString("conditionVal1");
                String conditionVal2 = resultSet.getString("conditionVal2");
                String control = resultSet.getString("Control");
                String value1 = resultSet.getString("Value1");
                String value2 = resultSet.getString("Value2");
                String fatal = resultSet.getString("Fatal");
                String description = resultSet.getString("Description");
                String screenshotFilename = resultSet.getString("screenshotFilename");
                list.add(factoryTestCaseStepActionControl.create(test, testcase, step, sequence, controlSequence, sort, conditionOper, conditionVal1, conditionVal2, control, value1, value2, fatal, description, screenshotFilename));
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    }
    return list;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl) IFactoryTestCaseStepActionControl(org.cerberus.crud.factory.IFactoryTestCaseStepActionControl) PreparedStatement(java.sql.PreparedStatement)

Example 3 with TestCaseStepActionControl

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

the class TestCaseStepActionControlDAO method findControlByTestTestCase.

@Override
public List<TestCaseStepActionControl> findControlByTestTestCase(String test, String testCase) throws CerberusException {
    List<TestCaseStepActionControl> list = null;
    StringBuilder query = new StringBuilder();
    query.append("SELECT tcsac.* ");
    query.append("FROM testcasestepactioncontrol AS tcsac ");
    query.append("RIGHT JOIN testcasestepaction AS tcsa ON tcsac.Test = tcsa.Test AND tcsac.TestCase = tcsa.TestCase AND tcsac.Step = tcsa.Step AND tcsac.Sequence = tcsa.Sequence ");
    query.append("RIGHT JOIN testcasestep AS tcs ON tcsac.Test = tcs.Test AND tcsac.TestCase = tcs.TestCase AND tcsac.Step = tcs.Step ");
    query.append("WHERE tcsac.Test = ? AND tcsac.TestCase = ? ");
    query.append("GROUP BY tcsac.Test, tcsac.TestCase, tcsac.Step, tcsac.Sequence, tcsac.ControlSequence ");
    query.append("ORDER BY tcs.Sort, tcsa.Sort, tcsac.Sort ");
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query.toString())) {
        preStat.setString(1, test);
        preStat.setString(2, testCase);
        try (ResultSet resultSet = preStat.executeQuery()) {
            list = new ArrayList<TestCaseStepActionControl>();
            while (resultSet.next()) {
                int step = resultSet.getInt("Step");
                int sequence = resultSet.getInt("Sequence");
                int controlSequence = resultSet.getInt("ControlSequence");
                int sort = resultSet.getInt("Sort");
                String conditionOper = resultSet.getString("conditionOper");
                String conditionVal1 = resultSet.getString("conditionVal1");
                String conditionVal2 = resultSet.getString("conditionVal2");
                String control = resultSet.getString("Control");
                String value1 = resultSet.getString("Value1");
                String value2 = resultSet.getString("Value2");
                String fatal = resultSet.getString("Fatal");
                String description = resultSet.getString("Description");
                String screenshotFilename = resultSet.getString("screenshotFilename");
                list.add(factoryTestCaseStepActionControl.create(test, testCase, step, sequence, controlSequence, sort, conditionOper, conditionVal1, conditionVal2, control, value1, value2, fatal, description, screenshotFilename));
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    }
    return list;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl) IFactoryTestCaseStepActionControl(org.cerberus.crud.factory.IFactoryTestCaseStepActionControl) PreparedStatement(java.sql.PreparedStatement)

Example 4 with TestCaseStepActionControl

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

the class LoadTestCaseService method loadTestCaseStepActionControl.

public List<TestCaseStepActionControl> loadTestCaseStepActionControl(TestCaseStep testCaseStep, TestCaseStepAction testCaseAction) {
    List<TestCaseStepActionControl> result = new ArrayList<TestCaseStepActionControl>();
    LOG.debug("get list of control");
    List<TestCaseStepActionControl> controlList = testCaseStepActionControlService.findControlByTestTestCaseStepSequence(testCaseAction.getTest(), testCaseAction.getTestCase(), testCaseAction.getStep(), testCaseAction.getSequence());
    if (controlList != null) {
        for (TestCaseStepActionControl testCaseStepActionControl : controlList) {
            LOG.debug("set control :" + testCaseStepActionControl.getControl());
            testCaseStepActionControl.setTest(testCaseStep.getTest());
            testCaseStepActionControl.setTestCase(testCaseStep.getTestCase());
            testCaseStepActionControl.setStep(testCaseStep.getStep());
            result.add(testCaseStepActionControl);
        }
    }
    LOG.debug("return List<TestCaseStepActionControl>");
    return result;
}
Also used : ArrayList(java.util.ArrayList) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl)

Example 5 with TestCaseStepActionControl

use of org.cerberus.crud.entity.TestCaseStepActionControl 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

TestCaseStepActionControl (org.cerberus.crud.entity.TestCaseStepActionControl)25 ArrayList (java.util.ArrayList)16 TestCaseStepAction (org.cerberus.crud.entity.TestCaseStepAction)12 IFactoryTestCaseStepActionControl (org.cerberus.crud.factory.IFactoryTestCaseStepActionControl)12 TestCaseStep (org.cerberus.crud.entity.TestCaseStep)11 TestCase (org.cerberus.crud.entity.TestCase)8 TestCaseCountryProperties (org.cerberus.crud.entity.TestCaseCountryProperties)8 ITestCaseStepActionControlService (org.cerberus.crud.service.ITestCaseStepActionControlService)8 ITestCaseStepActionService (org.cerberus.crud.service.ITestCaseStepActionService)8 ITestCaseStepService (org.cerberus.crud.service.ITestCaseStepService)8 JSONObject (org.json.JSONObject)8 TestCaseCountry (org.cerberus.crud.entity.TestCaseCountry)7 ITestCaseService (org.cerberus.crud.service.ITestCaseService)7 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)6 ITestCaseCountryPropertiesService (org.cerberus.crud.service.ITestCaseCountryPropertiesService)6 MessageEvent (org.cerberus.engine.entity.MessageEvent)6 JSONArray (org.json.JSONArray)6