use of org.cerberus.engine.entity.MessageGeneral 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.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.
the class ExecutionRunService method executeAction.
private TestCaseStepActionExecution executeAction(TestCaseStepActionExecution testCaseStepActionExecution, TestCaseExecution tcExecution) {
LOG.debug("Starting execute Action : " + testCaseStepActionExecution.getAction());
AnswerItem<String> answerDecode = new AnswerItem();
/**
* If execution is not manual, do action and record files
*/
if (!tcExecution.getManualExecution().equals("Y")) {
testCaseStepActionExecution = this.actionService.doAction(testCaseStepActionExecution);
/**
* Record Screenshot, PageSource
*/
try {
testCaseStepActionExecution.addFileList(recorderService.recordExecutionInformationAfterStepActionandControl(testCaseStepActionExecution, null));
} catch (Exception ex) {
LOG.warn("Unable to record Screenshot/PageSource : " + ex.toString());
}
} else {
/**
* If execution manual, set Action result message as notExecuted
*/
testCaseStepActionExecution.setActionResultMessage(new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED));
testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_NE));
testCaseStepActionExecution.setEnd(new Date().getTime());
}
/**
* Register Action in database
*/
LOG.debug("Registering Action : " + testCaseStepActionExecution.getAction());
this.testCaseStepActionExecutionService.updateTestCaseStepActionExecution(testCaseStepActionExecution);
LOG.debug("Registered Action");
if (testCaseStepActionExecution.isStopExecution()) {
return testCaseStepActionExecution;
}
// As controls are associated with an action, the current state for the action is stored in order to restore it
// if some property is not defined for the country
MessageEvent actionMessage = testCaseStepActionExecution.getActionResultMessage();
MessageGeneral excutionResultMessage = testCaseStepActionExecution.getExecutionResultMessage();
/**
* Iterate Control
*/
List<TestCaseStepActionControl> tcsacList = testCaseStepActionExecution.getTestCaseStepAction().getTestCaseStepActionControl();
for (TestCaseStepActionControl testCaseStepActionControl : tcsacList) {
/**
* Start Execution of TestCAseStepActionControl
*/
long startControl = new Date().getTime();
/**
* Create and Register TestCaseStepActionControlExecution
*/
LOG.debug("Creating TestCaseStepActionControlExecution");
TestCaseStepActionControlExecution testCaseStepActionControlExecution = factoryTestCaseStepActionControlExecution.create(testCaseStepActionExecution.getId(), testCaseStepActionControl.getTest(), testCaseStepActionControl.getTestCase(), testCaseStepActionControl.getStep(), testCaseStepActionExecution.getIndex(), testCaseStepActionControl.getSequence(), testCaseStepActionControl.getControlSequence(), testCaseStepActionControl.getSort(), null, null, testCaseStepActionControl.getConditionOper(), testCaseStepActionControl.getConditionVal1(), testCaseStepActionControl.getConditionVal2(), testCaseStepActionControl.getConditionVal1(), testCaseStepActionControl.getConditionVal2(), testCaseStepActionControl.getControl(), testCaseStepActionControl.getValue1(), testCaseStepActionControl.getValue2(), testCaseStepActionControl.getValue1(), testCaseStepActionControl.getValue2(), testCaseStepActionControl.getFatal(), startControl, 0, 0, 0, testCaseStepActionControl.getDescription(), testCaseStepActionExecution, new MessageEvent(MessageEventEnum.CONTROL_PENDING));
this.testCaseStepActionControlExecutionService.insertTestCaseStepActionControlExecution(testCaseStepActionControlExecution);
LOG.debug("Executing control : " + testCaseStepActionControlExecution.getControlSequence() + " type : " + testCaseStepActionControlExecution.getControl());
/**
* We populate the TestCase Control List
*/
testCaseStepActionExecution.addTestCaseStepActionExecutionList(testCaseStepActionControlExecution);
// Evaluate the condition at the control level.
AnswerItem<Boolean> conditionAnswer;
boolean conditionDecodeError = false;
if (!tcExecution.getManualExecution().equals("Y")) {
try {
answerDecode = variableService.decodeStringCompletly(testCaseStepActionControlExecution.getConditionVal1(), tcExecution, null, false);
testCaseStepActionControlExecution.setConditionVal1((String) answerDecode.getItem());
if (!(answerDecode.isCodeStringEquals("OK"))) {
// If anything wrong with the decode --> we stop here with decode message in the action result.
testCaseStepActionControlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Condition Value1"));
testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));
testCaseStepActionControlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());
testCaseStepActionControlExecution.setEnd(new Date().getTime());
LOG.debug("Control interupted due to decode 'Control Condition Value1' Error.");
conditionDecodeError = true;
}
} catch (CerberusEventException cex) {
LOG.warn(cex);
}
try {
answerDecode = variableService.decodeStringCompletly(testCaseStepActionControlExecution.getConditionVal2(), tcExecution, null, false);
testCaseStepActionControlExecution.setConditionVal2((String) answerDecode.getItem());
if (!(answerDecode.isCodeStringEquals("OK"))) {
// If anything wrong with the decode --> we stop here with decode message in the action result.
testCaseStepActionControlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Condition Value2"));
testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));
testCaseStepActionControlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());
testCaseStepActionControlExecution.setEnd(new Date().getTime());
LOG.debug("Control interupted due to decode 'Control Condition Value2' Error.");
conditionDecodeError = true;
}
} catch (CerberusEventException cex) {
LOG.warn(cex);
}
}
if (!(conditionDecodeError)) {
conditionAnswer = this.conditionService.evaluateCondition(testCaseStepActionControlExecution.getConditionOper(), testCaseStepActionControlExecution.getConditionVal1(), testCaseStepActionControlExecution.getConditionVal2(), tcExecution);
boolean execute_Control = (boolean) conditionAnswer.getItem();
/**
* If condition OK or if manual execution, then execute the
* control
*/
if (conditionAnswer.getResultMessage().getMessage().getCodeString().equals("PE") || tcExecution.getManualExecution().equals("Y")) {
if (execute_Control || tcExecution.getManualExecution().equals("Y")) {
/**
* We execute the control
*/
testCaseStepActionControlExecution = executeControl(testCaseStepActionControlExecution, tcExecution);
/**
* We update the Action with the execution message and
* stop flag from the control. We update the status only
* if the control is not OK. This is to prevent moving
* the status to OK when it should stay KO when a
* control failed previously.
*/
testCaseStepActionExecution.setStopExecution(testCaseStepActionControlExecution.isStopExecution());
if (!(testCaseStepActionControlExecution.getControlResultMessage().equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS)))) {
// NA is a special case of not having success while calculating the property; the action shouldn't be stopped
if (testCaseStepActionControlExecution.getControlResultMessage().equals(new MessageEvent(MessageEventEnum.PROPERTY_FAILED_NO_PROPERTY_DEFINITION))) {
// restores the messages information if the property is not defined for the country
testCaseStepActionExecution.setActionResultMessage(actionMessage);
testCaseStepActionExecution.setExecutionResultMessage(excutionResultMessage);
} else {
testCaseStepActionExecution.setExecutionResultMessage(testCaseStepActionControlExecution.getExecutionResultMessage());
testCaseStepActionExecution.setActionResultMessage(testCaseStepActionControlExecution.getControlResultMessage());
}
}
/**
* If Control reported to stop the testcase, we stop it.
*/
if (testCaseStepActionControlExecution.isStopExecution()) {
break;
}
} else {
// We don't execute the control and record a generic execution.
/**
* Record Screenshot, PageSource
*/
testCaseStepActionControlExecution.addFileList(recorderService.recordExecutionInformationAfterStepActionandControl(testCaseStepActionControlExecution.getTestCaseStepActionExecution(), testCaseStepActionControlExecution));
/**
* Register Control in database
*/
LOG.debug("Registering Control : " + testCaseStepActionControlExecution.getControlSequence());
// We change the Action message only if the action is not executed due to condition.
MessageEvent controlMes = new MessageEvent(MessageEventEnum.CONDITION_TESTCASECONTROL_NOTEXECUTED);
testCaseStepActionControlExecution.setControlResultMessage(controlMes);
testCaseStepActionControlExecution.setReturnMessage(testCaseStepActionControlExecution.getReturnMessage().replace("%COND%", testCaseStepActionControlExecution.getConditionOper()).replace("%MESSAGE%", conditionAnswer.getResultMessage().getDescription()));
testCaseStepActionControlExecution.setEnd(new Date().getTime());
this.testCaseStepActionControlExecutionService.updateTestCaseStepActionControlExecution(testCaseStepActionControlExecution);
LOG.debug("Registered Control");
// Websocket --> we refresh the corresponding Detail Execution pages attached to this execution.
if (tcExecution.isCerberus_featureflipping_activatewebsocketpush()) {
TestCaseExecutionEndPoint.getInstance().send(tcExecution, false);
}
}
} else {
// Error when performing the condition evaluation. We force no execution (false)
MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_CONDITION);
mes.setDescription(mes.getDescription().replace("%COND%", testCaseStepActionControlExecution.getConditionOper()).replace("%AREA%", "control ").replace("%MES%", conditionAnswer.getResultMessage().getDescription()));
testCaseStepActionControlExecution.setExecutionResultMessage(mes);
testCaseStepActionExecution.setExecutionResultMessage(mes);
testCaseStepActionControlExecution.setControlResultMessage(new MessageEvent(MessageEventEnum.CONDITION_TESTCASECONTROL_FAILED).resolveDescription("AREA", "").resolveDescription("COND", testCaseStepActionControlExecution.getConditionOper()).resolveDescription("MESSAGE", conditionAnswer.getResultMessage().getDescription()));
testCaseStepActionExecution.setActionResultMessage(new MessageEvent(MessageEventEnum.CONDITION_TESTCASEACTION_FAILED).resolveDescription("AREA", "control ").resolveDescription("COND", testCaseStepActionControlExecution.getConditionOper()).resolveDescription("MESSAGE", conditionAnswer.getResultMessage().getDescription()));
testCaseStepActionControlExecution.setEnd(new Date().getTime());
this.testCaseStepActionControlExecutionService.updateTestCaseStepActionControlExecution(testCaseStepActionControlExecution);
LOG.debug("Control interupted due to condition error.");
// We stop any further Control execution.
break;
}
} else {
testCaseStepActionControlExecution.setEnd(new Date().getTime());
testCaseStepActionExecution.setExecutionResultMessage(testCaseStepActionControlExecution.getExecutionResultMessage());
testCaseStepActionExecution.setActionResultMessage(testCaseStepActionControlExecution.getControlResultMessage());
this.testCaseStepActionControlExecutionService.updateTestCaseStepActionControlExecution(testCaseStepActionControlExecution);
LOG.debug("Registered Control");
// Websocket --> we refresh the corresponding Detail Execution pages attached to this execution.
if (tcExecution.isCerberus_featureflipping_activatewebsocketpush()) {
TestCaseExecutionEndPoint.getInstance().send(tcExecution, false);
}
}
/**
* Log TestCaseStepActionControlExecution
*/
if (tcExecution.getVerbose() > 0) {
LOG.info(testCaseStepActionControlExecution.toJson(false, true));
}
}
// Websocket --> we refresh the corresponding Detail Execution pages attached to this execution.
if (tcExecution.isCerberus_featureflipping_activatewebsocketpush()) {
TestCaseExecutionEndPoint.getInstance().send(tcExecution, false);
}
LOG.debug("Finished execute Action : " + testCaseStepActionExecution.getAction());
return testCaseStepActionExecution;
}
use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.
the class ExecutionRunService method executeControl.
private TestCaseStepActionControlExecution executeControl(TestCaseStepActionControlExecution testCaseStepActionControlExecution, TestCaseExecution tcExecution) {
/**
* If execution is not manual, do control and record files
*/
if (!tcExecution.getManualExecution().equals("Y")) {
testCaseStepActionControlExecution = this.controlService.doControl(testCaseStepActionControlExecution);
/**
* Record Screenshot, PageSource
*/
testCaseStepActionControlExecution.addFileList(recorderService.recordExecutionInformationAfterStepActionandControl(testCaseStepActionControlExecution.getTestCaseStepActionExecution(), testCaseStepActionControlExecution));
} else {
/**
* If execution manual, set Control result message as notExecuted
*/
testCaseStepActionControlExecution.setControlResultMessage(new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED));
testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_NE));
testCaseStepActionControlExecution.setEnd(new Date().getTime());
}
/**
* Register Control in database
*/
LOG.debug("Registering Control : " + testCaseStepActionControlExecution.getControlSequence());
this.testCaseStepActionControlExecutionService.updateTestCaseStepActionControlExecution(testCaseStepActionControlExecution);
LOG.debug("Registered Control");
// Websocket --> we refresh the corresponding Detail Execution pages attached to this execution.
if (tcExecution.isCerberus_featureflipping_activatewebsocketpush()) {
TestCaseExecutionEndPoint.getInstance().send(tcExecution, false);
}
return testCaseStepActionControlExecution;
}
use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.
the class SeleniumServerService method startServer.
@Override
public void startServer(TestCaseExecution tCExecution) throws CerberusException {
// message used for log purposes
String logPrefix = "[" + tCExecution.getTest() + " - " + tCExecution.getTestCase() + "] ";
try {
LOG.info(logPrefix + "Start Robot Server (Selenium, Appium or Sikuli)");
/**
* Set Session
*/
LOG.debug(logPrefix + "Setting the session.");
String system = tCExecution.getApplicationObj().getSystem();
/**
* Get the parameters that will be used to set the servers
* (selenium/appium) If timeout has been defined at the execution
* level, set the selenium & appium wait element with this value,
* else, take the one from parameter
*/
Integer cerberus_selenium_pageLoadTimeout, cerberus_selenium_implicitlyWait, cerberus_selenium_setScriptTimeout, cerberus_selenium_wait_element, cerberus_appium_wait_element, cerberus_selenium_action_click_timeout;
if (!tCExecution.getTimeout().isEmpty()) {
cerberus_selenium_wait_element = Integer.valueOf(tCExecution.getTimeout());
cerberus_appium_wait_element = Integer.valueOf(tCExecution.getTimeout());
} else {
cerberus_selenium_wait_element = parameterService.getParameterIntegerByKey("cerberus_selenium_wait_element", system, 90000);
cerberus_appium_wait_element = parameterService.getParameterIntegerByKey("cerberus_appium_wait_element", system, 90000);
}
cerberus_selenium_pageLoadTimeout = parameterService.getParameterIntegerByKey("cerberus_selenium_pageLoadTimeout", system, 90000);
cerberus_selenium_implicitlyWait = parameterService.getParameterIntegerByKey("cerberus_selenium_implicitlyWait", system, 0);
cerberus_selenium_setScriptTimeout = parameterService.getParameterIntegerByKey("cerberus_selenium_setScriptTimeout", system, 90000);
cerberus_selenium_action_click_timeout = parameterService.getParameterIntegerByKey("cerberus_selenium_action_click_timeout", system, 90000);
LOG.debug(logPrefix + "TimeOut defined on session : " + cerberus_selenium_wait_element);
Session session = new Session();
session.setCerberus_selenium_implicitlyWait(cerberus_selenium_implicitlyWait);
session.setCerberus_selenium_pageLoadTimeout(cerberus_selenium_pageLoadTimeout);
session.setCerberus_selenium_setScriptTimeout(cerberus_selenium_setScriptTimeout);
session.setCerberus_selenium_wait_element(cerberus_selenium_wait_element);
session.setCerberus_appium_wait_element(cerberus_appium_wait_element);
session.setCerberus_selenium_action_click_timeout(cerberus_selenium_action_click_timeout);
session.setHost(tCExecution.getSeleniumIP());
session.setHostUser(tCExecution.getSeleniumIPUser());
session.setHostPassword(tCExecution.getSeleniumIPPassword());
session.setPort(tCExecution.getPort());
tCExecution.setSession(session);
LOG.debug(logPrefix + "Session is set.");
/**
* SetUp Capabilities
*/
LOG.debug(logPrefix + "Set Capabilities");
DesiredCapabilities caps = this.setCapabilities(tCExecution);
session.setDesiredCapabilities(caps);
LOG.debug(logPrefix + "Set Capabilities - retreived");
/**
* SetUp Proxy
*/
String hubUrl = StringUtil.cleanHostURL(SeleniumServerService.getBaseUrl(StringUtil.formatURLCredential(tCExecution.getSession().getHostUser(), tCExecution.getSession().getHostPassword()) + session.getHost(), session.getPort())) + "/wd/hub";
LOG.debug(logPrefix + "Hub URL :" + hubUrl);
URL url = new URL(hubUrl);
HttpCommandExecutor executor = null;
boolean isProxy = proxyService.useProxy(hubUrl, system);
if (isProxy) {
String proxyHost = parameterService.getParameterStringByKey("cerberus_proxy_host", system, DEFAULT_PROXY_HOST);
int proxyPort = parameterService.getParameterIntegerByKey("cerberus_proxy_port", system, DEFAULT_PROXY_PORT);
HttpClientBuilder builder = HttpClientBuilder.create();
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
builder.setProxy(proxy);
if (parameterService.getParameterBooleanByKey("cerberus_proxyauthentification_active", system, DEFAULT_PROXYAUTHENT_ACTIVATE)) {
String proxyUser = parameterService.getParameterStringByKey("cerberus_proxyauthentification_user", system, DEFAULT_PROXYAUTHENT_USER);
String proxyPassword = parameterService.getParameterStringByKey("cerberus_proxyauthentification_password", system, DEFAULT_PROXYAUTHENT_PASSWORD);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(proxyUser, proxyPassword));
if (url.getUserInfo() != null && !url.getUserInfo().isEmpty()) {
credsProvider.setCredentials(new AuthScope(url.getHost(), (url.getPort() > 0 ? url.getPort() : url.getDefaultPort())), new UsernamePasswordCredentials(tCExecution.getSession().getHostUser(), tCExecution.getSession().getHostPassword()));
}
builder.setDefaultCredentialsProvider(credsProvider);
}
Factory factory = new MyHttpClientFactory(builder);
executor = new HttpCommandExecutor(new HashMap<String, CommandInfo>(), url, factory);
}
/**
* SetUp Driver
*/
LOG.debug(logPrefix + "Set Driver");
WebDriver driver = null;
AppiumDriver appiumDriver = null;
if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {
if (caps.getPlatform().is(Platform.ANDROID)) {
if (executor == null) {
appiumDriver = new AndroidDriver(url, caps);
} else {
appiumDriver = new AndroidDriver(executor, caps);
}
driver = (WebDriver) appiumDriver;
} else if (caps.getPlatform().is(Platform.MAC)) {
if (executor == null) {
appiumDriver = new IOSDriver(url, caps);
} else {
appiumDriver = new IOSDriver(executor, caps);
}
driver = (WebDriver) appiumDriver;
} else // Any Other
{
if (executor == null) {
driver = new RemoteWebDriver(url, caps);
} else {
driver = new RemoteWebDriver(executor, caps);
}
}
} else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {
if (executor == null) {
appiumDriver = new AndroidDriver(url, caps);
} else {
appiumDriver = new AndroidDriver(executor, caps);
}
driver = (WebDriver) appiumDriver;
} else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
if (executor == null) {
appiumDriver = new IOSDriver(url, caps);
} else {
appiumDriver = new IOSDriver(executor, caps);
}
driver = (WebDriver) appiumDriver;
} else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {
/**
* Check sikuli extension is reachable
*/
if (!sikuliService.isSikuliServerReachable(session)) {
MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_SIKULI_COULDNOTCONNECT);
mes.setDescription(mes.getDescription().replace("%SSIP%", tCExecution.getSeleniumIP()));
mes.setDescription(mes.getDescription().replace("%SSPORT%", tCExecution.getSeleniumPort()));
throw new CerberusException(mes);
}
/**
* If CountryEnvParameter IP is set, open the App
*/
if (!tCExecution.getCountryEnvironmentParameters().getIp().isEmpty()) {
sikuliService.doSikuliActionOpenApp(session, tCExecution.getCountryEnvironmentParameters().getIp());
}
}
/**
* Defining the timeout at the driver level. Only in case of not
* Appium Driver (see
* https://github.com/vertigo17/Cerberus/issues/754)
*/
if (driver != null && appiumDriver == null) {
driver.manage().timeouts().pageLoadTimeout(cerberus_selenium_pageLoadTimeout, TimeUnit.MILLISECONDS);
driver.manage().timeouts().implicitlyWait(cerberus_selenium_implicitlyWait, TimeUnit.MILLISECONDS);
driver.manage().timeouts().setScriptTimeout(cerberus_selenium_setScriptTimeout, TimeUnit.MILLISECONDS);
}
tCExecution.getSession().setDriver(driver);
tCExecution.getSession().setAppiumDriver(appiumDriver);
/**
* If Gui application, maximize window Get IP of Node in case of
* remote Server. Maximize does not work for chrome browser We also
* get the Real UserAgent from the browser.
*/
if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI) && !caps.getPlatform().equals(Platform.ANDROID)) {
if (!caps.getBrowserName().equals(BrowserType.CHROME)) {
driver.manage().window().maximize();
}
getIPOfNode(tCExecution);
/**
* If screenSize is defined, set the size of the screen.
*/
String targetScreensize = getScreenSizeToUse(tCExecution.getTestCaseObj().getScreenSize(), tCExecution.getScreenSize());
LOG.debug("Selenium resolution : " + targetScreensize);
if ((!StringUtil.isNullOrEmpty(targetScreensize)) && targetScreensize.contains("*")) {
Integer screenWidth = Integer.valueOf(targetScreensize.split("\\*")[0]);
Integer screenLength = Integer.valueOf(targetScreensize.split("\\*")[1]);
setScreenSize(driver, screenWidth, screenLength);
LOG.debug("Selenium resolution Activated : " + screenWidth + "*" + screenLength);
}
tCExecution.setScreenSize(getScreenSize(driver));
tCExecution.setRobotDecli(tCExecution.getRobotDecli().replace("%SCREENSIZE%", tCExecution.getScreenSize()));
String userAgent = (String) ((JavascriptExecutor) driver).executeScript("return navigator.userAgent;");
tCExecution.setUserAgent(userAgent);
}
tCExecution.getSession().setStarted(true);
} catch (CerberusException exception) {
LOG.error(logPrefix + exception.toString(), exception);
throw new CerberusException(exception.getMessageError());
} catch (MalformedURLException exception) {
LOG.error(logPrefix + exception.toString(), exception);
MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_URL_MALFORMED);
mes.setDescription(mes.getDescription().replace("%URL%", tCExecution.getSession().getHost() + ":" + tCExecution.getSession().getPort()));
throw new CerberusException(mes);
} catch (UnreachableBrowserException exception) {
LOG.error(logPrefix + exception.toString(), exception);
MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_SELENIUM_COULDNOTCONNECT);
mes.setDescription(mes.getDescription().replace("%SSIP%", tCExecution.getSeleniumIP()));
mes.setDescription(mes.getDescription().replace("%SSPORT%", tCExecution.getSeleniumPort()));
mes.setDescription(mes.getDescription().replace("%ERROR%", exception.toString()));
throw new CerberusException(mes);
} catch (Exception exception) {
LOG.error(logPrefix + exception.toString(), exception);
MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
mes.setDescription(mes.getDescription().replace("%MES%", exception.toString()));
throw new CerberusException(mes);
}
}
use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.
the class CalculatePropertyForTestCase method doGet.
@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.BLOCKS);
String type = policy.sanitize(httpServletRequest.getParameter("type"));
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
String result = null;
String description = null;
String system = "";
String property = httpServletRequest.getParameter("property");
String testName = policy.sanitize(httpServletRequest.getParameter("test"));
String testCaseName = policy.sanitize(httpServletRequest.getParameter("testCase"));
String country = policy.sanitize(httpServletRequest.getParameter("country"));
String environment = policy.sanitize(httpServletRequest.getParameter("environment"));
try {
if (type.equals("executeSoapFromLib")) {
IAppServiceService appServiceService = appContext.getBean(AppServiceService.class);
ISoapService soapService = appContext.getBean(ISoapService.class);
IXmlUnitService xmlUnitService = appContext.getBean(IXmlUnitService.class);
AppService appService = appServiceService.findAppServiceByKey(property);
if (appService != null) {
ExecutionUUID executionUUIDObject = appContext.getBean(ExecutionUUID.class);
UUID executionUUID = UUID.randomUUID();
executionUUIDObject.setExecutionUUID(executionUUID.toString(), null);
soapService.callSOAP(appService.getServiceRequest(), appService.getServicePath(), appService.getOperation(), appService.getAttachementURL(), null, null, 60000, system);
result = xmlUnitService.getFromXml(executionUUID.toString(), appService.getAttachementURL());
description = appService.getDescription();
executionUUIDObject.removeExecutionUUID(executionUUID.toString());
LOG.debug("Clean ExecutionUUID");
}
} else {
try {
ITestCaseService testCaseService = appContext.getBean(TestCaseService.class);
IApplicationService applicationService = appContext.getBean(ApplicationService.class);
TestCase testCase = testCaseService.findTestCaseByKey(testName, testCaseName);
if (testCase != null) {
system = applicationService.convert(applicationService.readByKey(testCase.getApplication())).getSystem();
} else {
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
}
} catch (CerberusException ex) {
LOG.warn(ex);
}
if (system != null) {
String database = policy.sanitize(httpServletRequest.getParameter("database"));
ICountryEnvironmentDatabaseService countryEnvironmentDatabaseService = appContext.getBean(CountryEnvironmentDatabaseService.class);
CountryEnvironmentDatabase countryEnvironmentDatabase;
countryEnvironmentDatabase = countryEnvironmentDatabaseService.convert(countryEnvironmentDatabaseService.readByKey(system, country, environment, database));
String connectionName = countryEnvironmentDatabase.getConnectionPoolName();
if (type.equals("executeSqlFromLib")) {
ISqlLibraryService sqlLibraryService = appContext.getBean(SqlLibraryService.class);
SqlLibrary sl = sqlLibraryService.findSqlLibraryByKey(policy.sanitize(property));
property = sl.getScript();
if (!(StringUtil.isNullOrEmpty(connectionName)) && !(StringUtil.isNullOrEmpty(policy.sanitize(property)))) {
ISQLService sqlService = appContext.getBean(ISQLService.class);
IParameterService parameterService = appContext.getBean(IParameterService.class);
Integer sqlTimeout = parameterService.getParameterIntegerByKey("cerberus_propertyexternalsql_timeout", system, 60);
result = sqlService.queryDatabase(connectionName, policy.sanitize(property), 1, sqlTimeout).get(0);
description = sl.getDescription();
}
}
}
}
} catch (CerberusException ex) {
LOG.warn(ex);
result = ex.getMessageError().getDescription();
description = ex.getMessageError().getDescription();
} catch (CerberusEventException ex) {
LOG.warn(ex);
result = ex.getMessageError().getDescription();
description = ex.getMessageError().getDescription();
}
if (result != null) {
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("resultList", result);
jsonObject.put("description", description);
httpServletResponse.setContentType("application/json");
httpServletResponse.getWriter().print(jsonObject.toString());
} catch (JSONException exception) {
LOG.warn(exception.toString());
}
}
}
Aggregations