use of org.cerberus.crud.entity.TestCaseExecutionFile in project cerberus-source by cerberustesting.
the class ControlService method getPageSource.
private MessageEvent getPageSource(TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution, TestCaseStepActionControlExecution testCaseStepActionControlExecution) {
MessageEvent message;
if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
TestCaseExecutionFile file = recorderService.recordPageSource(tCExecution, testCaseStepActionExecution, testCaseStepActionControlExecution.getControlSequence());
if (file != null) {
List<TestCaseExecutionFile> fileList = new ArrayList<TestCaseExecutionFile>();
fileList.add(file);
testCaseStepActionControlExecution.setFileList(fileList);
}
message = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_GETPAGESOURCE);
return message;
}
message = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
message.setDescription(message.getDescription().replace("%CONTROL%", "takeScreenShot"));
message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType()));
return message;
}
use of org.cerberus.crud.entity.TestCaseExecutionFile in project cerberus-source by cerberustesting.
the class RecorderService method recordManuallyFile.
@Override
public AnswerItem recordManuallyFile(TestCaseStepActionExecution testCaseStepActionExecution, TestCaseStepActionControlExecution testCaseStepActionControlExecution, String extension, String desc, FileItem file, Integer id, String fileName, Integer fileID) {
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", "Can't upload file");
AnswerItem a = new AnswerItem();
TestCaseExecutionFile object = null;
String returnCode;
Integer controlNumber = 0;
String test = "";
String testCase = "";
String step = "";
String index = "";
String sequence = "";
String controlString = "";
Integer myExecution = id;
if (testCaseStepActionControlExecution == null) {
test = testCaseStepActionExecution.getTest();
testCase = testCaseStepActionExecution.getTestCase();
step = String.valueOf(testCaseStepActionExecution.getStep());
index = String.valueOf(testCaseStepActionExecution.getIndex());
sequence = String.valueOf(testCaseStepActionExecution.getSequence());
controlString = controlNumber.equals(0) ? null : String.valueOf(controlNumber);
returnCode = testCaseStepActionExecution.getReturnCode();
} else {
returnCode = testCaseStepActionControlExecution.getReturnCode();
controlNumber = testCaseStepActionControlExecution.getControlSequence();
test = testCaseStepActionControlExecution.getTest();
testCase = testCaseStepActionControlExecution.getTestCase();
step = String.valueOf(testCaseStepActionControlExecution.getStep());
index = String.valueOf(testCaseStepActionControlExecution.getIndex());
sequence = String.valueOf(testCaseStepActionControlExecution.getSequence());
controlString = controlNumber.equals(0) ? null : String.valueOf(controlNumber);
}
// Used for logging purposes
String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - [" + test + " - " + testCase + " - step: " + step + " action: " + sequence + "] ";
try {
Recorder recorder = new Recorder();
String name = "";
File dir = null;
if (file != null) {
name = file.getName();
extension = name.substring(name.lastIndexOf('.') + 1, name.length());
extension = extension.toUpperCase();
extension = testCaseExecutionFileService.checkExtension(name, extension);
recorder = this.initFilenames(myExecution, test, testCase, step, index, sequence, controlString, null, 0, name.substring(0, name.lastIndexOf('.')), extension, true);
dir = new File(recorder.getFullPath());
} else {
name = fileName;
extension = testCaseExecutionFileService.checkExtension(name, extension);
if (name.contains(".")) {
recorder = this.initFilenames(myExecution, test, testCase, step, index, sequence, controlString, null, 0, name.substring(0, name.lastIndexOf('.')), extension, true);
dir = new File(recorder.getFullPath());
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "manual testcase execution file").replace("%OPERATION%", "Create").replace("%REASON%", "file is missing!"));
a.setResultMessage(msg);
return a;
}
}
if (!dir.exists()) {
try {
boolean isCreated = dir.mkdirs();
if (!isCreated) {
throw new SecurityException();
}
} catch (SecurityException se) {
LOG.warn("Unable to create manual execution file dir: " + se.getMessage());
msg = new MessageEvent(MessageEventEnum.FILE_ERROR).resolveDescription("DESCRIPTION", se.toString()).resolveDescription("MORE", "Please check the parameter cerberus_exemanualmedia_path");
a.setResultMessage(msg);
return a;
}
}
if (file != null) {
AnswerItem<TestCaseExecutionFile> current = testCaseExecutionFileService.readByKey(myExecution, recorder.getLevel(), desc);
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
if (current.getItem() != null) {
try {
File temp = new File(recorder.getRootFolder() + current.getItem().getFileName());
temp.delete();
} catch (SecurityException se) {
LOG.warn("Unable to create manual execution file dir: " + se.getMessage());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", se.toString());
}
}
try {
file.write(new File(recorder.getFullFilename()));
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("DESCRIPTION", "Manual Execution File uploaded");
msg.setDescription(msg.getDescription().replace("%ITEM%", "Manual Execution File").replace("%OPERATION%", "Upload"));
LOG.debug(logPrefix + "Copy file finished with success - source: " + file.getName() + " destination: " + recorder.getRelativeFilenameURL());
object = testCaseExecutionFileFactory.create(fileID, myExecution, recorder.getLevel(), desc, recorder.getRelativeFilenameURL(), extension, "", null, "", null);
} catch (Exception e) {
LOG.warn("Unable to upload Manual Execution File: " + e.getMessage());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
}
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("DESCRIPTION", "Manual Execution File updated");
msg.setDescription(msg.getDescription().replace("%ITEM%", "Manual Execution File").replace("%OPERATION%", "updated"));
LOG.debug(logPrefix + "Updated test case manual file finished with success");
object = testCaseExecutionFileFactory.create(fileID, myExecution, recorder.getLevel(), desc, name, extension, "", null, "", null);
}
testCaseExecutionFileService.saveManual(object);
} catch (CerberusException e) {
LOG.error(logPrefix + e.toString());
}
a.setResultMessage(msg);
a.setItem(object);
return a;
}
use of org.cerberus.crud.entity.TestCaseExecutionFile in project cerberus-source by cerberustesting.
the class RecorderService method recordExecutionInformationAfterStepActionandControl.
@Override
public List<TestCaseExecutionFile> recordExecutionInformationAfterStepActionandControl(TestCaseStepActionExecution testCaseStepActionExecution, TestCaseStepActionControlExecution testCaseStepActionControlExecution) {
List<TestCaseExecutionFile> objectFileList = new ArrayList<TestCaseExecutionFile>();
TestCaseExecutionFile objectFile = null;
// Used for logging purposes
String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";
TestCaseExecution myExecution;
boolean doScreenshot;
boolean getPageSource;
String applicationType;
String returnCode;
Integer controlNumber = 0;
if (testCaseStepActionControlExecution == null) {
myExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();
doScreenshot = testCaseStepActionExecution.getActionResultMessage().isDoScreenshot();
getPageSource = testCaseStepActionExecution.getActionResultMessage().isGetPageSource();
applicationType = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType();
returnCode = testCaseStepActionExecution.getReturnCode();
} else {
myExecution = testCaseStepActionControlExecution.getTestCaseStepActionExecution().getTestCaseStepExecution().gettCExecution();
doScreenshot = testCaseStepActionControlExecution.getControlResultMessage().isDoScreenshot();
getPageSource = testCaseStepActionControlExecution.getControlResultMessage().isGetPageSource();
applicationType = testCaseStepActionControlExecution.getTestCaseStepActionExecution().getTestCaseStepExecution().gettCExecution().getApplicationObj().getType();
returnCode = testCaseStepActionControlExecution.getReturnCode();
controlNumber = testCaseStepActionControlExecution.getControlSequence();
}
/**
* SCREENSHOT Management. Screenshot only done when : screenshot
* parameter is eq to 2 or screenshot parameter is eq to 1 with the
* correct doScreenshot flag on the last action MessageEvent.
*/
if ((myExecution.getScreenshot() == 2) || ((myExecution.getScreenshot() == 1) && (doScreenshot))) {
if (applicationType.equals(Application.TYPE_GUI) || applicationType.equals(Application.TYPE_APK) || applicationType.equals(Application.TYPE_IPA) || applicationType.equals(Application.TYPE_FAT)) {
/**
* Only if the return code is not equal to Cancel, meaning lost
* connectivity with selenium.
*/
if (!returnCode.equals("CA")) {
objectFile = this.recordScreenshot(myExecution, testCaseStepActionExecution, controlNumber);
if (objectFile != null) {
objectFileList.add(objectFile);
}
} else {
LOG.debug(logPrefix + "Not Doing screenshot because connectivity with selenium server lost.");
}
}
} else {
LOG.debug(logPrefix + "Not Doing screenshot because of the screenshot parameter or flag on the last Action result.");
}
/**
* PAGESOURCE management. Get PageSource if requested by the last Action
* MessageEvent.
*/
if ((myExecution.getPageSource() == 2) || ((myExecution.getPageSource() == 1) && (getPageSource))) {
if (applicationType.equals(Application.TYPE_GUI) || applicationType.equals(Application.TYPE_APK) || applicationType.equals(Application.TYPE_IPA)) {
/**
* Only if the return code is not equal to Cancel, meaning lost
* connectivity with selenium.
*/
if (!returnCode.equals("CA")) {
objectFile = this.recordPageSource(myExecution, testCaseStepActionExecution, controlNumber);
if (objectFile != null) {
objectFileList.add(objectFile);
}
} else {
LOG.debug(logPrefix + "Not Doing screenshot because connectivity with selenium server lost.");
}
}
} else {
LOG.debug(logPrefix + "Not getting page source because of the pageSource parameter or flag on the last Action result.");
}
/**
* Last call XML SOURCE management. Get Source of the XML if requested
* by the last Action or control MessageEvent.
*/
if (applicationType.equals(Application.TYPE_SRV) && ((myExecution.getPageSource() == 2) || ((myExecution.getPageSource() == 1) && (getPageSource)) || (myExecution.getScreenshot() == 2) || ((myExecution.getScreenshot() == 1) && (doScreenshot)))) {
// Record the Request and Response.
AppService se = (AppService) testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getLastServiceCalled();
if (se != null) {
// No Calls were performed previously
List<TestCaseExecutionFile> objectFileSOAPList = new ArrayList<TestCaseExecutionFile>();
objectFileSOAPList = this.recordServiceCall(myExecution, testCaseStepActionExecution, controlNumber, null, se);
if (objectFileSOAPList.isEmpty() != true) {
for (TestCaseExecutionFile testCaseExecutionFile : objectFileSOAPList) {
objectFileList.add(testCaseExecutionFile);
}
}
}
}
return objectFileList;
}
use of org.cerberus.crud.entity.TestCaseExecutionFile in project cerberus-source by cerberustesting.
the class RecorderService method recordServiceCall.
@Override
public List<TestCaseExecutionFile> recordServiceCall(TestCaseExecution testCaseExecution, TestCaseStepActionExecution testCaseStepActionExecution, Integer control, String property, AppService se) {
// Used for logging purposes
String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";
List<TestCaseExecutionFile> objectFileList = new ArrayList<TestCaseExecutionFile>();
TestCaseExecutionFile object = null;
String test = null;
String testCase = null;
String step = null;
String index = null;
String sequence = null;
if (testCaseStepActionExecution != null) {
test = testCaseExecution.getTest();
testCase = testCaseExecution.getTestCase();
step = String.valueOf(testCaseStepActionExecution.getStep());
index = String.valueOf(testCaseStepActionExecution.getIndex());
sequence = String.valueOf(testCaseStepActionExecution.getSequence());
}
String controlString = control.equals(0) ? null : String.valueOf(control);
long runId = testCaseExecution.getId();
int propertyIndex = 0;
if (!(StringUtil.isNullOrEmpty(property))) {
propertyIndex = 1;
}
try {
// Service Call META data information.
Recorder recorderRequest = this.initFilenames(runId, test, testCase, step, index, sequence, controlString, property, propertyIndex, "call", "json", false);
recordFile(recorderRequest.getFullPath(), recorderRequest.getFileName(), se.toJSONOnExecution().toString());
// Index file created to database.
object = testCaseExecutionFileFactory.create(0, runId, recorderRequest.getLevel(), "Service Call", recorderRequest.getRelativeFilenameURL(), "JSON", "", null, "", null);
testCaseExecutionFileService.save(object);
objectFileList.add(object);
// REQUEST.
if (!(StringUtil.isNullOrEmpty(se.getServiceRequest()))) {
String messageFormatExt = "txt";
String messageFormat = TestCaseExecutionFile.FILETYPE_TXT;
if (se.getServiceRequest().startsWith("{")) {
// TODO find a better solution to guess the format of the request.
messageFormatExt = "json";
messageFormat = TestCaseExecutionFile.FILETYPE_JSON;
} else if (se.getServiceRequest().startsWith("<")) {
messageFormatExt = "xml";
messageFormat = TestCaseExecutionFile.FILETYPE_XML;
}
recorderRequest = this.initFilenames(runId, test, testCase, step, index, sequence, controlString, property, propertyIndex, "request", messageFormatExt, false);
recordFile(recorderRequest.getFullPath(), recorderRequest.getFileName(), se.getServiceRequest());
// Index file created to database.
object = testCaseExecutionFileFactory.create(0, runId, recorderRequest.getLevel(), "Request", recorderRequest.getRelativeFilenameURL(), messageFormat, "", null, "", null);
testCaseExecutionFileService.save(object);
objectFileList.add(object);
}
// RESPONSE if exists.
if (!(StringUtil.isNullOrEmpty(se.getResponseHTTPBody()))) {
String messageFormatExt = "txt";
String messageFormat = TestCaseExecutionFile.FILETYPE_TXT;
switch(se.getResponseHTTPBodyContentType()) {
case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:
messageFormatExt = "json";
messageFormat = TestCaseExecutionFile.FILETYPE_JSON;
break;
case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:
messageFormatExt = "xml";
messageFormat = TestCaseExecutionFile.FILETYPE_XML;
break;
default:
messageFormatExt = "txt";
messageFormat = TestCaseExecutionFile.FILETYPE_TXT;
break;
}
Recorder recorderResponse = this.initFilenames(runId, test, testCase, step, index, sequence, controlString, property, propertyIndex, "response", messageFormatExt, false);
recordFile(recorderResponse.getFullPath(), recorderResponse.getFileName(), se.getResponseHTTPBody());
// Index file created to database.
object = testCaseExecutionFileFactory.create(0, runId, recorderResponse.getLevel(), "Response", recorderResponse.getRelativeFilenameURL(), messageFormat, "", null, "", null);
testCaseExecutionFileService.save(object);
objectFileList.add(object);
}
} catch (Exception ex) {
LOG.error(logPrefix + ex.toString());
}
return objectFileList;
}
use of org.cerberus.crud.entity.TestCaseExecutionFile in project cerberus-source by cerberustesting.
the class RecorderService method recordScreenshot.
@Override
public TestCaseExecutionFile recordScreenshot(TestCaseExecution testCaseExecution, TestCaseStepActionExecution testCaseStepActionExecution, Integer control) {
TestCaseExecutionFile object = null;
String test = testCaseStepActionExecution.getTest();
String testCase = testCaseStepActionExecution.getTestCase();
String step = String.valueOf(testCaseStepActionExecution.getStep());
String index = String.valueOf(testCaseStepActionExecution.getIndex());
String sequence = String.valueOf(testCaseStepActionExecution.getSequence());
String controlString = control.equals(0) ? null : String.valueOf(control);
long runId = testCaseExecution.getId();
String applicationType = testCaseExecution.getApplicationObj().getType();
// Used for logging purposes
String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - [" + test + " - " + testCase + " - step: " + step + " action: " + sequence + "] ";
LOG.debug(logPrefix + "Doing screenshot.");
/**
* Take Screenshot and write it
*/
File newImage = null;
if (applicationType.equals(Application.TYPE_GUI) || applicationType.equals(Application.TYPE_APK) || applicationType.equals(Application.TYPE_IPA)) {
newImage = this.webdriverService.takeScreenShotFile(testCaseExecution.getSession());
} else if (applicationType.equals(Application.TYPE_FAT)) {
newImage = this.sikuliService.takeScreenShotFile(testCaseExecution.getSession());
}
if (newImage != null) {
try {
Recorder recorder = this.initFilenames(runId, test, testCase, step, index, sequence, controlString, null, 0, "screenshot", "png", false);
LOG.debug(logPrefix + "FullPath " + recorder.getFullPath());
File dir = new File(recorder.getFullPath());
if (!dir.exists()) {
LOG.debug(logPrefix + "Create directory for execution " + recorder.getFullPath());
dir.mkdirs();
}
// Getting the max size of the screenshot.
long maxSizeParam = parameterService.getParameterIntegerByKey("cerberus_screenshot_max_size", "", 1048576);
if (maxSizeParam < newImage.length()) {
LOG.warn(logPrefix + "Screen-shot size exceeds the maximum defined in configurations " + newImage.getName() + " destination: " + recorder.getRelativeFilenameURL());
}
// copies the temp file to the execution file
FileUtils.copyFile(newImage, new File(recorder.getFullFilename()));
LOG.debug(logPrefix + "Copy file finished with success - source: " + newImage.getName() + " destination: " + recorder.getRelativeFilenameURL());
// Index file created to database.
object = testCaseExecutionFileFactory.create(0, testCaseExecution.getId(), recorder.getLevel(), "Screenshot", recorder.getRelativeFilenameURL(), "PNG", "", null, "", null);
testCaseExecutionFileService.save(object);
// deletes the temporary file
FileUtils.forceDelete(newImage);
LOG.debug(logPrefix + "Temp file deleted with success " + newImage.getName());
LOG.debug(logPrefix + "Screenshot done in : " + recorder.getRelativeFilenameURL());
} catch (IOException ex) {
LOG.error(logPrefix + ex.toString());
} catch (CerberusException ex) {
LOG.error(logPrefix + ex.toString());
}
} else {
LOG.warn(logPrefix + "Screenshot returned null.");
}
return object;
}
Aggregations