How to use getFileName method of org.cerberus.engine.entity.Recorder class

Best Cerberus-source code snippet using org.cerberus.engine.entity.Recorder.getFileName

Source:RecorderService.java Github

copy

Full Screen

...251 AnswerItem<TestCaseExecutionFile> current = testCaseExecutionFileService.readByKey(myExecution, recorder.getLevel(), desc);252 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);253 if (current.getItem() != null) {254 try {255 File temp = new File(recorder.getRootFolder() + current.getItem().getFileName());256 temp.delete();257 } catch (SecurityException se) {258 LOG.warn("Unable to create manual execution file dir: " + se.getMessage());259 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",260 se.toString());261 }262 }263 try {264 file.write(new File(recorder.getFullFilename()));265 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("DESCRIPTION",266 "Manual Execution File uploaded");267 msg.setDescription(msg.getDescription().replace("%ITEM%", "Manual Execution File").replace("%OPERATION%", "Upload"));268 LOG.debug(logPrefix + "Copy file finished with success - source: " + file.getName() + " destination: " + recorder.getRelativeFilenameURL());269 object = testCaseExecutionFileFactory.create(fileID, myExecution, recorder.getLevel(), desc, recorder.getRelativeFilenameURL(), extension, "", null, "", null);270 } catch (Exception e) {271 LOG.warn("Unable to upload Manual Execution File: " + e.getMessage());272 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",273 e.toString());274 }275 } else {276 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("DESCRIPTION",277 "Manual Execution File updated");278 msg.setDescription(msg.getDescription().replace("%ITEM%", "Manual Execution File").replace("%OPERATION%", "updated"));279 LOG.debug(logPrefix + "Updated test case manual file finished with success");280 object = testCaseExecutionFileFactory.create(fileID, myExecution, recorder.getLevel(), desc, name, extension, "", null, "", null);281 }282 testCaseExecutionFileService.saveManual(object);283 } catch (CerberusException e) {284 LOG.error(logPrefix + e.toString());285 }286 a.setResultMessage(msg);287 a.setItem(object);288 return a;289 }290 @Override291 public TestCaseExecutionFile recordScreenshot(TestCaseExecution testCaseExecution, TestCaseStepActionExecution testCaseStepActionExecution, Integer control) {292 TestCaseExecutionFile object = null;293 String test = testCaseStepActionExecution.getTest();294 String testCase = testCaseStepActionExecution.getTestCase();295 String step = String.valueOf(testCaseStepActionExecution.getStep());296 String index = String.valueOf(testCaseStepActionExecution.getIndex());297 String sequence = String.valueOf(testCaseStepActionExecution.getSequence());298 String controlString = control.equals(0) ? null : String.valueOf(control);299 long runId = testCaseExecution.getId();300 String applicationType = testCaseExecution.getApplicationObj().getType();301 // Used for logging purposes302 String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - [" + test + " - " + testCase + " - step: " + step + " action: " + sequence + "] ";303 LOG.debug(logPrefix + "Doing screenshot.");304 /**305 * Take Screenshot and write it306 */307 File newImage = null;308 if (applicationType.equals(Application.TYPE_GUI)309 || applicationType.equals(Application.TYPE_APK)310 || applicationType.equals(Application.TYPE_IPA)) {311 newImage = this.webdriverService.takeScreenShotFile(testCaseExecution.getSession());312 } else if (applicationType.equals(Application.TYPE_FAT)) {313 newImage = this.sikuliService.takeScreenShotFile(testCaseExecution.getSession());314 }315 if (newImage != null) {316 try {317 Recorder recorder = this.initFilenames(runId, test, testCase, step, index, sequence, controlString, null, 0, "screenshot", "png", false);318 LOG.debug(logPrefix + "FullPath " + recorder.getFullPath());319 File dir = new File(recorder.getFullPath());320 if (!dir.exists()) {321 LOG.debug(logPrefix + "Create directory for execution " + recorder.getFullPath());322 dir.mkdirs();323 }324 // Getting the max size of the screenshot.325 long maxSizeParam = parameterService.getParameterIntegerByKey("cerberus_screenshot_max_size", "", 1048576);326 if (maxSizeParam < newImage.length()) {327 LOG.warn(logPrefix + "Screen-shot size exceeds the maximum defined in configurations " + newImage.getName() + " destination: " + recorder.getRelativeFilenameURL());328 }329 //copies the temp file to the execution file330 FileUtils.copyFile(newImage, new File(recorder.getFullFilename()));331 LOG.debug(logPrefix + "Copy file finished with success - source: " + newImage.getName() + " destination: " + recorder.getRelativeFilenameURL());332 // Index file created to database.333 object = testCaseExecutionFileFactory.create(0, testCaseExecution.getId(), recorder.getLevel(), "Screenshot", recorder.getRelativeFilenameURL(), "PNG", "", null, "", null);334 testCaseExecutionFileService.save(object);335 //deletes the temporary file336 FileUtils.forceDelete(newImage);337 LOG.debug(logPrefix + "Temp file deleted with success " + newImage.getName());338 LOG.debug(logPrefix + "Screenshot done in : " + recorder.getRelativeFilenameURL());339 } catch (IOException ex) {340 LOG.error(logPrefix + ex.toString());341 } catch (CerberusException ex) {342 LOG.error(logPrefix + ex.toString());343 }344 } else {345 LOG.warn(logPrefix + "Screenshot returned null.");346 }347 return object;348 }349 @Override350 public TestCaseExecutionFile recordPageSource(TestCaseExecution testCaseExecution, TestCaseStepActionExecution testCaseStepActionExecution, Integer control) {351 // Used for logging purposes352 String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";353 LOG.debug(logPrefix + "Starting to save Page Source File.");354 TestCaseExecutionFile object = null;355 String test = testCaseExecution.getTest();356 String testCase = testCaseExecution.getTestCase();357 String step = String.valueOf(testCaseStepActionExecution.getStep());358 String index = String.valueOf(testCaseStepActionExecution.getIndex());359 String sequence = String.valueOf(testCaseStepActionExecution.getSequence());360 String controlString = control.equals(0) ? null : String.valueOf(control);361 try {362 Recorder recorder = this.initFilenames(testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getId(), test, testCase, step, index, sequence, controlString, null, 0, "pagesource", "html", false);363 File dir = new File(recorder.getFullPath());364 dir.mkdirs();365 File file = new File(recorder.getFullFilename());366 try(FileOutputStream fileOutputStream = new FileOutputStream(file);) {367 fileOutputStream.write(this.webdriverService.getPageSource(testCaseExecution.getSession()).getBytes());368 fileOutputStream.close();369 // Index file created to database.370 object = testCaseExecutionFileFactory.create(0, testCaseExecution.getId(), recorder.getLevel(), "Page Source", recorder.getRelativeFilenameURL(), "HTML", "", null, "", null);371 testCaseExecutionFileService.save(object);372 } catch (FileNotFoundException ex) {373 LOG.error(logPrefix + ex.toString());374 } catch (IOException ex) {375 LOG.error(logPrefix + ex.toString());376 }377 LOG.debug(logPrefix + "Page Source file saved in : " + recorder.getRelativeFilenameURL());378 } catch (CerberusException ex) {379 LOG.error(logPrefix + ex.toString());380 }381 return object;382 }383 @Override384 public List<TestCaseExecutionFile> recordServiceCall(TestCaseExecution testCaseExecution, TestCaseStepActionExecution testCaseStepActionExecution,385 Integer control, String property, AppService se) {386 // Used for logging purposes387 String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";388 List<TestCaseExecutionFile> objectFileList = new ArrayList<TestCaseExecutionFile>();389 TestCaseExecutionFile object = null;390 String test = null;391 String testCase = null;392 String step = null;393 String index = null;394 String sequence = null;395 if (testCaseStepActionExecution != null) {396 test = testCaseExecution.getTest();397 testCase = testCaseExecution.getTestCase();398 step = String.valueOf(testCaseStepActionExecution.getStep());399 index = String.valueOf(testCaseStepActionExecution.getIndex());400 sequence = String.valueOf(testCaseStepActionExecution.getSequence());401 }402 String controlString = control.equals(0) ? null : String.valueOf(control);403 long runId = testCaseExecution.getId();404 int propertyIndex = 0;405 if (!(StringUtil.isNullOrEmpty(property))) {406 propertyIndex = 1;407 }408 try {409 // Service Call META data information.410 Recorder recorderRequest = this.initFilenames(runId, test, testCase, step, index, sequence, controlString, property, propertyIndex, "call", "json", false);411 recordFile(recorderRequest.getFullPath(), recorderRequest.getFileName(), se.toJSONOnExecution().toString());412 // Index file created to database.413 object = testCaseExecutionFileFactory.create(0, runId, recorderRequest.getLevel(), "Service Call", recorderRequest.getRelativeFilenameURL(), "JSON", "", null, "", null);414 testCaseExecutionFileService.save(object);415 objectFileList.add(object);416 // REQUEST.417 if (!(StringUtil.isNullOrEmpty(se.getServiceRequest()))) {418 String messageFormatExt = "txt";419 String messageFormat = TestCaseExecutionFile.FILETYPE_TXT;420 if (se.getServiceRequest().startsWith("{")) { // TODO find a better solution to guess the format of the request.421 messageFormatExt = "json";422 messageFormat = TestCaseExecutionFile.FILETYPE_JSON;423 } else if (se.getServiceRequest().startsWith("<")) {424 messageFormatExt = "xml";425 messageFormat = TestCaseExecutionFile.FILETYPE_XML;426 }427 recorderRequest = this.initFilenames(runId, test, testCase, step, index, sequence, controlString, property, propertyIndex, "request", messageFormatExt, false);428 recordFile(recorderRequest.getFullPath(), recorderRequest.getFileName(), se.getServiceRequest());429 // Index file created to database.430 object = testCaseExecutionFileFactory.create(0, runId, recorderRequest.getLevel(), "Request", recorderRequest.getRelativeFilenameURL(), messageFormat, "", null, "", null);431 testCaseExecutionFileService.save(object);432 objectFileList.add(object);433 }434 // RESPONSE if exists.435 if (!(StringUtil.isNullOrEmpty(se.getResponseHTTPBody()))) {436 String messageFormatExt = "txt";437 String messageFormat = TestCaseExecutionFile.FILETYPE_TXT;438 switch (se.getResponseHTTPBodyContentType()) {439 case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:440 messageFormatExt = "json";441 messageFormat = TestCaseExecutionFile.FILETYPE_JSON;442 break;443 case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:444 messageFormatExt = "xml";445 messageFormat = TestCaseExecutionFile.FILETYPE_XML;446 break;447 default:448 messageFormatExt = "txt";449 messageFormat = TestCaseExecutionFile.FILETYPE_TXT;450 break;451 }452 Recorder recorderResponse = this.initFilenames(runId, test, testCase, step, index, sequence, controlString, property, propertyIndex, "response", messageFormatExt, false);453 recordFile(recorderResponse.getFullPath(), recorderResponse.getFileName(), se.getResponseHTTPBody());454 // Index file created to database.455 object = testCaseExecutionFileFactory.create(0, runId, recorderResponse.getLevel(), "Response", recorderResponse.getRelativeFilenameURL(), messageFormat, "", null, "", null);456 testCaseExecutionFileService.save(object);457 objectFileList.add(object);458 }459 } catch (Exception ex) {460 LOG.error(logPrefix + ex.toString());461 }462 return objectFileList;463 }464 @Override465 public TestCaseExecutionFile recordTestDataLibProperty(Long runId, String property, int propertyIndex, List<HashMap<String, String>> result) {466 TestCaseExecutionFile object = null;467 // Used for logging purposes468 String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";469 try {470 JSONArray jsonResult = null;471 jsonResult = dataLibService.convertToJSONObject(result);472 // RESULT.473 Recorder recorder = this.initFilenames(runId, null, null, null, null, null, null, property, propertyIndex, "result", "json", false);474 recordFile(recorder.getFullPath(), recorder.getFileName(), jsonResult.toString());475 // Index file created to database.476 object = testCaseExecutionFileFactory.create(0, runId, recorder.getLevel(), "Result", recorder.getRelativeFilenameURL(), "JSON", "", null, "", null);477 testCaseExecutionFileService.save(object);478 } catch (CerberusException | JSONException ex) {479 LOG.error(logPrefix + "TestDataLib file was not saved due to unexpected error." + ex.toString());480 }481 return object;482 }483 @Override484 public TestCaseExecutionFile recordSeleniumLog(TestCaseExecution testCaseExecution) {485 TestCaseExecutionFile object = null;486 // Used for logging purposes487 String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";488 if (testCaseExecution.getApplicationObj().getType().equals(Application.TYPE_GUI)) {...

Full Screen

Full Screen

getFileName

Using AI Code Generation

copy

Full Screen

1import org.cerberus.engine.entity.Recorder;2import org.cerberus.crud.entity.TestCaseExecution;3import org.cerberus.crud.entity.TestCaseExecutionData;4import org.cerberus.crud.entity.TestCaseExecutionFile;5import org.cerberus.crud.service.IParameterService;6import org.cerberus.engine.entity.MessageEvent;7import org.cerberus.engine.entity.MessageGeneral;8import org.cerberus.engine.executio

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful