use of org.cerberus.engine.entity.Recorder in project cerberus-source by cerberustesting.
the class RecorderService method recordTestDataLibProperty.
@Override
public TestCaseExecutionFile recordTestDataLibProperty(Long runId, String property, int propertyIndex, List<HashMap<String, String>> result) {
TestCaseExecutionFile object = null;
// Used for logging purposes
String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";
try {
JSONArray jsonResult = null;
jsonResult = dataLibService.convertToJSONObject(result);
// RESULT.
Recorder recorder = this.initFilenames(runId, null, null, null, null, null, null, property, propertyIndex, "result", "json", false);
recordFile(recorder.getFullPath(), recorder.getFileName(), jsonResult.toString());
// Index file created to database.
object = testCaseExecutionFileFactory.create(0, runId, recorder.getLevel(), "Result", recorder.getRelativeFilenameURL(), "JSON", "", null, "", null);
testCaseExecutionFileService.save(object);
} catch (CerberusException | JSONException ex) {
LOG.error(logPrefix + "TestDataLib file was not saved due to unexpected error." + ex.toString());
}
return object;
}
use of org.cerberus.engine.entity.Recorder in project cerberus-source by cerberustesting.
the class RecorderService method recordPageSource.
@Override
public TestCaseExecutionFile recordPageSource(TestCaseExecution testCaseExecution, TestCaseStepActionExecution testCaseStepActionExecution, Integer control) {
// Used for logging purposes
String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";
LOG.debug(logPrefix + "Starting to save Page Source File.");
TestCaseExecutionFile object = null;
String test = testCaseExecution.getTest();
String testCase = testCaseExecution.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);
try {
Recorder recorder = this.initFilenames(testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getId(), test, testCase, step, index, sequence, controlString, null, 0, "pagesource", "html", false);
File dir = new File(recorder.getFullPath());
dir.mkdirs();
File file = new File(recorder.getFullFilename());
try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
fileOutputStream.write(this.webdriverService.getPageSource(testCaseExecution.getSession()).getBytes());
fileOutputStream.close();
// Index file created to database.
object = testCaseExecutionFileFactory.create(0, testCaseExecution.getId(), recorder.getLevel(), "Page Source", recorder.getRelativeFilenameURL(), "HTML", "", null, "", null);
testCaseExecutionFileService.save(object);
} catch (FileNotFoundException ex) {
LOG.error(logPrefix + ex.toString());
} catch (IOException ex) {
LOG.error(logPrefix + ex.toString());
}
LOG.debug(logPrefix + "Page Source file saved in : " + recorder.getRelativeFilenameURL());
} catch (CerberusException ex) {
LOG.error(logPrefix + ex.toString());
}
return object;
}
use of org.cerberus.engine.entity.Recorder in project cerberus-source by cerberustesting.
the class RecorderService method recordSeleniumLog.
@Override
public TestCaseExecutionFile recordSeleniumLog(TestCaseExecution testCaseExecution) {
TestCaseExecutionFile object = null;
// Used for logging purposes
String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";
if (testCaseExecution.getApplicationObj().getType().equals(Application.TYPE_GUI)) {
if (testCaseExecution.getSeleniumLog() == 2 || (testCaseExecution.getSeleniumLog() == 1 && !testCaseExecution.getControlStatus().equals("OK"))) {
LOG.debug(logPrefix + "Starting to save Selenium log file.");
try {
Recorder recorder = this.initFilenames(testCaseExecution.getId(), null, null, null, null, null, null, null, 0, "selenium_log", "txt", false);
File dir = new File(recorder.getFullPath());
dir.mkdirs();
File file = new File(recorder.getFullFilename());
try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(baos);
for (String element : this.webdriverService.getSeleniumLog(testCaseExecution.getSession())) {
out.writeBytes(element);
}
byte[] bytes = baos.toByteArray();
fileOutputStream.write(bytes);
out.close();
baos.close();
fileOutputStream.close();
// Index file created to database.
object = testCaseExecutionFileFactory.create(0, testCaseExecution.getId(), recorder.getLevel(), "Selenium log", recorder.getRelativeFilenameURL(), "TXT", "", null, "", null);
testCaseExecutionFileService.save(object);
} catch (FileNotFoundException ex) {
LOG.error(logPrefix + ex.toString());
} catch (IOException ex) {
LOG.error(logPrefix + ex.toString());
}
LOG.debug(logPrefix + "Selenium log recorded in : " + recorder.getRelativeFilenameURL());
} catch (CerberusException ex) {
LOG.error(logPrefix + ex.toString());
}
}
} else {
LOG.debug(logPrefix + "Selenium Log not recorded because test on non GUI application");
}
return object;
}
use of org.cerberus.engine.entity.Recorder 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.engine.entity.Recorder in project cerberus-source by cerberustesting.
the class RecorderService method recordUploadedFile.
@Override
public void recordUploadedFile(long executionId, TestCaseStepActionExecution tcsae, FileItem uploadedFile) {
String UploadedfileName = new File(uploadedFile.getName()).getName();
try {
// UPLOADED File.
Recorder recorder = this.initFilenames(executionId, tcsae.getTest(), tcsae.getTestCase(), String.valueOf(tcsae.getStep()), String.valueOf(tcsae.getIndex()), String.valueOf(tcsae.getSequence()), null, null, 0, "image", "jpg", false);
File storeFile = new File(recorder.getFullFilename());
// saves the file on disk
uploadedFile.write(storeFile);
// Index file created to database.
testCaseExecutionFileService.save(executionId, recorder.getLevel(), "Image", recorder.getRelativeFilenameURL(), "JPG", "");
} catch (Exception ex) {
LOG.error("File: " + UploadedfileName + " failed to be uploaded/saved: " + ex.toString());
}
}
Aggregations