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

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

Source:RecorderService.java Github

copy

Full Screen

...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)) {489 if (testCaseExecution.getSeleniumLog() == 2 || (testCaseExecution.getSeleniumLog() == 1 && !testCaseExecution.getControlStatus().equals("OK"))) {490 LOG.debug(logPrefix + "Starting to save Selenium log file.");491 try {492 Recorder recorder = this.initFilenames(testCaseExecution.getId(), null, null, null, null, null, null, null, 0, "selenium_log", "txt", false);493 File dir = new File(recorder.getFullPath());494 dir.mkdirs();495 File file = new File(recorder.getFullFilename());496 497 try(FileOutputStream fileOutputStream = new FileOutputStream(file);) {498 ByteArrayOutputStream baos = new ByteArrayOutputStream();499 DataOutputStream out = new DataOutputStream(baos);500 for (String element : this.webdriverService.getSeleniumLog(testCaseExecution.getSession())) {501 out.writeBytes(element);502 }503 byte[] bytes = baos.toByteArray();504 fileOutputStream.write(bytes);505 out.close();506 baos.close();507 fileOutputStream.close();508 // Index file created to database.509 object = testCaseExecutionFileFactory.create(0, testCaseExecution.getId(), recorder.getLevel(), "Selenium log", recorder.getRelativeFilenameURL(), "TXT", "", null, "", null);510 testCaseExecutionFileService.save(object);511 } catch (FileNotFoundException ex) {512 LOG.error(logPrefix + ex.toString());513 } catch (IOException ex) {514 LOG.error(logPrefix + ex.toString());515 }516 LOG.debug(logPrefix + "Selenium log recorded in : " + recorder.getRelativeFilenameURL());517 } catch (CerberusException ex) {518 LOG.error(logPrefix + ex.toString());519 }520 }521 } else {522 LOG.debug(logPrefix + "Selenium Log not recorded because test on non GUI application");523 }524 return object;525 }526 @Override527 public void recordUploadedFile(long executionId, TestCaseStepActionExecution tcsae, FileItem uploadedFile) {528 String UploadedfileName = new File(uploadedFile.getName()).getName();529 try {530 // UPLOADED File.531 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);532 File storeFile = new File(recorder.getFullFilename());533 // saves the file on disk534 uploadedFile.write(storeFile);535 // Index file created to database.536 testCaseExecutionFileService.save(executionId, recorder.getLevel(), "Image", recorder.getRelativeFilenameURL(), "JPG", "");537 } catch (Exception ex) {538 LOG.error("File: " + UploadedfileName + " failed to be uploaded/saved: " + ex.toString());539 }540 }541 /**542 * Auxiliary method that saves a file543 *544 * @param path - directory path545 * @param fileName - name of the file546 * @param content -content of the file547 */548 private void recordFile(String path, String fileName, String content) {549 LOG.info("Starting to save File - recordFile.");550 File dir = new File(path);...

Full Screen

Full Screen

getRelativeFilenameURL

Using AI Code Generation

copy

Full Screen

1package org.cerberus.engine.entity;2import org.apache.logging.log4j.LogManager;3import org.apache.logging.log4j.Logger;4import org.cerberus.engine.entity.MessageEvent;5import org.cerberus.engine.entity.MessageGeneral;6import org.cerberus.engine.entity.MessageGeneralEnum;7import org.cerberus.engine.entity.MessageEventEnum;8import org.cerberus.engine.entity.MessageEventFactory;9import org.cerberus.util.StringUtil;10import org.cerberus.util.answer.Answer;11import org.cerberus.util.answer.AnswerItem;12import org.cerberus.util.answer.AnswerList;13import org.cerberus.util.answer.AnswerUtil;14import org.cerberus.util.answer.AnswerUtil;15import org.cerberus.exception.CerberusException;16import org.cerberus.crud.entity.Application;17import org.cerberus.crud.entity.BuildRevisionInvariant;

Full Screen

Full Screen

getRelativeFilenameURL

Using AI Code Generation

copy

Full Screen

1import org.cerberus.engine.entity.*;2import org.cerberus.engine.entity.MessageEvent;3import org.cerberus.engine.entity.MessageEventFactory;4import org.cerberus.engine.entity.MessageGeneral;5import org.cerberus.engine.entity.MessageGeneralEnum;6import org.cerberus.engine.entity.MessageGeneralFactory;7import org.cerberus.engine.entity.MessageEventEnum;8import org.cerberus.engine.execution.IExecutionHandler;9import org.cerberus.engine.execution.impl.ExecutionHandler;10import org.cerberus.engine.execution.impl.Screenshot;11import org.cerberus.engine.generation.Test;12import org.cerberus.engine.generation.TestCaseCountryProperties;13import org.cerberus.engine.generation.TestCaseStepActionControlExecution;14import org.cerberus.engine.generation.TestCaseStepActionExecution;15import org.cerberus.engine.generation.TestCaseStepExecution;16import org.cerberus.engine.generation.TestCaseExecution;17import org.cerberus.engine.generation.factory.TestCaseExecutionFactory;18import org.cerberus.engine.generation.factory.TestCaseStepActionExecutionFactory;19import org.cerberus.engine.generation.factory.TestCaseStepExecutionFactory;20import org.cerberus.engine.generation.factory.TestCaseExecutionFactory;21import org.cerberus.engine.generation.factory.TestCaseStepActionExecutionFactory;22import org.cerberus.engine.generation.factory.TestCaseStepExecutionFactory;23import org.cerberus.engine.generation.factory.TestCaseExecutionFactory;24import org.cerberus.engine.generation.factory.TestCaseStepActionExecutionFactory;25import org.cerberus.engine.generation.factory.TestCaseStepExecutionFactory;26import org.cerberus.engine.generation.factory.TestCaseExecutionFactory;27import org.cerberus.engine.generation.factory.TestCaseStepActionExecutionFactory;28import org.cerberus.engine.generation.factory.TestCaseStepExecutionFactory;29import org.cerberus.engine.generation.factory.TestCaseExecutionFactory;30import org.cerberus.engine.generation.factory.TestCaseStepActionExecutionFactory;31import org.cerberus.engine.generation.factory.TestCaseStepExecutionFactory;32import org.cerberus.engine.generation.factory.TestCaseExecutionFactory;33import org.cerberus.engine.generation.factory.TestCaseStepActionExecutionFactory;34import org.cerberus.engine.generation.factory.TestCaseStepExecutionFactory;35import org.cerberus.engine.generation.factory.TestCaseExecutionFactory;36import org.cerberus.engine.generation.factory.TestCaseStepActionExecutionFactory;37import org.cerber

Full Screen

Full Screen

getRelativeFilenameURL

Using AI Code Generation

copy

Full Screen

1import org.cerberus.engine.entity.Recorder;2String relativePath = Recorder.getRelativeFilenameURL("C:\\Users\\myuser\\Desktop\\myfile.txt");3Recorder.recordFile("C:\\Users\\myuser\\Desktop\\myfile.txt", relativePath);4Recorder.recordFile("C:\\Users\\myuser\\Desktop\\myfile.txt");5Recorder.recordFile("myfile.txt");6Recorder.recordFile("myfile.txt", "myfile.txt");7Recorder.recordFile("myfile.txt", "myfolder/myfile.txt");8Recorder.recordFile("myfile.txt", "../myfolder/myfile.txt");

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