Best Cerberus-source code snippet using org.cerberus.crud.entity.TestCaseStepActionControlExecution.getConditionVal3
Source:ExecutionRunService.java
...472 } catch (CerberusEventException cex) {473 LOG.warn(cex);474 }475 try {476 answerDecode = variableService.decodeStringCompletly(tCExecution.getConditionVal3(), tCExecution, null, false);477 tCExecution.setConditionVal3((String) answerDecode.getItem());478 if (!(answerDecode.isCodeStringEquals("OK"))) {479 // If anything wrong with the decode --> we stop here with decode message in the action result.480 tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_DECODE)481 .resolveDescription("MES", answerDecode.getMessageDescription())482 .resolveDescription("AREA", "TestCase Condition Value3"));483 tCExecution.setEnd(new Date().getTime());484 LOG.debug(logPrefix + "TestCase interupted due to decode 'TestCase Condition Value3Error.");485 conditionDecodeError = true;486 }487 } catch (CerberusEventException cex) {488 LOG.warn(cex);489 }490 }491 if (!conditionDecodeError) {492 conditionAnswerTc = this.conditionService.evaluateCondition(tCExecution.getConditionOper(), tCExecution.getConditionVal1(), tCExecution.getConditionVal2(), tCExecution.getConditionVal3(), tCExecution);493 boolean execute_TestCase = (boolean) conditionAnswerTc.getItem();494 if (execute_TestCase || tCExecution.getManualExecution().equals("Y")) {495 boolean doStepStopExecution = false;496 for (TestCaseStep testCaseStep : mainExecutionTestCaseStepList) {497 // exeMod management : We trigger Forced Step no matter if previous step execution asked to stop.498 if ((!doStepStopExecution) || (testCaseStep.getForceExe().equalsIgnoreCase("Y"))) {499 // init the index of the step in case we loop.500 int step_index = 1;501 boolean execute_Next_Step = false;502 TestCaseStepExecution testCaseStepExecution;503 int maxloop = parameterService.getParameterIntegerByKey("cerberus_loopstep_max", tCExecution.getApplicationObj().getSystem(), 20);504 // Step Loop management.505 do {506 /**507 * Start Execution of TestCaseStep508 */509 LOG.debug(logPrefix + "Start execution of testcasestep");510 long startStep = new Date().getTime();511 /**512 * Create and Register TestCaseStepExecution513 */514 MessageEvent stepMess = new MessageEvent(MessageEventEnum.STEP_PENDING)515 .resolveDescription("STEP", String.valueOf(testCaseStep.getSort()))516 .resolveDescription("STEPINDEX", String.valueOf(step_index));517 testCaseStepExecution = factoryTestCaseStepExecution.create(518 runID, testCaseStep.getTest(), testCaseStep.getTestCase(),519 testCaseStep.getStep(), step_index, testCaseStep.getSort(), testCaseStep.getLoop(), testCaseStep.getConditionOper(), testCaseStep.getConditionVal1(), testCaseStep.getConditionVal2(), testCaseStep.getConditionVal3(), testCaseStep.getConditionVal1(), testCaseStep.getConditionVal2(), testCaseStep.getConditionVal3(), null,520 startStep, 0, startStep, 0, new BigDecimal("0"), null, stepMess, testCaseStep, tCExecution,521 testCaseStep.getUseStep(), testCaseStep.getUseStepTest(), testCaseStep.getUseStepTestCase(), testCaseStep.getUseStepStep(), testCaseStep.getDescription());522 testCaseStepExecution.setLoop(testCaseStep.getLoop());523 testCaseStepExecutionService.insertTestCaseStepExecution(testCaseStepExecution);524 testCaseStepExecution.setExecutionResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_TESTSTARTED));525 /**526 * We populate the TestCaseStep inside the527 * execution List528 */529 tCExecution.addTestCaseStepExecutionList(testCaseStepExecution);530 // determine if step is executed (execute_Step) and if we trigger a new step execution after (execute_Next_Step)531 boolean execute_Step = true;532 boolean descriptionOrConditionStepDecodeError = false;533 boolean conditionStepError = false;534 AnswerItem<Boolean> conditionAnswer = new AnswerItem<>(new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_UNKNOWNCONDITION));535 if (testCaseStepExecution.getLoop().equals(TestCaseStep.LOOP_ONCEIFCONDITIONFALSE)536 || testCaseStepExecution.getLoop().equals(TestCaseStep.LOOP_ONCEIFCONDITIONTRUE)537 || testCaseStepExecution.getLoop().equals(TestCaseStep.LOOP_WHILECONDITIONFALSEDO)538 || testCaseStepExecution.getLoop().equals(TestCaseStep.LOOP_WHILECONDITIONTRUEDO)539 || testCaseStepExecution.getLoop().equals("")540 || step_index > 1) {541 // Decode Conditionvalue1 and Conditionvalue2 and Evaluate the condition at the Step level.542 try {543 answerDecode = variableService.decodeStringCompletly(testCaseStepExecution.getConditionVal1(), tCExecution, null, false);544 testCaseStepExecution.setConditionVal1((String) answerDecode.getItem());545 if (!(answerDecode.isCodeStringEquals("OK"))) {546 testCaseStepExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));547 testCaseStepExecution.setStepResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Step Condition Value1"));548 testCaseStepExecution.setReturnMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Step Condition Value1").getDescription());549 testCaseStepExecution.setReturnCode(answerDecode.getResultMessage().getCodeString());550 testCaseStepExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());551 testCaseStepExecution.setEnd(new Date().getTime());552 LOG.debug(logPrefix + "Step interupted due to decode 'Step Condition Value1' Error.");553 descriptionOrConditionStepDecodeError = true;554 }555 } catch (CerberusEventException cex) {556 LOG.warn(cex);557 }558 if (!descriptionOrConditionStepDecodeError) {559 try {560 answerDecode = variableService.decodeStringCompletly(testCaseStepExecution.getConditionVal2(), tCExecution, null, false);561 testCaseStepExecution.setConditionVal2((String) answerDecode.getItem());562 if (!(answerDecode.isCodeStringEquals("OK"))) {563 testCaseStepExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));564 testCaseStepExecution.setStepResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Step Condition Value2"));565 testCaseStepExecution.setReturnMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Step Condition Value2").getDescription());566 testCaseStepExecution.setReturnCode(answerDecode.getResultMessage().getCodeString());567 testCaseStepExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());568 testCaseStepExecution.setEnd(new Date().getTime());569 LOG.debug(logPrefix + "Step interupted due to decode 'Step Condition Value2' Error.");570 descriptionOrConditionStepDecodeError = true;571 }572 } catch (CerberusEventException cex) {573 LOG.warn(cex);574 }575 }576 if (!descriptionOrConditionStepDecodeError) {577 try {578 answerDecode = variableService.decodeStringCompletly(testCaseStepExecution.getConditionVal3(), tCExecution, null, false);579 testCaseStepExecution.setConditionVal3((String) answerDecode.getItem());580 if (!(answerDecode.isCodeStringEquals("OK"))) {581 testCaseStepExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));582 testCaseStepExecution.setStepResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Step Condition Value3"));583 testCaseStepExecution.setReturnMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Step Condition Value3").getDescription());584 testCaseStepExecution.setReturnCode(answerDecode.getResultMessage().getCodeString());585 testCaseStepExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());586 testCaseStepExecution.setEnd(new Date().getTime());587 LOG.debug(logPrefix + "Step interupted due to decode 'Step Condition Value3' Error.");588 descriptionOrConditionStepDecodeError = true;589 }590 } catch (CerberusEventException cex) {591 LOG.warn(cex);592 }593 }594 if (!descriptionOrConditionStepDecodeError) {595 try {596 answerDecode = variableService.decodeStringCompletly(testCaseStepExecution.getDescription(), tCExecution, null, false);597 testCaseStepExecution.setDescription((String) answerDecode.getItem());598 if (!(answerDecode.isCodeStringEquals("OK"))) {599 testCaseStepExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));600 testCaseStepExecution.setStepResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Step Description"));601 testCaseStepExecution.setReturnMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Step Description").getDescription());602 testCaseStepExecution.setReturnCode(answerDecode.getResultMessage().getCodeString());603 testCaseStepExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());604 testCaseStepExecution.setEnd(new Date().getTime());605 LOG.debug(logPrefix + "Step interupted due to decode 'Step Description' Error.");606 descriptionOrConditionStepDecodeError = true;607 }608 } catch (CerberusEventException cex) {609 LOG.warn(cex);610 }611 }612 if (!(descriptionOrConditionStepDecodeError)) {613 conditionAnswer = this.conditionService.evaluateCondition(testCaseStepExecution.getConditionOper(), testCaseStepExecution.getConditionVal1(), testCaseStepExecution.getConditionVal2(), testCaseStepExecution.getConditionVal3(), tCExecution);614 execute_Step = (boolean) conditionAnswer.getItem();615 if (conditionAnswer.getResultMessage().getMessage().getCodeString().equals("PE")) {616 // There were no error when performing the condition evaluation.617 switch (testCaseStepExecution.getLoop()) {618 case TestCaseStep.LOOP_ONCEIFCONDITIONFALSE:619 execute_Step = !execute_Step;620 execute_Next_Step = false;621 break;622 case TestCaseStep.LOOP_ONCEIFCONDITIONTRUE:623 case "":624 execute_Next_Step = false;625 break;626 case TestCaseStep.LOOP_WHILECONDITIONFALSEDO:627 case TestCaseStep.LOOP_DOWHILECONDITIONFALSE:628 execute_Step = !execute_Step;629 execute_Next_Step = execute_Step;630 break;631 case TestCaseStep.LOOP_WHILECONDITIONTRUEDO:632 case TestCaseStep.LOOP_DOWHILECONDITIONTRUE:633 execute_Next_Step = execute_Step;634 break;635 default:636 execute_Next_Step = false;637 }638 } else {639 // Error when performing the condition evaluation. We force no execution (false)640 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_CONDITION);641 mes.setDescription(mes.getDescription()642 .replace("%AREA%", "step ")643 .replace("%COND%", testCaseStepExecution.getConditionOper())644 .replace("%MES%", conditionAnswer.getResultMessage().getDescription()));645 tCExecution.setResultMessage(mes);646 testCaseStepExecution.setExecutionResultMessage(mes);647 testCaseStepExecution.setStepResultMessage(new MessageEvent(MessageEventEnum.CONDITION_TESTCASESTEP_FAILED)648 .resolveDescription("AREA", "")649 .resolveDescription("COND", testCaseStepExecution.getConditionOper())650 .resolveDescription("MESSAGE", conditionAnswer.getResultMessage().getDescription())651 );652 testCaseStepExecution.setEnd(new Date().getTime());653 LOG.debug(logPrefix + "Step interupted due to condition error.");654 conditionStepError = true;655 execute_Next_Step = false;656 execute_Step = false;657 }658 } else {659 // If anything wrong with the decode --> we stop here with decode message in the action result.660 tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_DECODE)661 .resolveDescription("AREA", "Step")662 .resolveDescription("MES", answerDecode.getMessageDescription()));663 tCExecution.setEnd(new Date().getTime());664 LOG.debug(logPrefix + "TestCase interupted due to decode Error.");665 // There was an error on decode so we stop everything.666 if (tCExecution.getManualExecution().equals("Y")) {667 execute_Next_Step = true;668 execute_Step = true;669 } else {670 execute_Next_Step = false;671 execute_Step = false;672 }673 }674 } else if (testCaseStepExecution.getLoop().equals(TestCaseStep.LOOP_DOWHILECONDITIONFALSE)675 || testCaseStepExecution.getLoop().equals(TestCaseStep.LOOP_DOWHILECONDITIONTRUE)) {676 // First Step execution for LOOP_DOWHILECONDITIONTRUE and LOOP_DOWHILECONDITIONFALSE --> We force the step execution and activate the next step execution.677 execute_Step = true;678 execute_Next_Step = true;679 } else {680 // First Step execution for Unknown Loop --> We force the step execution only once (default behaviour).681 execute_Step = true;682 execute_Next_Step = false;683 conditionAnswer.setResultMessage(new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_UNKNOWNCONDITION));684 }685 /**686 * Execute Step687 */688 LOG.debug(logPrefix + "Executing step : " + testCaseStepExecution.getTest() + " - " + testCaseStepExecution.getTestCase() + " - Step " + testCaseStepExecution.getStep() + " - Index " + testCaseStepExecution.getStep());689 if (execute_Step) {690 /**691 * We execute the step692 */693 testCaseStepExecution = this.executeStep(testCaseStepExecution, tCExecution);694 /**695 * Updating Execution Result Message only if696 * execution result message of the step is697 * not PE or OK.698 */699 if ((!(testCaseStepExecution.getExecutionResultMessage().equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_TESTSTARTED))))700 && (!(testCaseStepExecution.getExecutionResultMessage().equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_OK))))) {701 tCExecution.setResultMessage(testCaseStepExecution.getExecutionResultMessage());702 }703 if (testCaseStepExecution.getStepResultMessage().equals(new MessageEvent(MessageEventEnum.STEP_PENDING))) {704 testCaseStepExecution.setStepResultMessage(new MessageEvent(MessageEventEnum.STEP_SUCCESS));705 }706 testCaseStepExecutionService.updateTestCaseStepExecution(testCaseStepExecution);707 if (testCaseStepExecution.isStopExecution()) {708 break;709 }710 } else // We don't execute the step and record a generic execution.711 if ((!descriptionOrConditionStepDecodeError) && (!conditionStepError)) {712 /**713 * Register Step in database714 */715 LOG.debug(logPrefix + "Registering Step : " + testCaseStepExecution.getStep());716 // We change the Step message only if the Step is not executed due to condition.717 MessageEvent stepMes = new MessageEvent(MessageEventEnum.CONDITION_TESTCASESTEP_NOTEXECUTED);718 testCaseStepExecution.setStepResultMessage(stepMes);719 testCaseStepExecution.setReturnMessage(testCaseStepExecution.getReturnMessage()720 .replace("%COND%", testCaseStepExecution.getConditionOper())721 .replace("%LOOP%", testCaseStepExecution.getLoop())722 .replace("%MESSAGE%", conditionAnswer.getResultMessage().getDescription())723 );724 testCaseStepExecution.setEnd(new Date().getTime());725 this.testCaseStepExecutionService.updateTestCaseStepExecution(testCaseStepExecution);726 LOG.debug(logPrefix + "Registered Step");727 } else {728 // Not executed because decode error or failed condition.729 testCaseStepExecution.setEnd(new Date().getTime());730 testCaseStepExecution.setStopExecution(true);731 this.testCaseStepExecutionService.updateTestCaseStepExecution(testCaseStepExecution);732 LOG.debug(logPrefix + "Registered Step");733 }734 /**735 * Log TestCaseStepExecution736 */737 if (tCExecution.getVerbose() > 0) {738 LOG.info(testCaseStepExecution.toJson(false, true));739 }740 // Websocket --> we refresh the corresponding Detail Execution pages attached to this execution.741 updateTCExecutionWebSocketOnly(tCExecution, false);742 step_index++;743 } while (execute_Next_Step && step_index <= maxloop);744 // Step execution boolean is considered for next step execution only if current step was not forced or forced and failed.745 if (!testCaseStep.getForceExe().equalsIgnoreCase("Y") || testCaseStepExecution.isStopExecution()) {746 doStepStopExecution = testCaseStepExecution.isStopExecution();747 }748 }749 }750 /**751 * If at that time the execution is still PE, we move it to752 * OK. It means that no issue were met.753 */754 if ((tCExecution.getResultMessage() == null) || (tCExecution.getResultMessage().equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_TESTSTARTED)))) {755 tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_OK));756 }757 /**758 * We notify external robot provider of end of execution759 * status.760 */761 switch (tCExecution.getRobotProvider()) {762 case TestCaseExecution.ROBOTPROVIDER_BROWSERSTACK:763 browserstackService.setSessionStatus(tCExecution.getSystem(), tCExecution.getRobotSessionID(), tCExecution.getControlStatus(), tCExecution.getControlMessage(), tCExecution.getRobotExecutorObj().getHostUser(), tCExecution.getRobotExecutorObj().getHostPassword());764 break;765 case TestCaseExecution.ROBOTPROVIDER_KOBITON:766 kobitonService.setSessionStatus(tCExecution.getSystem(), tCExecution.getRobotSessionID(), tCExecution.getControlStatus(), tCExecution.getControlMessage(), tCExecution.getRobotExecutorObj().getHostUser(), tCExecution.getRobotExecutorObj().getHostPassword());767 break;768 }769 } else { // We don't execute the testcase linked with condition.770 MessageGeneral mes;771 /**772 * Update Execution status from condition773 */774 if (conditionAnswerTc.getResultMessage().getMessage().getCodeString().equals("PE")) {775 mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_NE_CONDITION);776 } else {777 mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_CONDITION);778 }779 mes.setDescription(mes.getDescription().replace("%COND%", tCExecution.getConditionOper())780 .replace("%MES%", conditionAnswerTc.getResultMessage().getDescription()));781 tCExecution.setResultMessage(mes);782 }783 }784 } catch (CerberusException ex) {785 /**786 * If an exception is found, set the execution to FA and print the787 * exception (only in debug mode)788 */789 MessageGeneral messageFin = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA);790 messageFin.setDescription(messageFin.getDescription() + " " + ex.getMessageError().getDescription());791 tCExecution.setResultMessage(messageFin);792 LOG.debug(logPrefix + "Exception found Executing Test " + tCExecution.getId() + " : " + ex.getMessageError().getDescription());793 } catch (Exception ex) {794 /**795 * If an exception is found, set the execution to FA and print the796 * exception797 */798 MessageGeneral messageFin = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA);799 messageFin.setDescription(messageFin.getDescription() + " " + ex.getMessage());800 tCExecution.setResultMessage(messageFin);801 tCExecution.setControlMessage(tCExecution.getControlMessage() + " Exception: " + ex);802 LOG.error(logPrefix + "Exception found Executing Test " + tCExecution.getId(), ex);803 } finally {804 /**805 * We stop the server session here (selenium for ex.).806 */807 try {808 if (videoRecorder != null) {809 videoRecorder.endRecordVideo();810 }811 tCExecution = this.stopTestCase(tCExecution);812 } catch (Exception ex) {813 LOG.error(logPrefix + "Exception Stopping Test " + tCExecution.getId() + " Exception : " + ex.toString(), ex);814 }815 /**816 * Log Execution817 */818 LOG.info(tCExecution.toJson(false));819 /**820 * Clean memory821 */822 try {823 executionUUID.removeExecutionUUID(tCExecution.getExecutionUUID());824 LOG.debug(logPrefix + "Clean ExecutionUUID");825 } catch (Exception ex) {826 LOG.error(logPrefix + "Exception cleaning Memory: " + ex.toString(), ex);827 }828 /**829 * Log execution is finished830 */831 LOG.info("Execution Finished : UUID=" + tCExecution.getExecutionUUID()832 + " ID=" + tCExecution.getId() + " RC=" + tCExecution.getControlStatus() + " "833 + "TestName=" + tCExecution.getEnvironment() + "." + tCExecution.getCountry() + "."834 + tCExecution.getBuild() + "." + tCExecution.getRevision() + "." + tCExecution.getTest() + "_"835 + tCExecution.getTestCase() + "_" + tCExecution.getTestCaseObj().getDescription().replace(".", ""));836 /**837 * Retry management, in case the result is not (OK or NE), we838 * execute the job again reducing the retry to 1.839 */840 boolean isRetried = retriesService.manageRetries(tCExecution);841 /**842 * Updating queue to done status only for execution from queue843 */844 if (tCExecution.getQueueID() != 0) {845 executionQueueService.updateToDone(tCExecution.getQueueID(), "", runID);846 }847 /**848 * After every execution finished, <br>849 * if the execution has a tag that has a campaign associated <br>850 * and no more executions are in the queue, <br>851 * we trigger : <br>852 * 1/ The update of the EndExeQueue of the tag <br>853 * 2/ We notify the Distribution List with execution report status854 */855 tagService.manageCampaignEndOfExecution(tCExecution.getTag());856 /**857 * Dependency management, At the end of the execution, we RELEASE858 * the corresponding dependencies and put corresponding Queue859 * entries to QUEUED status.860 */861 if (!isRetried) {862 testCaseExecutionQueueDepService.manageDependenciesEndOfExecution(tCExecution);863 }864 // After every execution finished we try to trigger more from the queue;-).865 executionThreadPoolService.executeNextInQueueAsynchroneously(false);866 }867 return tCExecution;868 }869 // Update Execution status and eventually push the new value to websocket.870 private void updateTCExecution(TestCaseExecution tCExecution, boolean forcePush) {871 try {872 testCaseExecutionService.updateTCExecution(tCExecution);873 } catch (CerberusException ex) {874 LOG.warn(ex);875 }876 updateTCExecutionWebSocketOnly(tCExecution, forcePush);877 }878 private void updateTCExecutionWebSocketOnly(TestCaseExecution tCExecution, boolean forcePush) {879 // Websocket --> we refresh the corresponding Detail Execution pages attached to this execution.880 if (tCExecution.isCerberus_featureflipping_activatewebsocketpush()) {881 TestCaseExecutionEndPoint.getInstance().send(tCExecution, forcePush);882 }883 }884 @Override885 public TestCaseExecution stopTestCase(TestCaseExecution tCExecution) {886 /**887 * Stop Execution888 */889 LOG.debug(tCExecution.getId() + " - Stop the execution " + tCExecution.getId() + " UUID:" + tCExecution.getExecutionUUID());890 try {891 //TODO:FN debug messages to be removed892 LOG.debug("[DEBUG] STOP " + " ID=" + tCExecution.getId());893 this.stopRunTestCase(tCExecution);894 } catch (Exception ex) {895 LOG.warn("Exception Stopping Execution " + tCExecution.getId() + " Exception :" + ex.toString());896 }897 /**898 * Collecting and calculating Statistics.899 */900 try {901// this.collectExecutionStats(tCExecution);902 } catch (Exception ex) {903 LOG.warn("Exception collecting stats for execution " + tCExecution.getId() + " Exception:" + ex.toString());904 }905 /**906 * Saving TestCaseExecution object.907 */908 tCExecution.setEnd(new Date().getTime());909 try {910 testCaseExecutionService.updateTCExecution(tCExecution);911 } catch (CerberusException ex) {912 LOG.warn("Exception updating Execution :" + tCExecution.getId() + " Exception:" + ex.toString());913 }914 // Websocket --> we refresh the corresponding Detail Execution pages attached to this execution.915 if (tCExecution.isCerberus_featureflipping_activatewebsocketpush()) {916 TestCaseExecutionEndPoint.getInstance().send(tCExecution, true);917 TestCaseExecutionEndPoint.getInstance().end(tCExecution);918 }919 return tCExecution;920 }921 private TestCaseStepExecution executeStep(TestCaseStepExecution testCaseStepExecution, TestCaseExecution tcExecution) {922 long runID = testCaseStepExecution.getId();923 String logPrefix = runID + " - ";924 AnswerItem<String> answerDecode = new AnswerItem<>();925 // Initialise the Step Data List.926 List<TestCaseExecutionData> myStepDataList = new ArrayList<TestCaseExecutionData>();927 testCaseStepExecution.setTestCaseExecutionDataList(myStepDataList);928 // Initialise the Data List used to enter the action.929 /**930 * Iterate Actions931 */932 List<TestCaseStepAction> testCaseStepActionList = testCaseStepExecution.getTestCaseStep().getTestCaseStepAction();933 LOG.debug("Getting list of actions of the step. " + testCaseStepActionList.size() + " action(s) to perform.");934 for (TestCaseStepAction testCaseStepAction : testCaseStepActionList) {935 /**936 * Start Execution of TestCaseStepAction937 */938 long startAction = new Date().getTime();939 /**940 * Create and Register TestCaseStepActionExecution.941 */942 TestCaseStepActionExecution testCaseStepActionExecution = factoryTestCaseStepActionExecution.create(943 testCaseStepExecution.getId(), testCaseStepAction.getTest(), testCaseStepAction.getTestCase(),944 testCaseStepAction.getStep(), testCaseStepExecution.getIndex(), testCaseStepAction.getSequence(), testCaseStepAction.getSort(), null, null,945 testCaseStepAction.getConditionOper(), testCaseStepAction.getConditionVal1(), testCaseStepAction.getConditionVal2(), testCaseStepAction.getConditionVal3(),946 testCaseStepAction.getConditionVal1(), testCaseStepAction.getConditionVal2(), testCaseStepAction.getConditionVal3(),947 testCaseStepAction.getAction(), testCaseStepAction.getValue1(), testCaseStepAction.getValue2(), testCaseStepAction.getValue3(), testCaseStepAction.getValue1(),948 testCaseStepAction.getValue2(), testCaseStepAction.getValue3(),949 testCaseStepAction.getForceExeStatus(), startAction, 0, startAction, 0, new MessageEvent(MessageEventEnum.ACTION_PENDING),950 testCaseStepAction.getDescription(), testCaseStepAction, testCaseStepExecution);951 this.testCaseStepActionExecutionService.insertTestCaseStepActionExecution(testCaseStepActionExecution);952 /**953 * We populate the TestCase Action List954 */955 testCaseStepExecution.addTestCaseStepActionExecutionList(testCaseStepActionExecution);956 /**957 * If execution is not manual, evaluate the condition at the action958 * level959 */960 AnswerItem<Boolean> conditionAnswer;961 boolean conditionDecodeError = false;962 if (!tcExecution.getManualExecution().equals("Y")) {963 try {964 answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getConditionVal1(), tcExecution, null, false);965 testCaseStepActionExecution.setConditionVal1((String) answerDecode.getItem());966 if (!(answerDecode.isCodeStringEquals("OK"))) {967 // If anything wrong with the decode --> we stop here with decode message in the action result.968 testCaseStepActionExecution.setActionResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Action Condition Value1"));969 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));970 testCaseStepActionExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());971 testCaseStepActionExecution.setEnd(new Date().getTime());972 LOG.debug("Action interupted due to decode 'Action Condition Value1' Error.");973 conditionDecodeError = true;974 }975 } catch (CerberusEventException cex) {976 LOG.warn(cex);977 }978 try {979 answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getConditionVal2(), tcExecution, null, false);980 testCaseStepActionExecution.setConditionVal2((String) answerDecode.getItem());981 if (!(answerDecode.isCodeStringEquals("OK"))) {982 // If anything wrong with the decode --> we stop here with decode message in the action result.983 testCaseStepActionExecution.setActionResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Action Condition Value2"));984 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));985 testCaseStepActionExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());986 testCaseStepActionExecution.setEnd(new Date().getTime());987 LOG.debug("Action interupted due to decode 'Action Condition Value2' Error.");988 conditionDecodeError = true;989 }990 } catch (CerberusEventException cex) {991 LOG.warn(cex);992 }993 try {994 answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getConditionVal3(), tcExecution, null, false);995 testCaseStepActionExecution.setConditionVal3((String) answerDecode.getItem());996 if (!(answerDecode.isCodeStringEquals("OK"))) {997 // If anything wrong with the decode --> we stop here with decode message in the action result.998 testCaseStepActionExecution.setActionResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Action Condition Value3"));999 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));1000 testCaseStepActionExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());1001 testCaseStepActionExecution.setEnd(new Date().getTime());1002 LOG.debug("Action interupted due to decode 'Action Condition Value3' Error.");1003 conditionDecodeError = true;1004 }1005 } catch (CerberusEventException cex) {1006 LOG.warn(cex);1007 }1008 }1009 if (!(conditionDecodeError)) {1010 conditionAnswer = this.conditionService.evaluateCondition(testCaseStepActionExecution.getConditionOper(), testCaseStepActionExecution.getConditionVal1(), testCaseStepActionExecution.getConditionVal2(), testCaseStepActionExecution.getConditionVal3(), tcExecution);1011 boolean execute_Action = (boolean) conditionAnswer.getItem();1012 /**1013 * If condition OK or if manual execution, then execute the1014 * action1015 */1016 if (conditionAnswer.getResultMessage().getMessage().getCodeString().equals("PE")1017 || tcExecution.getManualExecution().equals("Y")) {1018 // Execute or not the action here.1019 if (execute_Action || tcExecution.getManualExecution().equals("Y")) {1020 LOG.debug("Executing action : " + testCaseStepActionExecution.getAction() + " with val1 : " + testCaseStepActionExecution.getValue1()1021 + " and val2 : " + testCaseStepActionExecution.getValue2()1022 + " and val3 : " + testCaseStepActionExecution.getValue3());1023 /**1024 * We execute the Action1025 */1026 testCaseStepActionExecution = this.executeAction(testCaseStepActionExecution, tcExecution);1027 /**1028 * If Action or property reported to stop the testcase,1029 * we stop it and update the step with the message.1030 */1031 testCaseStepExecution.setStopExecution(testCaseStepActionExecution.isStopExecution());1032 if ((!(testCaseStepActionExecution.getExecutionResultMessage().equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_OK))))1033 && (!(testCaseStepActionExecution.getExecutionResultMessage().equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_TESTEXECUTING))))) {1034 testCaseStepExecution.setExecutionResultMessage(testCaseStepActionExecution.getExecutionResultMessage());1035 testCaseStepExecution.setStepResultMessage(testCaseStepActionExecution.getActionResultMessage());1036 }1037 if (testCaseStepActionExecution.isStopExecution()) {1038 break;1039 }1040 } else { // We don't execute the action and record a generic execution.1041 /**1042 * Record Screenshot, PageSource1043 */1044 testCaseStepActionExecution.addFileList(recorderService.recordExecutionInformationAfterStepActionandControl(testCaseStepActionExecution, null));1045 LOG.debug("Registering Action : " + testCaseStepActionExecution.getAction());1046 // We change the Action message only if the action is not executed due to condition.1047 MessageEvent actionMes = new MessageEvent(MessageEventEnum.CONDITION_TESTCASEACTION_NOTEXECUTED);1048 testCaseStepActionExecution.setActionResultMessage(actionMes);1049 testCaseStepActionExecution.setReturnMessage(testCaseStepActionExecution.getReturnMessage()1050 .replace("%COND%", testCaseStepActionExecution.getConditionOper())1051 .replace("%MESSAGE%", conditionAnswer.getResultMessage().getDescription())1052 );1053 testCaseStepActionExecution.setEnd(new Date().getTime());1054 this.testCaseStepActionExecutionService.updateTestCaseStepActionExecution(testCaseStepActionExecution);1055 LOG.debug("Registered Action");1056 }1057 } else {1058 // Error when performing the condition evaluation. We force no execution (false)1059 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_CONDITION);1060 mes.setDescription(mes.getDescription()1061 .replace("%COND%", testCaseStepActionExecution.getConditionOper())1062 .replace("%AREA%", "action ")1063 .replace("%MES%", conditionAnswer.getResultMessage().getDescription()));1064 testCaseStepActionExecution.setExecutionResultMessage(mes);1065 testCaseStepExecution.setExecutionResultMessage(testCaseStepActionExecution.getExecutionResultMessage());1066 testCaseStepActionExecution.setActionResultMessage(new MessageEvent(MessageEventEnum.CONDITION_TESTCASEACTION_FAILED)1067 .resolveDescription("AREA", "")1068 .resolveDescription("COND", testCaseStepActionExecution.getConditionOper())1069 .resolveDescription("MESSAGE", conditionAnswer.getResultMessage().getDescription()));1070 testCaseStepExecution.setStepResultMessage(new MessageEvent(MessageEventEnum.CONDITION_TESTCASESTEP_FAILED)1071 .resolveDescription("AREA", "action ")1072 .resolveDescription("COND", testCaseStepActionExecution.getConditionOper())1073 .resolveDescription("MESSAGE", conditionAnswer.getResultMessage().getDescription()));1074 if (testCaseStepActionExecution.getForceExeStatus().equals("PE")) {1075 testCaseStepActionExecution.setStopExecution(false);1076 MessageEvent actionMes = testCaseStepActionExecution.getActionResultMessage();1077 actionMes.setDescription(testCaseStepActionExecution.getActionResultMessage().getDescription() + " -- Execution forced to continue.");1078 testCaseStepActionExecution.setActionResultMessage(actionMes);1079 } else {1080 testCaseStepActionExecution.setStopExecution(true);1081 }1082 testCaseStepExecution.setStopExecution(testCaseStepActionExecution.isStopExecution());1083 testCaseStepActionExecution.setEnd(new Date().getTime());1084 this.testCaseStepActionExecutionService.updateTestCaseStepActionExecution(testCaseStepActionExecution);1085 LOG.debug("Action interupted due to condition error.");1086 // We stop any further Action execution.1087 if (testCaseStepActionExecution.isStopExecution()) {1088 break;1089 }1090 }1091 } else {1092 testCaseStepActionExecution.setEnd(new Date().getTime());1093 testCaseStepExecution.setExecutionResultMessage(testCaseStepActionExecution.getExecutionResultMessage());1094 testCaseStepExecution.setStepResultMessage(testCaseStepActionExecution.getActionResultMessage());1095 testCaseStepExecution.setStopExecution(testCaseStepActionExecution.isStopExecution());1096 this.testCaseStepActionExecutionService.updateTestCaseStepActionExecution(testCaseStepActionExecution);1097 LOG.debug("Registered Action");1098 if (testCaseStepActionExecution.isStopExecution()) {1099 break;1100 }1101 }1102 /**1103 * Log TestCaseStepActionExecution1104 */1105 if (tcExecution.getVerbose() > 0) {1106 LOG.info(testCaseStepActionExecution.toJson(false, true));1107 }1108 }1109 testCaseStepExecution.setEnd(new Date().getTime());1110 this.testCaseStepExecutionService.updateTestCaseStepExecution(testCaseStepExecution);1111 updateTCExecutionWebSocketOnly(tcExecution, false);1112 return testCaseStepExecution;1113 }1114 private TestCaseStepActionExecution executeAction(TestCaseStepActionExecution testCaseStepActionExecution, TestCaseExecution tcExecution) {1115 LOG.debug("Starting execute Action : " + testCaseStepActionExecution.getAction());1116 AnswerItem<String> answerDecode = new AnswerItem<>();1117 /**1118 * If execution is not manual, do action and record files1119 */1120 if (!tcExecution.getManualExecution().equals("Y")) {1121 testCaseStepActionExecution = this.actionService.doAction(testCaseStepActionExecution);1122 /**1123 * Record Screenshot, PageSource1124 */1125 try {1126 testCaseStepActionExecution.addFileList(recorderService.recordExecutionInformationAfterStepActionandControl(testCaseStepActionExecution, null));1127 } catch (Exception ex) {1128 LOG.warn("Unable to record Screenshot/PageSource : " + ex.toString(), ex);1129 }1130 } else {1131 /**1132 * If execution manual, set Action result message as notExecuted1133 */1134 testCaseStepActionExecution.setActionResultMessage(new MessageEvent(MessageEventEnum.ACTION_WAITINGFORMANUALEXECUTION));1135 testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_WE));1136 testCaseStepActionExecution.setEnd(new Date().getTime());1137 }1138 /**1139 * Register Action in database1140 */1141 LOG.debug("Registering Action : " + testCaseStepActionExecution.getAction());1142 this.testCaseStepActionExecutionService.updateTestCaseStepActionExecution(testCaseStepActionExecution);1143 LOG.debug("Registered Action");1144 if (testCaseStepActionExecution.isStopExecution()) {1145 return testCaseStepActionExecution;1146 }1147 //As controls are associated with an action, the current state for the action is stored in order to restore it1148 //if some property is not defined for the country1149 MessageEvent actionMessage = testCaseStepActionExecution.getActionResultMessage();1150 MessageGeneral excutionResultMessage = testCaseStepActionExecution.getExecutionResultMessage();1151 /**1152 * Iterate Control1153 */1154 List<TestCaseStepActionControl> tcsacList = testCaseStepActionExecution.getTestCaseStepAction().getTestCaseStepActionControl();1155 for (TestCaseStepActionControl testCaseStepActionControl : tcsacList) {1156 /**1157 * Start Execution of TestCAseStepActionControl1158 */1159 long startControl = new Date().getTime();1160 /**1161 * Create and Register TestCaseStepActionControlExecution1162 */1163 LOG.debug("Creating TestCaseStepActionControlExecution");1164 TestCaseStepActionControlExecution testCaseStepActionControlExecution1165 = factoryTestCaseStepActionControlExecution.create(testCaseStepActionExecution.getId(), testCaseStepActionControl.getTest(), testCaseStepActionControl.getTestCase(),1166 testCaseStepActionControl.getStep(), testCaseStepActionExecution.getIndex(), testCaseStepActionControl.getSequence(), testCaseStepActionControl.getControlSequence(), testCaseStepActionControl.getSort(),1167 null, null,1168 testCaseStepActionControl.getConditionOper(), testCaseStepActionControl.getConditionVal1(), testCaseStepActionControl.getConditionVal2(), testCaseStepActionControl.getConditionVal3(), testCaseStepActionControl.getConditionVal1(), testCaseStepActionControl.getConditionVal2(), testCaseStepActionControl.getConditionVal3(),1169 testCaseStepActionControl.getControl(), testCaseStepActionControl.getValue1(), testCaseStepActionControl.getValue2(), testCaseStepActionControl.getValue3(), testCaseStepActionControl.getValue1(), testCaseStepActionControl.getValue2(),1170 testCaseStepActionControl.getValue3(), testCaseStepActionControl.getFatal(), startControl, 0, 0, 0,1171 testCaseStepActionControl.getDescription(), testCaseStepActionExecution, new MessageEvent(MessageEventEnum.CONTROL_PENDING));1172 this.testCaseStepActionControlExecutionService.insertTestCaseStepActionControlExecution(testCaseStepActionControlExecution);1173 LOG.debug("Executing control : " + testCaseStepActionControlExecution.getControlSequence() + " type : " + testCaseStepActionControlExecution.getControl());1174 /**1175 * We populate the TestCase Control List1176 */1177 testCaseStepActionExecution.addTestCaseStepActionExecutionList(testCaseStepActionControlExecution);1178 // Evaluate the condition at the control level.1179 AnswerItem<Boolean> conditionAnswer;1180 boolean conditionDecodeError = false;1181 if (!tcExecution.getManualExecution().equals("Y")) {1182 try {1183 answerDecode = variableService.decodeStringCompletly(testCaseStepActionControlExecution.getConditionVal1(), tcExecution, null, false);1184 testCaseStepActionControlExecution.setConditionVal1((String) answerDecode.getItem());1185 if (!(answerDecode.isCodeStringEquals("OK"))) {1186 // If anything wrong with the decode --> we stop here with decode message in the action result.1187 testCaseStepActionControlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Condition Value1"));1188 testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));1189 testCaseStepActionControlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());1190 testCaseStepActionControlExecution.setEnd(new Date().getTime());1191 LOG.debug("Control interupted due to decode 'Control Condition Value1' Error.");1192 conditionDecodeError = true;1193 }1194 } catch (CerberusEventException cex) {1195 LOG.warn(cex);1196 }1197 try {1198 answerDecode = variableService.decodeStringCompletly(testCaseStepActionControlExecution.getConditionVal2(), tcExecution, null, false);1199 testCaseStepActionControlExecution.setConditionVal2((String) answerDecode.getItem());1200 if (!(answerDecode.isCodeStringEquals("OK"))) {1201 // If anything wrong with the decode --> we stop here with decode message in the action result.1202 testCaseStepActionControlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Condition Value2"));1203 testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));1204 testCaseStepActionControlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());1205 testCaseStepActionControlExecution.setEnd(new Date().getTime());1206 LOG.debug("Control interupted due to decode 'Control Condition Value2' Error.");1207 conditionDecodeError = true;1208 }1209 } catch (CerberusEventException cex) {1210 LOG.warn(cex);1211 }1212 try {1213 answerDecode = variableService.decodeStringCompletly(testCaseStepActionControlExecution.getConditionVal3(), tcExecution, null, false);1214 testCaseStepActionControlExecution.setConditionVal3((String) answerDecode.getItem());1215 if (!(answerDecode.isCodeStringEquals("OK"))) {1216 // If anything wrong with the decode --> we stop here with decode message in the action result.1217 testCaseStepActionControlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Condition Value3"));1218 testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));1219 testCaseStepActionControlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());1220 testCaseStepActionControlExecution.setEnd(new Date().getTime());1221 LOG.debug("Control interupted due to decode 'Control Condition Value3' Error.");1222 conditionDecodeError = true;1223 }1224 } catch (CerberusEventException cex) {1225 LOG.warn(cex);1226 }1227 }1228 if (!(conditionDecodeError)) {1229 conditionAnswer = this.conditionService.evaluateCondition(testCaseStepActionControlExecution.getConditionOper(), testCaseStepActionControlExecution.getConditionVal1(), testCaseStepActionControlExecution.getConditionVal2(), testCaseStepActionControlExecution.getConditionVal3(), tcExecution);1230 boolean execute_Control = (boolean) conditionAnswer.getItem();1231 /**1232 * If condition OK or if manual execution, then execute the1233 * control1234 */1235 if (conditionAnswer.getResultMessage().getMessage().getCodeString().equals("PE")1236 || tcExecution.getManualExecution().equals("Y")) {1237 if (execute_Control || tcExecution.getManualExecution().equals("Y")) {1238 /**1239 * We execute the control1240 */1241 testCaseStepActionControlExecution = executeControl(testCaseStepActionControlExecution, tcExecution);1242 /**1243 * We update the Action with the execution message and...
getConditionVal3
Using AI Code Generation
1String expectedValue = "test";2String actualValue = getConditionVal3();3if (actualValue.equals(expectedValue)) {4} else {5}6String expectedValue = "test";7String actualValue = getConditionVal3();8if (actualValue.equals(expectedValue)) {9} else {10}11Parameter Description getConditionOperator3() Returns the condition operator. getConditionVal1() Returns the first value of the condition. getConditionVal2() Returns the second value of the condition. getConditionVal3() Returns the third value of the condition. getControl() Returns the control. getControlMessage() Returns the control message. getControlProperty() Returns the control property. getControlType() Returns the control type. getControlValue() Returns the control value. getEnd() Returns the end date. getExecutionResultMessage() Returns the execution result message. getExecutionResultMessageToReport() Returns the execution result message to report. getExecutionResultPicture() Returns the execution result picture. getExecutionResultPictureToReport() Returns the execution result picture to report. getExecutionResultVideo() Returns the execution result video. getExecutionResultVideoToReport() Returns the execution result video to report. getExecutionTime() Returns the execution time. getFullEnd() Returns the full end date. getFullStart() Returns the full start date. getManualExecution() Returns the manual execution. getManualUrl() Returns the manual URL. getManualHost() Returns the manual host. getManualContextRoot() Returns the manual context root. getManualLoginRelativeURL() Returns the manual login relative URL. getManualEnvData() Returns the manual environment data. getManualCountry() Returns the manual country. getManualBrowser() Returns the manual browser. getManualIP() Returns the manual IP. getManualPlatform() Returns the manual platform. getManualVersion() Returns the manual version. getManualScreenSize() Returns the manual screen
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!