use of org.cerberus.crud.entity.TestCaseStepAction in project cerberus-source by cerberustesting.
the class FactoryTestCaseStepAction method create.
@Override
public TestCaseStepAction create(String test, String testCase, int step, int sequence, int sort, String conditionOper, String conditionVal1, String conditionVal2, String action, String value1, String value2, String forceExeStatus, String description, String screenshotFilename) {
TestCaseStepAction testCaseStepAction = new TestCaseStepAction();
testCaseStepAction.setConditionOper(conditionOper);
testCaseStepAction.setConditionVal1(conditionVal1);
testCaseStepAction.setConditionVal2(conditionVal2);
testCaseStepAction.setAction(action);
testCaseStepAction.setValue1(value1);
testCaseStepAction.setValue2(value2);
testCaseStepAction.setForceExeStatus(forceExeStatus);
testCaseStepAction.setSequence(sequence);
testCaseStepAction.setStep(step);
testCaseStepAction.setSort(sort);
testCaseStepAction.setTest(test);
testCaseStepAction.setTestCase(testCase);
testCaseStepAction.setDescription(description);
testCaseStepAction.setScreenshotFilename(screenshotFilename);
return testCaseStepAction;
}
use of org.cerberus.crud.entity.TestCaseStepAction in project cerberus-source by cerberustesting.
the class ExecutionRunService method executeStep.
private TestCaseStepExecution executeStep(TestCaseStepExecution testCaseStepExecution, TestCaseExecution tcExecution) {
long runID = testCaseStepExecution.getId();
String logPrefix = runID + " - ";
AnswerItem<String> answerDecode = new AnswerItem();
// Initialise the Step Data List.
List<TestCaseExecutionData> myStepDataList = new ArrayList<TestCaseExecutionData>();
testCaseStepExecution.setTestCaseExecutionDataList(myStepDataList);
// Initialise the Data List used to enter the action.
/**
* Iterate Actions
*/
List<TestCaseStepAction> testCaseStepActionList = testCaseStepExecution.getTestCaseStep().getTestCaseStepAction();
LOG.debug("Getting list of actions of the step. " + testCaseStepActionList.size() + " action(s) to perform.");
for (TestCaseStepAction testCaseStepAction : testCaseStepActionList) {
/**
* Start Execution of TestCaseStepAction
*/
long startAction = new Date().getTime();
/**
* Create and Register TestCaseStepActionExecution.
*/
TestCaseStepActionExecution testCaseStepActionExecution = factoryTestCaseStepActionExecution.create(testCaseStepExecution.getId(), testCaseStepAction.getTest(), testCaseStepAction.getTestCase(), testCaseStepAction.getStep(), testCaseStepExecution.getIndex(), testCaseStepAction.getSequence(), testCaseStepAction.getSort(), null, null, testCaseStepAction.getConditionOper(), testCaseStepAction.getConditionVal1(), testCaseStepAction.getConditionVal2(), testCaseStepAction.getConditionVal1(), testCaseStepAction.getConditionVal2(), testCaseStepAction.getAction(), testCaseStepAction.getValue1(), testCaseStepAction.getValue2(), testCaseStepAction.getValue1(), testCaseStepAction.getValue2(), testCaseStepAction.getForceExeStatus(), startAction, 0, startAction, 0, new MessageEvent(MessageEventEnum.ACTION_PENDING), testCaseStepAction.getDescription(), testCaseStepAction, testCaseStepExecution);
this.testCaseStepActionExecutionService.insertTestCaseStepActionExecution(testCaseStepActionExecution);
/**
* We populate the TestCase Action List
*/
testCaseStepExecution.addTestCaseStepActionExecutionList(testCaseStepActionExecution);
/**
* If execution is not manual, evaluate the condition at the action
* level
*/
AnswerItem<Boolean> conditionAnswer;
boolean conditionDecodeError = false;
if (!tcExecution.getManualExecution().equals("Y")) {
try {
answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getConditionVal1(), tcExecution, null, false);
testCaseStepActionExecution.setConditionVal1((String) answerDecode.getItem());
if (!(answerDecode.isCodeStringEquals("OK"))) {
// If anything wrong with the decode --> we stop here with decode message in the action result.
testCaseStepActionExecution.setActionResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Action Condition Value1"));
testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));
testCaseStepActionExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());
testCaseStepActionExecution.setEnd(new Date().getTime());
LOG.debug("Action interupted due to decode 'Action Condition Value1' Error.");
conditionDecodeError = true;
}
} catch (CerberusEventException cex) {
LOG.warn(cex);
}
try {
answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getConditionVal2(), tcExecution, null, false);
testCaseStepActionExecution.setConditionVal2((String) answerDecode.getItem());
if (!(answerDecode.isCodeStringEquals("OK"))) {
// If anything wrong with the decode --> we stop here with decode message in the action result.
testCaseStepActionExecution.setActionResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Action Condition Value2"));
testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));
testCaseStepActionExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());
testCaseStepActionExecution.setEnd(new Date().getTime());
LOG.debug("Action interupted due to decode 'Action Condition Value2' Error.");
conditionDecodeError = true;
}
} catch (CerberusEventException cex) {
LOG.warn(cex);
}
}
if (!(conditionDecodeError)) {
conditionAnswer = this.conditionService.evaluateCondition(testCaseStepActionExecution.getConditionOper(), testCaseStepActionExecution.getConditionVal1(), testCaseStepActionExecution.getConditionVal2(), tcExecution);
boolean execute_Action = (boolean) conditionAnswer.getItem();
/**
* If condition OK or if manual execution, then execute the
* action
*/
if (conditionAnswer.getResultMessage().getMessage().getCodeString().equals("PE") || tcExecution.getManualExecution().equals("Y")) {
// Execute or not the action here.
if (execute_Action || tcExecution.getManualExecution().equals("Y")) {
LOG.debug("Executing action : " + testCaseStepActionExecution.getAction() + " with val1 : " + testCaseStepActionExecution.getValue1() + " and val2 : " + testCaseStepActionExecution.getValue2());
/**
* We execute the Action
*/
testCaseStepActionExecution = this.executeAction(testCaseStepActionExecution, tcExecution);
/**
* If Action or property reported to stop the testcase,
* we stop it and update the step with the message.
*/
testCaseStepExecution.setStopExecution(testCaseStepActionExecution.isStopExecution());
if ((!(testCaseStepActionExecution.getExecutionResultMessage().equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_OK)))) && (!(testCaseStepActionExecution.getExecutionResultMessage().equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_TESTEXECUTING))))) {
testCaseStepExecution.setExecutionResultMessage(testCaseStepActionExecution.getExecutionResultMessage());
testCaseStepExecution.setStepResultMessage(testCaseStepActionExecution.getActionResultMessage());
}
if (testCaseStepActionExecution.isStopExecution()) {
break;
}
} else {
// We don't execute the action and record a generic execution.
/**
* Record Screenshot, PageSource
*/
testCaseStepActionExecution.addFileList(recorderService.recordExecutionInformationAfterStepActionandControl(testCaseStepActionExecution, null));
LOG.debug("Registering Action : " + testCaseStepActionExecution.getAction());
// We change the Action message only if the action is not executed due to condition.
MessageEvent actionMes = new MessageEvent(MessageEventEnum.CONDITION_TESTCASEACTION_NOTEXECUTED);
testCaseStepActionExecution.setActionResultMessage(actionMes);
testCaseStepActionExecution.setReturnMessage(testCaseStepActionExecution.getReturnMessage().replace("%COND%", testCaseStepActionExecution.getConditionOper()).replace("%MESSAGE%", conditionAnswer.getResultMessage().getDescription()));
testCaseStepActionExecution.setEnd(new Date().getTime());
this.testCaseStepActionExecutionService.updateTestCaseStepActionExecution(testCaseStepActionExecution);
LOG.debug("Registered Action");
}
} else {
// Error when performing the condition evaluation. We force no execution (false)
MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_CONDITION);
mes.setDescription(mes.getDescription().replace("%COND%", testCaseStepActionExecution.getConditionOper()).replace("%AREA%", "action ").replace("%MES%", conditionAnswer.getResultMessage().getDescription()));
testCaseStepActionExecution.setExecutionResultMessage(mes);
testCaseStepExecution.setExecutionResultMessage(testCaseStepActionExecution.getExecutionResultMessage());
testCaseStepExecution.setStopExecution(testCaseStepActionExecution.isStopExecution());
testCaseStepActionExecution.setActionResultMessage(new MessageEvent(MessageEventEnum.CONDITION_TESTCASEACTION_FAILED).resolveDescription("AREA", "").resolveDescription("COND", testCaseStepActionExecution.getConditionOper()).resolveDescription("MESSAGE", conditionAnswer.getResultMessage().getDescription()));
testCaseStepExecution.setStepResultMessage(new MessageEvent(MessageEventEnum.CONDITION_TESTCASESTEP_FAILED).resolveDescription("AREA", "action ").resolveDescription("COND", testCaseStepActionExecution.getConditionOper()).resolveDescription("MESSAGE", conditionAnswer.getResultMessage().getDescription()));
testCaseStepActionExecution.setEnd(new Date().getTime());
this.testCaseStepActionExecutionService.updateTestCaseStepActionExecution(testCaseStepActionExecution);
LOG.debug("Action interupted due to condition error.");
// We stop any further Action execution.
break;
}
} else {
testCaseStepActionExecution.setEnd(new Date().getTime());
testCaseStepExecution.setExecutionResultMessage(testCaseStepActionExecution.getExecutionResultMessage());
testCaseStepExecution.setStepResultMessage(testCaseStepActionExecution.getActionResultMessage());
testCaseStepExecution.setStopExecution(testCaseStepActionExecution.isStopExecution());
this.testCaseStepActionExecutionService.updateTestCaseStepActionExecution(testCaseStepActionExecution);
LOG.debug("Registered Action");
if (testCaseStepActionExecution.isStopExecution()) {
break;
}
}
/**
* Log TestCaseStepActionExecution
*/
if (tcExecution.getVerbose() > 0) {
LOG.info(testCaseStepActionExecution.toJson(false, true));
}
}
testCaseStepExecution.setEnd(new Date().getTime());
this.testCaseStepExecutionService.updateTestCaseStepExecution(testCaseStepExecution);
// Websocket --> we refresh the corresponding Detail Execution pages attached to this execution.
if (tcExecution.isCerberus_featureflipping_activatewebsocketpush()) {
TestCaseExecutionEndPoint.getInstance().send(tcExecution, false);
}
return testCaseStepExecution;
}
use of org.cerberus.crud.entity.TestCaseStepAction in project cerberus-source by cerberustesting.
the class TestCaseService method findTestCaseByKeyWithDependency.
@Override
public TestCase findTestCaseByKeyWithDependency(String test, String testCase) throws CerberusException {
TestCase newTcase;
newTcase = findTestCaseByKey(test, testCase);
if (newTcase == null) {
// TODO:FN temporary debug messages
LOG.warn("test case is null - test: " + test + " testcase: " + testCase);
} else {
List<TestCaseCountry> testCaseCountry = testCaseCountryService.findTestCaseCountryByTestTestCase(test, testCase);
List<TestCaseCountry> testCaseCountryToAdd = new ArrayList();
for (TestCaseCountry tcc : testCaseCountry) {
List<TestCaseCountryProperties> properties = testCaseCountryPropertiesService.findListOfPropertyPerTestTestCaseCountry(test, testCase, tcc.getCountry());
tcc.setTestCaseCountryProperty(properties);
testCaseCountryToAdd.add(tcc);
}
newTcase.setTestCaseCountry(testCaseCountryToAdd);
String initialTest = test;
String initialTc = testCase;
List<TestCaseStep> tcs = testCaseStepService.getListOfSteps(test, testCase);
List<TestCaseStep> tcsToAdd = new ArrayList();
for (TestCaseStep step : tcs) {
int stepNumber = step.getStep();
int initialStep = step.getStep();
if (step.getUseStep().equals("Y")) {
test = step.getUseStepTest();
testCase = step.getUseStepTestCase();
stepNumber = step.getUseStepStep();
}
List<TestCaseStepAction> tcsa = testCaseStepActionService.getListOfAction(test, testCase, stepNumber);
List<TestCaseStepAction> tcsaToAdd = new ArrayList();
for (TestCaseStepAction action : tcsa) {
List<TestCaseStepActionControl> tcsac = testCaseStepActionControlService.findControlByTestTestCaseStepSequence(test, testCase, stepNumber, action.getSequence());
List<TestCaseStepActionControl> tcsacToAdd = new ArrayList();
for (TestCaseStepActionControl control : tcsac) {
control.setTest(initialTest);
control.setTestCase(initialTc);
control.setStep(initialStep);
tcsacToAdd.add(control);
}
action.setTestCaseStepActionControl(tcsacToAdd);
action.setTest(initialTest);
action.setTestCase(initialTc);
action.setStep(initialStep);
tcsaToAdd.add(action);
}
step.setTestCaseStepAction(tcsaToAdd);
tcsToAdd.add(step);
}
newTcase.setTestCaseStep(tcsToAdd);
}
return newTcase;
}
use of org.cerberus.crud.entity.TestCaseStepAction in project cerberus-source by cerberustesting.
the class TestCaseStepActionService method readByVarious1WithDependency.
@Override
public AnswerList readByVarious1WithDependency(String test, String testcase, int step) {
AnswerList actions = testCaseStepActionDAO.readByVarious1(test, testcase, step);
AnswerList response = null;
List<TestCaseStepAction> tcseList = new ArrayList();
for (Object action : actions.getDataList()) {
TestCaseStepAction tces = (TestCaseStepAction) action;
AnswerList controls = testCaseStepActionControlService.readByVarious1(test, testcase, step, tces.getSequence());
tces.setTestCaseStepActionControl(controls.getDataList());
tcseList.add(tces);
}
response = new AnswerList(tcseList, actions.getTotalRows(), new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));
return response;
}
use of org.cerberus.crud.entity.TestCaseStepAction in project cerberus-source by cerberustesting.
the class TestCaseStepActionService method compareListAndUpdateInsertDeleteElements.
@Override
public void compareListAndUpdateInsertDeleteElements(List<TestCaseStepAction> newList, List<TestCaseStepAction> oldList, boolean duplicate) throws CerberusException {
/**
* Iterate on (TestCaseStepAction From Page - TestCaseStepAction From
* Database) If TestCaseStepAction in Database has same key : Update and
* remove from the list. If TestCaseStepAction in database does ot exist
* : Insert it.
*/
List<TestCaseStepAction> tcsaToUpdateOrInsert = new ArrayList(newList);
tcsaToUpdateOrInsert.removeAll(oldList);
List<TestCaseStepAction> tcsaToUpdateOrInsertToIterate = new ArrayList(tcsaToUpdateOrInsert);
for (TestCaseStepAction tcsaDifference : tcsaToUpdateOrInsertToIterate) {
for (TestCaseStepAction tcsaInDatabase : oldList) {
if (tcsaDifference.hasSameKey(tcsaInDatabase)) {
this.updateTestCaseStepAction(tcsaDifference);
tcsaToUpdateOrInsert.remove(tcsaDifference);
}
}
}
/**
* Iterate on (TestCaseStepAction From Database - TestCaseStepAction
* From Page). If TestCaseStepAction in Page has same key : remove from
* the list. Then delete the list of TestCaseStepAction
*/
if (!duplicate) {
List<TestCaseStepAction> tcsaToDelete = new ArrayList(oldList);
tcsaToDelete.removeAll(newList);
List<TestCaseStepAction> tcsaToDeleteToIterate = new ArrayList(tcsaToDelete);
for (TestCaseStepAction tcsaDifference : tcsaToDeleteToIterate) {
for (TestCaseStepAction tcsaInPage : newList) {
if (tcsaDifference.hasSameKey(tcsaInPage)) {
tcsaToDelete.remove(tcsaDifference);
}
}
}
this.deleteListTestCaseStepAction(tcsaToDelete);
}
// We insert only at the end (after deletion of all potencial enreg - linked with #1281)
this.insertListTestCaseStepAction(tcsaToUpdateOrInsert);
}
Aggregations