How to use setStopExecution method of org.cerberus.crud.entity.TestCaseStepExecution class

Best Cerberus-source code snippet using org.cerberus.crud.entity.TestCaseStepExecution.setStopExecution

Source:ExecutionRunService.java Github

copy

Full Screen

...555 testCaseStepExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));556 testCaseStepExecution.setStepResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Step Condition Value1"));557 testCaseStepExecution.setReturnMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Step Condition Value1").getDescription());558 testCaseStepExecution.setReturnCode(answerDecode.getResultMessage().getCodeString());559 testCaseStepExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());560 testCaseStepExecution.setEnd(new Date().getTime());561 LOG.debug(logPrefix + "Step interupted due to decode 'Step Condition Value1' Error.");562 descriptionOrConditionStepDecodeError = true;563 }564 } catch (CerberusEventException cex) {565 LOG.warn(cex);566 }567 if (!descriptionOrConditionStepDecodeError) {568 try {569 answerDecode = variableService.decodeStringCompletly(testCaseStepExecution.getConditionVal2(), tCExecution, null, false);570 testCaseStepExecution.setConditionVal2((String) answerDecode.getItem());571 if (!(answerDecode.isCodeStringEquals("OK"))) {572 testCaseStepExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));573 testCaseStepExecution.setStepResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Step Condition Value2"));574 testCaseStepExecution.setReturnMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Step Condition Value2").getDescription());575 testCaseStepExecution.setReturnCode(answerDecode.getResultMessage().getCodeString());576 testCaseStepExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());577 testCaseStepExecution.setEnd(new Date().getTime());578 LOG.debug(logPrefix + "Step interupted due to decode 'Step Condition Value2' Error.");579 descriptionOrConditionStepDecodeError = true;580 }581 } catch (CerberusEventException cex) {582 LOG.warn(cex);583 }584 }585 if (!descriptionOrConditionStepDecodeError) {586 try {587 answerDecode = variableService.decodeStringCompletly(testCaseStepExecution.getConditionVal3(), tCExecution, null, false);588 testCaseStepExecution.setConditionVal3((String) answerDecode.getItem());589 if (!(answerDecode.isCodeStringEquals("OK"))) {590 testCaseStepExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));591 testCaseStepExecution.setStepResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Step Condition Value3"));592 testCaseStepExecution.setReturnMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Step Condition Value3").getDescription());593 testCaseStepExecution.setReturnCode(answerDecode.getResultMessage().getCodeString());594 testCaseStepExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());595 testCaseStepExecution.setEnd(new Date().getTime());596 LOG.debug(logPrefix + "Step interupted due to decode 'Step Condition Value3' Error.");597 descriptionOrConditionStepDecodeError = true;598 }599 } catch (CerberusEventException cex) {600 LOG.warn(cex);601 }602 }603 if (!descriptionOrConditionStepDecodeError) {604 try {605 answerDecode = variableService.decodeStringCompletly(testCaseStepExecution.getDescription(), tCExecution, null, false);606 testCaseStepExecution.setDescription((String) answerDecode.getItem());607 if (!(answerDecode.isCodeStringEquals("OK"))) {608 testCaseStepExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));609 testCaseStepExecution.setStepResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Step Description"));610 testCaseStepExecution.setReturnMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Step Description").getDescription());611 testCaseStepExecution.setReturnCode(answerDecode.getResultMessage().getCodeString());612 testCaseStepExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());613 testCaseStepExecution.setEnd(new Date().getTime());614 LOG.debug(logPrefix + "Step interupted due to decode 'Step Description' Error.");615 descriptionOrConditionStepDecodeError = true;616 }617 } catch (CerberusEventException cex) {618 LOG.warn(cex);619 }620 }621 if (!(descriptionOrConditionStepDecodeError)) {622 conditionAnswer = this.conditionService.evaluateCondition(testCaseStepExecution.getConditionOperator(), testCaseStepExecution.getConditionVal1(), testCaseStepExecution.getConditionVal2(), testCaseStepExecution.getConditionVal3(), tCExecution);623 execute_Step = (boolean) conditionAnswer.getItem();624 if (conditionAnswer.getResultMessage().getMessage().getCodeString().equals("PE")) {625 // There were no error when performing the condition evaluation.626 switch (testCaseStepExecution.getLoop()) {627 case TestCaseStep.LOOP_ONCEIFCONDITIONFALSE:628 execute_Step = !execute_Step;629 execute_Next_Step = false;630 break;631 case TestCaseStep.LOOP_ONCEIFCONDITIONTRUE:632 case "":633 execute_Next_Step = false;634 break;635 case TestCaseStep.LOOP_WHILECONDITIONFALSEDO:636 case TestCaseStep.LOOP_DOWHILECONDITIONFALSE:637 execute_Step = !execute_Step;638 execute_Next_Step = execute_Step;639 break;640 case TestCaseStep.LOOP_WHILECONDITIONTRUEDO:641 case TestCaseStep.LOOP_DOWHILECONDITIONTRUE:642 execute_Next_Step = execute_Step;643 break;644 default:645 execute_Next_Step = false;646 }647 } else {648 // Error when performing the condition evaluation. We force no execution (false)649 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_CONDITION);650 mes.setDescription(mes.getDescription()651 .replace("%AREA%", "step ")652 .replace("%COND%", testCaseStepExecution.getConditionOperator())653 .replace("%MES%", conditionAnswer.getResultMessage().getDescription()));654 tCExecution.setResultMessage(mes);655 testCaseStepExecution.setExecutionResultMessage(mes);656 testCaseStepExecution.setStepResultMessage(new MessageEvent(MessageEventEnum.CONDITION_TESTCASESTEP_FAILED)657 .resolveDescription("AREA", "")658 .resolveDescription("COND", testCaseStepExecution.getConditionOperator())659 .resolveDescription("MESSAGE", conditionAnswer.getResultMessage().getDescription())660 );661 testCaseStepExecution.setEnd(new Date().getTime());662 LOG.debug(logPrefix + "Step interupted due to condition error.");663 conditionStepError = true;664 execute_Next_Step = false;665 execute_Step = false;666 }667 } else {668 // If anything wrong with the decode --> we stop here with decode message in the action result.669 tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_DECODE)670 .resolveDescription("AREA", "Step")671 .resolveDescription("MES", answerDecode.getMessageDescription()));672 tCExecution.setEnd(new Date().getTime());673 LOG.debug(logPrefix + "TestCase interupted due to decode Error.");674 // There was an error on decode so we stop everything.675 if (tCExecution.getManualExecution().equals("Y")) {676 execute_Next_Step = true;677 execute_Step = true;678 } else {679 execute_Next_Step = false;680 execute_Step = false;681 }682 }683 } else if (testCaseStepExecution.getLoop().equals(TestCaseStep.LOOP_DOWHILECONDITIONFALSE)684 || testCaseStepExecution.getLoop().equals(TestCaseStep.LOOP_DOWHILECONDITIONTRUE)) {685 // First Step execution for LOOP_DOWHILECONDITIONTRUE and LOOP_DOWHILECONDITIONFALSE --> We force the step execution and activate the next step execution.686 execute_Step = true;687 execute_Next_Step = true;688 } else {689 // First Step execution for Unknown Loop --> We force the step execution only once (default behaviour).690 execute_Step = true;691 execute_Next_Step = false;692 conditionAnswer.setResultMessage(new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_UNKNOWNCONDITION));693 }694 /**695 * Execute Step696 */697 LOG.debug(logPrefix + "Executing step : " + testCaseStepExecution.getTest() + " - " + testCaseStepExecution.getTestCase() + " - Step " + testCaseStepExecution.getStep() + " - Index " + testCaseStepExecution.getStep());698 if (execute_Step) {699 /**700 * We execute the step701 */702 testCaseStepExecution = this.executeStep(testCaseStepExecution, tCExecution);703 /**704 * Updating Execution Result Message only if705 * execution result message of the step is706 * not PE or OK.707 */708 if ((!(testCaseStepExecution.getExecutionResultMessage().equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_TESTSTARTED))))709 && (!(testCaseStepExecution.getExecutionResultMessage().equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_OK))))) {710 tCExecution.setResultMessage(testCaseStepExecution.getExecutionResultMessage());711 }712 if (testCaseStepExecution.getStepResultMessage().equals(new MessageEvent(MessageEventEnum.STEP_PENDING))) {713 testCaseStepExecution.setStepResultMessage(new MessageEvent(MessageEventEnum.STEP_SUCCESS));714 }715 testCaseStepExecutionService.updateTestCaseStepExecution(testCaseStepExecution);716 if (testCaseStepExecution.isStopExecution()) {717 break;718 }719 } else // We don't execute the step and record a generic execution.720 if ((!descriptionOrConditionStepDecodeError) && (!conditionStepError)) {721 /**722 * Register Step in database723 */724 LOG.debug(logPrefix + "Registering Step : " + testCaseStepExecution.getStep());725 // We change the Step message only if the Step is not executed due to condition.726 MessageEvent stepMes = new MessageEvent(MessageEventEnum.CONDITION_TESTCASESTEP_NOTEXECUTED);727 testCaseStepExecution.setStepResultMessage(stepMes);728 testCaseStepExecution.setReturnMessage(testCaseStepExecution.getReturnMessage()729 .replace("%COND%", testCaseStepExecution.getConditionOperator())730 .replace("%LOOP%", testCaseStepExecution.getLoop())731 .replace("%MESSAGE%", conditionAnswer.getResultMessage().getDescription())732 );733 testCaseStepExecution.setEnd(new Date().getTime());734 this.testCaseStepExecutionService.updateTestCaseStepExecution(testCaseStepExecution);735 LOG.debug(logPrefix + "Registered Step");736 } else {737 // Not executed because decode error or failed condition.738 testCaseStepExecution.setEnd(new Date().getTime());739 testCaseStepExecution.setStopExecution(true);740 this.testCaseStepExecutionService.updateTestCaseStepExecution(testCaseStepExecution);741 LOG.debug(logPrefix + "Registered Step");742 }743 /**744 * Log TestCaseStepExecution745 */746 if (tCExecution.getVerbose() > 0) {747 LOG.info(testCaseStepExecution.toJson(false, true));748 }749 // Websocket --> we refresh the corresponding Detail Execution pages attached to this execution.750 updateTCExecutionWebSocketOnly(tCExecution, false);751 step_index++;752 } while (execute_Next_Step && step_index <= maxloop);753 // Step execution boolean is considered for next step execution only if current step was not forced or forced and failed.754 if (!testCaseStep.getForceExe().equalsIgnoreCase("Y") || testCaseStepExecution.isStopExecution()) {755 doStepStopExecution = testCaseStepExecution.isStopExecution();756 }757 }758 }759 /**760 * If at that time the execution is still PE, we move it to761 * OK. It means that no issue were met.762 */763 if ((tCExecution.getResultMessage() == null) || (tCExecution.getResultMessage().equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_TESTSTARTED)))) {764 tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_OK));765 }766 /**767 * We notify external robot provider of end of execution768 * status.769 */770 switch (tCExecution.getRobotProvider()) {771 case TestCaseExecution.ROBOTPROVIDER_BROWSERSTACK:772 browserstackService.setSessionStatus(tCExecution.getSystem(), tCExecution.getRobotSessionID(), tCExecution.getControlStatus(), tCExecution.getControlMessage(), tCExecution.getRobotExecutorObj().getHostUser(), tCExecution.getRobotExecutorObj().getHostPassword());773 break;774 case TestCaseExecution.ROBOTPROVIDER_KOBITON:775 kobitonService.setSessionStatus(tCExecution.getSystem(), tCExecution.getRobotSessionID(), tCExecution.getControlStatus(), tCExecution.getControlMessage(), tCExecution.getRobotExecutorObj().getHostUser(), tCExecution.getRobotExecutorObj().getHostPassword());776 break;777 }778 } else { // We don't execute the testcase linked with condition.779 MessageGeneral mes;780 /**781 * Update Execution status from condition782 */783 if (conditionAnswerTc.getResultMessage().getMessage().getCodeString().equals("PE")) {784 mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_NE_CONDITION);785 } else {786 mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_CONDITION);787 }788 mes.setDescription(mes.getDescription().replace("%COND%", tCExecution.getConditionOperator())789 .replace("%MES%", conditionAnswerTc.getResultMessage().getDescription()));790 tCExecution.setResultMessage(mes);791 }792 }793 } catch (CerberusException ex) {794 /**795 * If an exception is found, set the execution to FA and print the796 * exception (only in debug mode)797 */798 MessageGeneral messageFin = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA);799 messageFin.setDescription(messageFin.getDescription() + " " + ex.getMessageError().getDescription());800 tCExecution.setResultMessage(messageFin);801 LOG.debug(logPrefix + "Exception found Executing Test " + tCExecution.getId() + " : " + ex.getMessageError().getDescription());802 } catch (Exception ex) {803 /**804 * If an exception is found, set the execution to FA and print the805 * exception806 */807 MessageGeneral messageFin = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA);808 messageFin.setDescription(messageFin.getDescription() + " " + ex.getMessage());809 tCExecution.setResultMessage(messageFin);810 tCExecution.setControlMessage(tCExecution.getControlMessage() + " Exception: " + ex);811 LOG.error(logPrefix + "Exception found Executing Test " + tCExecution.getId(), ex);812 } finally {813 /**814 * We stop the server session here (selenium for ex.).815 */816 try {817 if (videoRecorder != null) {818 videoRecorder.endRecordVideo();819 }820 tCExecution = this.stopTestCase(tCExecution);821 } catch (Exception ex) {822 LOG.error(logPrefix + "Exception Stopping Test " + tCExecution.getId() + " Exception : " + ex.toString(), ex);823 }824 /**825 * Log Execution826 */827 LOG.info(tCExecution.toJson(false));828 /**829 * Clean memory830 */831 try {832 executionUUID.removeExecutionUUID(tCExecution.getExecutionUUID());833 LOG.debug(logPrefix + "Clean ExecutionUUID");834 } catch (Exception ex) {835 LOG.error(logPrefix + "Exception cleaning Memory: " + ex.toString(), ex);836 }837 /**838 * Log execution is finished839 */840 LOG.info("Execution Finished : UUID=" + tCExecution.getExecutionUUID()841 + " ID=" + tCExecution.getId() + " RC=" + tCExecution.getControlStatus() + " "842 + "TestName=" + tCExecution.getEnvironment() + "." + tCExecution.getCountry() + "."843 + tCExecution.getBuild() + "." + tCExecution.getRevision() + "." + tCExecution.getTest() + "_"844 + tCExecution.getTestCase() + "_" + tCExecution.getTestCaseObj().getDescription().replace(".", ""));845 /**846 * Retry management, in case the result is not (OK or NE), we847 * execute the job again reducing the retry to 1.848 */849 boolean isRetried = retriesService.manageRetries(tCExecution);850 /**851 * Updating queue to done status only for execution from queue852 */853 if (tCExecution.getQueueID() != 0) {854 executionQueueService.updateToDone(tCExecution.getQueueID(), "", runID);855 }856 /**857 * After every execution finished, <br>858 * if the execution has a tag that has a campaign associated <br>859 * and no more executions are in the queue, <br>860 * we trigger : <br>861 * 1/ The update of the EndExeQueue of the tag <br>862 * 2/ We notify the Distribution List with execution report status863 */864 tagService.manageCampaignEndOfExecution(tCExecution.getTag());865 /**866 * Dependency management, At the end of the execution, we RELEASE867 * the corresponding dependencies and put corresponding Queue868 * entries to QUEUED status.869 */870 if (!isRetried) {871 testCaseExecutionQueueDepService.manageDependenciesEndOfExecution(tCExecution);872 }873 // After every execution finished we try to trigger more from the queue;-).874 executionThreadPoolService.executeNextInQueueAsynchroneously(false);875 }876 return tCExecution;877 }878 // Update Execution status and eventually push the new value to websocket.879 private void updateTCExecution(TestCaseExecution tCExecution, boolean forcePush) {880 try {881 testCaseExecutionService.updateTCExecution(tCExecution);882 } catch (CerberusException ex) {883 LOG.warn(ex);884 }885 updateTCExecutionWebSocketOnly(tCExecution, forcePush);886 }887 private void updateTCExecutionWebSocketOnly(TestCaseExecution tCExecution, boolean forcePush) {888 // Websocket --> we refresh the corresponding Detail Execution pages attached to this execution.889 if (tCExecution.isCerberus_featureflipping_activatewebsocketpush()) {890 TestCaseExecutionEndPoint.getInstance().send(tCExecution, forcePush);891 }892 }893 @Override894 public TestCaseExecution stopTestCase(TestCaseExecution tCExecution) {895 /**896 * Stop Execution897 */898 LOG.debug(tCExecution.getId() + " - Stop the execution " + tCExecution.getId() + " UUID:" + tCExecution.getExecutionUUID());899 try {900 //TODO:FN debug messages to be removed901 LOG.debug("[DEBUG] STOP " + " ID=" + tCExecution.getId());902 this.stopRunTestCase(tCExecution);903 } catch (Exception ex) {904 LOG.warn("Exception Stopping Execution " + tCExecution.getId() + " Exception :" + ex.toString());905 }906 /**907 * Saving TestCaseExecution object.908 */909 tCExecution.setEnd(new Date().getTime());910 try {911 testCaseExecutionService.updateTCExecution(tCExecution);912 } catch (CerberusException ex) {913 LOG.warn("Exception updating Execution :" + tCExecution.getId() + " Exception:" + ex.toString());914 }915 // Websocket --> we refresh the corresponding Detail Execution pages attached to this execution.916 if (tCExecution.isCerberus_featureflipping_activatewebsocketpush()) {917 TestCaseExecutionEndPoint.getInstance().send(tCExecution, true);918 TestCaseExecutionEndPoint.getInstance().end(tCExecution);919 }920 return tCExecution;921 }922 private TestCaseStepExecution executeStep(TestCaseStepExecution testCaseStepExecution, TestCaseExecution tcExecution) {923 long runID = testCaseStepExecution.getId();924 String logPrefix = runID + " - ";925 AnswerItem<String> answerDecode = new AnswerItem<>();926 // Initialise the Step Data List.927 List<TestCaseExecutionData> myStepDataList = new ArrayList<>();928 testCaseStepExecution.setTestCaseExecutionDataList(myStepDataList);929 // Initialise the Data List used to enter the action.930 /**931 * Iterate Actions932 */933 List<TestCaseStepAction> testCaseStepActionList = testCaseStepExecution.getTestCaseStep().getActions();934 LOG.debug("Getting list of actions of the step. " + testCaseStepActionList.size() + " action(s) to perform.");935 for (TestCaseStepAction testCaseStepAction : testCaseStepActionList) {936 /**937 * Start Execution of TestCaseStepAction938 */939 long startAction = new Date().getTime();940 /**941 * Create and Register TestCaseStepActionExecution.942 */943 TestCaseStepActionExecution testCaseStepActionExecution = factoryTestCaseStepActionExecution.create(944 testCaseStepExecution.getId(), testCaseStepAction.getTest(), testCaseStepAction.getTestCase(),945 testCaseStepAction.getStep(), testCaseStepExecution.getIndex(), testCaseStepAction.getSequence(), testCaseStepAction.getSort(), null, null,946 testCaseStepAction.getConditionOperator(), testCaseStepAction.getConditionVal1(), testCaseStepAction.getConditionVal2(), testCaseStepAction.getConditionVal3(),947 testCaseStepAction.getConditionVal1(), testCaseStepAction.getConditionVal2(), testCaseStepAction.getConditionVal3(),948 testCaseStepAction.getAction(), testCaseStepAction.getValue1(), testCaseStepAction.getValue2(), testCaseStepAction.getValue3(), testCaseStepAction.getValue1(),949 testCaseStepAction.getValue2(), testCaseStepAction.getValue3(),950 testCaseStepAction.getForceExeStatus(), startAction, startAction, startAction, startAction, new MessageEvent(MessageEventEnum.ACTION_PENDING),951 testCaseStepAction.getDescription(), testCaseStepAction, testCaseStepExecution);952 this.testCaseStepActionExecutionService.insertTestCaseStepActionExecution(testCaseStepActionExecution);953 /**954 * We populate the TestCase Action List955 */956 testCaseStepExecution.addTestCaseStepActionExecutionList(testCaseStepActionExecution);957 /**958 * If execution is not manual, evaluate the condition at the action959 * level960 */961 AnswerItem<Boolean> conditionAnswer;962 boolean conditionDecodeError = false;963 if (!tcExecution.getManualExecution().equals("Y")) {964 try {965 answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getConditionVal1(), tcExecution, null, false);966 testCaseStepActionExecution.setConditionVal1((String) answerDecode.getItem());967 if (!(answerDecode.isCodeStringEquals("OK"))) {968 // If anything wrong with the decode --> we stop here with decode message in the action result.969 testCaseStepActionExecution.setActionResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Action Condition Value1"));970 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));971 testCaseStepActionExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());972 testCaseStepActionExecution.setEnd(new Date().getTime());973 LOG.debug("Action interupted due to decode 'Action Condition Value1' Error.");974 conditionDecodeError = true;975 }976 } catch (CerberusEventException cex) {977 LOG.warn(cex);978 }979 try {980 answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getConditionVal2(), tcExecution, null, false);981 testCaseStepActionExecution.setConditionVal2((String) answerDecode.getItem());982 if (!(answerDecode.isCodeStringEquals("OK"))) {983 // If anything wrong with the decode --> we stop here with decode message in the action result.984 testCaseStepActionExecution.setActionResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Action Condition Value2"));985 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));986 testCaseStepActionExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());987 testCaseStepActionExecution.setEnd(new Date().getTime());988 LOG.debug("Action interupted due to decode 'Action Condition Value2' Error.");989 conditionDecodeError = true;990 }991 } catch (CerberusEventException cex) {992 LOG.warn(cex);993 }994 try {995 answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getConditionVal3(), tcExecution, null, false);996 testCaseStepActionExecution.setConditionVal3((String) answerDecode.getItem());997 if (!(answerDecode.isCodeStringEquals("OK"))) {998 // If anything wrong with the decode --> we stop here with decode message in the action result.999 testCaseStepActionExecution.setActionResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Action Condition Value3"));1000 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));1001 testCaseStepActionExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());1002 testCaseStepActionExecution.setEnd(new Date().getTime());1003 LOG.debug("Action interupted due to decode 'Action Condition Value3' Error.");1004 conditionDecodeError = true;1005 }1006 } catch (CerberusEventException cex) {1007 LOG.warn(cex);1008 }1009 }1010 if (!(conditionDecodeError)) {1011 conditionAnswer = this.conditionService.evaluateCondition(testCaseStepActionExecution.getConditionOperator(), testCaseStepActionExecution.getConditionVal1(), testCaseStepActionExecution.getConditionVal2(), testCaseStepActionExecution.getConditionVal3(), tcExecution);1012 boolean execute_Action = (boolean) conditionAnswer.getItem();1013 /**1014 * If condition OK or if manual execution, then execute the1015 * action1016 */1017 if (conditionAnswer.getResultMessage().getMessage().getCodeString().equals("PE")1018 || tcExecution.getManualExecution().equals("Y")) {1019 // Execute or not the action here.1020 if (execute_Action || tcExecution.getManualExecution().equals("Y")) {1021 LOG.debug("Executing action : " + testCaseStepActionExecution.getAction() + " with val1 : " + testCaseStepActionExecution.getValue1()1022 + " and val2 : " + testCaseStepActionExecution.getValue2()1023 + " and val3 : " + testCaseStepActionExecution.getValue3());1024 /**1025 * We execute the Action1026 */1027 testCaseStepActionExecution = this.executeAction(testCaseStepActionExecution, tcExecution);1028 /**1029 * If Action or property reported to stop the testcase,1030 * we stop it and update the step with the message.1031 */1032 testCaseStepExecution.setStopExecution(testCaseStepActionExecution.isStopExecution());1033 if ((!(testCaseStepActionExecution.getExecutionResultMessage().equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_OK))))1034 && (!(testCaseStepActionExecution.getExecutionResultMessage().equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_TESTEXECUTING))))) {1035 testCaseStepExecution.setExecutionResultMessage(testCaseStepActionExecution.getExecutionResultMessage());1036 testCaseStepExecution.setStepResultMessage(testCaseStepActionExecution.getActionResultMessage());1037 }1038 if (testCaseStepActionExecution.isStopExecution()) {1039 break;1040 }1041 } else { // We don't execute the action and record a generic execution.1042 /**1043 * Record Screenshot, PageSource1044 */1045 testCaseStepActionExecution.addFileList(recorderService.recordExecutionInformationAfterStepActionandControl(testCaseStepActionExecution, null));1046 LOG.debug("Registering Action : " + testCaseStepActionExecution.getAction());1047 // We change the Action message only if the action is not executed due to condition.1048 MessageEvent actionMes = new MessageEvent(MessageEventEnum.CONDITION_TESTCASEACTION_NOTEXECUTED);1049 testCaseStepActionExecution.setActionResultMessage(actionMes);1050 testCaseStepActionExecution.setReturnMessage(testCaseStepActionExecution.getReturnMessage()1051 .replace("%COND%", testCaseStepActionExecution.getConditionOperator())1052 .replace("%MESSAGE%", conditionAnswer.getResultMessage().getDescription())1053 );1054 testCaseStepActionExecution.setEnd(new Date().getTime());1055 this.testCaseStepActionExecutionService.updateTestCaseStepActionExecution(testCaseStepActionExecution);1056 LOG.debug("Registered Action");1057 }1058 } else {1059 // Error when performing the condition evaluation. We force no execution (false)1060 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_CONDITION);1061 mes.setDescription(mes.getDescription()1062 .replace("%COND%", testCaseStepActionExecution.getConditionOperator())1063 .replace("%AREA%", "action ")1064 .replace("%MES%", conditionAnswer.getResultMessage().getDescription()));1065 testCaseStepActionExecution.setExecutionResultMessage(mes);1066 testCaseStepExecution.setExecutionResultMessage(testCaseStepActionExecution.getExecutionResultMessage());1067 testCaseStepActionExecution.setActionResultMessage(new MessageEvent(MessageEventEnum.CONDITION_TESTCASEACTION_FAILED)1068 .resolveDescription("AREA", "")1069 .resolveDescription("COND", testCaseStepActionExecution.getConditionOperator())1070 .resolveDescription("MESSAGE", conditionAnswer.getResultMessage().getDescription()));1071 testCaseStepExecution.setStepResultMessage(new MessageEvent(MessageEventEnum.CONDITION_TESTCASESTEP_FAILED)1072 .resolveDescription("AREA", "action ")1073 .resolveDescription("COND", testCaseStepActionExecution.getConditionOperator())1074 .resolveDescription("MESSAGE", conditionAnswer.getResultMessage().getDescription()));1075 if (testCaseStepActionExecution.getForceExeStatus().equals("PE")) {1076 testCaseStepActionExecution.setStopExecution(false);1077 MessageEvent actionMes = testCaseStepActionExecution.getActionResultMessage();1078 actionMes.setDescription(testCaseStepActionExecution.getActionResultMessage().getDescription() + " -- Execution forced to continue.");1079 testCaseStepActionExecution.setActionResultMessage(actionMes);1080 } else {1081 testCaseStepActionExecution.setStopExecution(true);1082 }1083 testCaseStepExecution.setStopExecution(testCaseStepActionExecution.isStopExecution());1084 testCaseStepActionExecution.setEnd(new Date().getTime());1085 this.testCaseStepActionExecutionService.updateTestCaseStepActionExecution(testCaseStepActionExecution);1086 LOG.debug("Action interupted due to condition error.");1087 // We stop any further Action execution.1088 if (testCaseStepActionExecution.isStopExecution()) {1089 break;1090 }1091 }1092 } else {1093 testCaseStepActionExecution.setEnd(new Date().getTime());1094 testCaseStepExecution.setExecutionResultMessage(testCaseStepActionExecution.getExecutionResultMessage());1095 testCaseStepExecution.setStepResultMessage(testCaseStepActionExecution.getActionResultMessage());1096 testCaseStepExecution.setStopExecution(testCaseStepActionExecution.isStopExecution());1097 this.testCaseStepActionExecutionService.updateTestCaseStepActionExecution(testCaseStepActionExecution);1098 LOG.debug("Registered Action");1099 if (testCaseStepActionExecution.isStopExecution()) {1100 break;1101 }1102 }1103 /**1104 * Log TestCaseStepActionExecution1105 */1106 if (tcExecution.getVerbose() > 0) {1107 LOG.info(testCaseStepActionExecution.toJson(false, true));1108 }1109 }1110 testCaseStepExecution.setEnd(new Date().getTime());1111 this.testCaseStepExecutionService.updateTestCaseStepExecution(testCaseStepExecution);1112 updateTCExecutionWebSocketOnly(tcExecution, false);1113 return testCaseStepExecution;1114 }1115 private TestCaseStepActionExecution executeAction(TestCaseStepActionExecution actionExe, TestCaseExecution exe) {1116 LOG.debug("Starting execute Action : " + actionExe.getAction());1117 AnswerItem<String> answerDecode = new AnswerItem<>();1118 /**1119 * If execution is not manual, do action and record files1120 */1121 if (!exe.getManualExecution().equals("Y")) {1122 actionExe = this.actionService.doAction(actionExe);1123 /**1124 * Record Screenshot, PageSource1125 */1126 try {1127 actionExe.addFileList(recorderService.recordExecutionInformationAfterStepActionandControl(actionExe, null));1128 } catch (Exception ex) {1129 LOG.warn("Unable to record Screenshot/PageSource : " + ex.toString(), ex);1130 }1131 } else {1132 /**1133 * If execution manual, set Action result message as notExecuted1134 */1135 actionExe.setActionResultMessage(new MessageEvent(MessageEventEnum.ACTION_WAITINGFORMANUALEXECUTION));1136 actionExe.setExecutionResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_WE));1137 actionExe.setEnd(new Date().getTime());1138 }1139 /**1140 * Register Action in database1141 */1142 LOG.debug("Registering Action : " + actionExe.getAction());1143 this.testCaseStepActionExecutionService.updateTestCaseStepActionExecution(actionExe);1144 LOG.debug("Registered Action");1145 if (actionExe.isStopExecution()) {1146 return actionExe;1147 }1148 // If Action setNetworkTrafficContent or setServiceCallContent is not executed, we don't execute the corresponding controls.1149 if (actionExe.getActionResultMessage().getCodeString().equals("NE")1150 && (actionExe.getAction().equals(TestCaseStepAction.ACTION_SETNETWORKTRAFFICCONTENT) || actionExe.getAction().equals(TestCaseStepAction.ACTION_SETNETWORKTRAFFICCONTENT))) {1151 return actionExe;1152 }1153 //As controls are associated with an action, the current state for the action is stored in order to restore it1154 //if some property is not defined for the country1155 MessageEvent actionMessage = actionExe.getActionResultMessage();1156 MessageGeneral excutionResultMessage = actionExe.getExecutionResultMessage();1157 /**1158 * Iterate Control1159 */1160 List<TestCaseStepActionControl> tcsacList = actionExe.getTestCaseStepAction().getControls();1161 for (TestCaseStepActionControl control : tcsacList) {1162 /**1163 * Start Execution of TestCAseStepActionControl1164 */1165 long startControl = new Date().getTime();1166 /**1167 * Create and Register TestCaseStepActionControlExecution1168 */1169 LOG.debug("Creating TestCaseStepActionControlExecution");1170 TestCaseStepActionControlExecution controlExe1171 = factoryTestCaseStepActionControlExecution.create(actionExe.getId(), control.getTest(), control.getTestCase(),1172 control.getStep(), actionExe.getIndex(), control.getSequence(), control.getControlSequence(), control.getSort(),1173 null, null,1174 control.getConditionOperator(), control.getConditionVal1(), control.getConditionVal2(), control.getConditionVal3(), control.getConditionVal1(), control.getConditionVal2(), control.getConditionVal3(),1175 control.getControl(), control.getValue1(), control.getValue2(), control.getValue3(), control.getValue1(), control.getValue2(),1176 control.getValue3(), control.getFatal(), startControl, 0, 0, 0,1177 control.getDescription(), actionExe, new MessageEvent(MessageEventEnum.CONTROL_PENDING));1178 this.testCaseStepActionControlExecutionService.insertTestCaseStepActionControlExecution(controlExe);1179 LOG.debug("Executing control : " + controlExe.getControlSequence() + " type : " + controlExe.getControl());1180 /**1181 * We populate the TestCase Control List1182 */1183 actionExe.addTestCaseStepActionExecutionList(controlExe);1184 // Evaluate the condition at the control level.1185 AnswerItem<Boolean> conditionAnswer;1186 boolean conditionDecodeError = false;1187 if (!exe.getManualExecution().equals("Y")) {1188 try {1189 answerDecode = variableService.decodeStringCompletly(controlExe.getConditionVal1(), exe, null, false);1190 controlExe.setConditionVal1((String) answerDecode.getItem());1191 if (!(answerDecode.isCodeStringEquals("OK"))) {1192 // If anything wrong with the decode --> we stop here with decode message in the action result.1193 controlExe.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Condition Value1"));1194 controlExe.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));1195 controlExe.setStopExecution(answerDecode.getResultMessage().isStopTest());1196 controlExe.setEnd(new Date().getTime());1197 LOG.debug("Control interupted due to decode 'Control Condition Value1' Error.");1198 conditionDecodeError = true;1199 }1200 } catch (CerberusEventException cex) {1201 LOG.warn(cex);1202 }1203 try {1204 answerDecode = variableService.decodeStringCompletly(controlExe.getConditionVal2(), exe, null, false);1205 controlExe.setConditionVal2((String) answerDecode.getItem());1206 if (!(answerDecode.isCodeStringEquals("OK"))) {1207 // If anything wrong with the decode --> we stop here with decode message in the action result.1208 controlExe.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Condition Value2"));1209 controlExe.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));1210 controlExe.setStopExecution(answerDecode.getResultMessage().isStopTest());1211 controlExe.setEnd(new Date().getTime());1212 LOG.debug("Control interupted due to decode 'Control Condition Value2' Error.");1213 conditionDecodeError = true;1214 }1215 } catch (CerberusEventException cex) {1216 LOG.warn(cex);1217 }1218 try {1219 answerDecode = variableService.decodeStringCompletly(controlExe.getConditionVal3(), exe, null, false);1220 controlExe.setConditionVal3((String) answerDecode.getItem());1221 if (!(answerDecode.isCodeStringEquals("OK"))) {1222 // If anything wrong with the decode --> we stop here with decode message in the action result.1223 controlExe.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Condition Value3"));1224 controlExe.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));1225 controlExe.setStopExecution(answerDecode.getResultMessage().isStopTest());1226 controlExe.setEnd(new Date().getTime());1227 LOG.debug("Control interupted due to decode 'Control Condition Value3' Error.");1228 conditionDecodeError = true;1229 }1230 } catch (CerberusEventException cex) {1231 LOG.warn(cex);1232 }1233 }1234 if (!(conditionDecodeError)) {1235 conditionAnswer = this.conditionService.evaluateCondition(controlExe.getConditionOperator(), controlExe.getConditionVal1(), controlExe.getConditionVal2(), controlExe.getConditionVal3(), exe);1236 boolean execute_Control = (boolean) conditionAnswer.getItem();1237 /**1238 * If condition OK or if manual execution, then execute the1239 * control1240 */1241 if (conditionAnswer.getResultMessage().getMessage().getCodeString().equals("PE")1242 || exe.getManualExecution().equals("Y")) {1243 if (execute_Control || exe.getManualExecution().equals("Y")) {1244 /**1245 * We execute the control1246 */1247 controlExe = executeControl(controlExe, exe);1248 /**1249 * We update the Action with the execution message and1250 * stop flag from the control. We update the status only1251 * if the control is not OK. This is to prevent moving1252 * the status to OK when it should stay KO when a1253 * control failed previously.1254 */1255 actionExe.setStopExecution(controlExe.isStopExecution());1256 if (!(controlExe.getControlResultMessage().equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS)))) {1257 //NA is a special case of not having success while calculating the property; the action shouldn't be stopped1258 if (controlExe.getControlResultMessage().equals(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_NO_PROPERTY_DEFINITION))) {1259 //restores the messages information if the property is not defined for the country1260 actionExe.setActionResultMessage(actionMessage);1261 actionExe.setExecutionResultMessage(excutionResultMessage);1262 } else {1263 actionExe.setExecutionResultMessage(controlExe.getExecutionResultMessage());1264 actionExe.setActionResultMessage(controlExe.getControlResultMessage());1265 }1266 }1267 /**1268 * If Control reported to stop the testcase, we stop it.1269 */...

Full Screen

Full Screen

setStopExecution

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.TestCaseStepExecution;2import org.cerberus.crud.entity.TestCaseExecution;3import org.cerberus.crud.entity.TestCaseExecutionData;4import org.cerberus.crud.entity.TestCaseExecutionDataLib;5import org.cerberus.crud.entity.TestCaseExecutionQueue;6import o

Full Screen

Full Screen

setStopExecution

Using AI Code Generation

copy

Full Screen

1if(condition){2 setStopExecution("This is a test case step", "KO");3}4setStopExecution("This is a test case step", "KO");5if(condition){6 return "This is a test case step", "KO";7}8return "This is a test case step", "KO";

Full Screen

Full Screen

setStopExecution

Using AI Code Generation

copy

Full Screen

1String stopExecution = test.testData.getData("stopExecution");2if (stopExecution.equals("Y")) {3 testCaseStepExecution.setStopExecution(true);4 testCaseStepExecution.setExecutionResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_FA));5 testCaseStepExecution.setExecutionResult(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_STOPTEST));6}7testCaseStepExecution.setExecutionResult(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_STOPTEST));8testCaseStepExecution.setExecutionResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_OK));9if (!stopExecution.equals("Y")) {10 testCaseStepExecution.setExecutionResult(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_STOPTEST));11 testCaseStepExecution.setExecutionResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_OK));12}13testCaseStepExecution.setExecutionResult(new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_STOPTEST));14testCaseStepExecution.setExecutionResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_OK));

Full Screen

Full Screen

setStopExecution

Using AI Code Generation

copy

Full Screen

1myProperty = getProperty("myProperty");2if (myProperty != null) {3 if (myProperty.equals("true")) {4 setStopExecution(true);5 }6}7myProperty = getProperty("myProperty");8if (myProperty != null) {9 if (myProperty.equals("true")) {10 setStopExecution(true);11 }12}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful