Best Cerberus-source code snippet using org.cerberus.engine.execution.impl.RecorderService.recordScreenshot
Source:RecorderService.java
...113 * Only if the return code is not equal to Cancel, meaning lost114 * connectivity with selenium.115 */116 if (!returnCode.equals("CA")) {117 objectFile = this.recordScreenshot(myExecution, testCaseStepActionExecution, controlNumber);118 if (objectFile != null) {119 objectFileList.add(objectFile);120 }121 } else {122 LOG.debug(logPrefix + "Not Doing screenshot because connectivity with selenium server lost.");123 }124 }125 } else {126 LOG.debug(logPrefix + "Not Doing screenshot because of the screenshot parameter or flag on the last Action result.");127 }128 /**129 * PAGESOURCE management. Get PageSource if requested by the last Action130 * MessageEvent.131 *132 */133 if ((myExecution.getPageSource() == 2) || ((myExecution.getPageSource() == 1) && (getPageSource))) {134 if (applicationType.equals(Application.TYPE_GUI)135 || applicationType.equals(Application.TYPE_APK)136 || applicationType.equals(Application.TYPE_IPA)) {137 /**138 * Only if the return code is not equal to Cancel, meaning lost139 * connectivity with selenium.140 */141 if (!returnCode.equals("CA")) {142 objectFile = this.recordPageSource(myExecution, testCaseStepActionExecution, controlNumber);143 if (objectFile != null) {144 objectFileList.add(objectFile);145 }146 } else {147 LOG.debug(logPrefix + "Not Doing screenshot because connectivity with selenium server lost.");148 }149 }150 } else {151 LOG.debug(logPrefix + "Not getting page source because of the pageSource parameter or flag on the last Action result.");152 }153 /**154 * Last call XML SOURCE management. Get Source of the XML if requested155 * by the last Action or control MessageEvent.156 *157 */158 if (applicationType.equals(Application.TYPE_SRV)159 && ((myExecution.getPageSource() == 2) || ((myExecution.getPageSource() == 1) && (getPageSource))160 || (myExecution.getScreenshot() == 2) || ((myExecution.getScreenshot() == 1) && (doScreenshot)))) {161 //Record the Request and Response.162 AppService se = (AppService) testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getLastServiceCalled();163 if (se != null) { // No Calls were performed previously164 List<TestCaseExecutionFile> objectFileSOAPList = new ArrayList<TestCaseExecutionFile>();165 objectFileSOAPList = this.recordServiceCall(myExecution, testCaseStepActionExecution, controlNumber, null, se);166 if (objectFileSOAPList.isEmpty() != true) {167 for (TestCaseExecutionFile testCaseExecutionFile : objectFileSOAPList) {168 objectFileList.add(testCaseExecutionFile);169 }170 }171 }172 }173 return objectFileList;174 }175 @Override176 public AnswerItem recordManuallyFile(TestCaseStepActionExecution testCaseStepActionExecution, TestCaseStepActionControlExecution testCaseStepActionControlExecution, String extension, String desc, FileItem file, Integer id, String fileName, Integer fileID) {177 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",178 "Can't upload file");179 AnswerItem a = new AnswerItem();180 TestCaseExecutionFile object = null;181 String returnCode;182 Integer controlNumber = 0;183 String test = "";184 String testCase = "";185 String step = "";186 String index = "";187 String sequence = "";188 String controlString = "";189 Integer myExecution = id;190 if (testCaseStepActionControlExecution == null) {191 test = testCaseStepActionExecution.getTest();192 testCase = testCaseStepActionExecution.getTestCase();193 step = String.valueOf(testCaseStepActionExecution.getStep());194 index = String.valueOf(testCaseStepActionExecution.getIndex());195 sequence = String.valueOf(testCaseStepActionExecution.getSequence());196 controlString = controlNumber.equals(0) ? null : String.valueOf(controlNumber);197 returnCode = testCaseStepActionExecution.getReturnCode();198 } else {199 returnCode = testCaseStepActionControlExecution.getReturnCode();200 controlNumber = testCaseStepActionControlExecution.getControlSequence();201 test = testCaseStepActionControlExecution.getTest();202 testCase = testCaseStepActionControlExecution.getTestCase();203 step = String.valueOf(testCaseStepActionControlExecution.getStep());204 index = String.valueOf(testCaseStepActionControlExecution.getIndex());205 sequence = String.valueOf(testCaseStepActionControlExecution.getSequence());206 controlString = controlNumber.equals(0) ? null : String.valueOf(controlNumber);207 }208 // Used for logging purposes209 String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - [" + test + " - " + testCase + " - step: " + step + " action: " + sequence + "] ";210 try {211 Recorder recorder = new Recorder();212 String name = "";213 File dir = null;214 if (file != null) {215 name = file.getName();216 extension = name.substring(name.lastIndexOf('.') + 1, name.length());217 extension = extension.toUpperCase();218 extension = testCaseExecutionFileService.checkExtension(name, extension);219 recorder = this.initFilenames(myExecution, test, testCase, step, index, sequence, controlString, null, 0, name.substring(0, name.lastIndexOf('.')), extension, true);220 dir = new File(recorder.getFullPath());221 } else {222 name = fileName;223 extension = testCaseExecutionFileService.checkExtension(name, extension);224 if (name.contains(".")) {225 recorder = this.initFilenames(myExecution, test, testCase, step, index, sequence, controlString, null, 0, name.substring(0, name.lastIndexOf('.')), extension, true);226 dir = new File(recorder.getFullPath());227 } else {228 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);229 msg.setDescription(msg.getDescription().replace("%ITEM%", "manual testcase execution file")230 .replace("%OPERATION%", "Create")231 .replace("%REASON%", "file is missing!"));232 a.setResultMessage(msg);233 return a;234 }235 }236 if (!dir.exists()) {237 try {238 boolean isCreated = dir.mkdirs();239 if (!isCreated) {240 throw new SecurityException();241 }242 } catch (SecurityException se) {243 LOG.warn("Unable to create manual execution file dir: " + se.getMessage());244 msg = new MessageEvent(MessageEventEnum.FILE_ERROR).resolveDescription("DESCRIPTION",245 se.toString()).resolveDescription("MORE", "Please check the parameter cerberus_exemanualmedia_path");246 a.setResultMessage(msg);247 return a;248 }249 }250 if (file != null) {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 it...
recordScreenshot
Using AI Code Generation
1import org.cerberus.engine.execution.impl.RecorderService2def recorder = new RecorderService()3recorder.recordScreenshot()4import org.cerberus.engine.execution.impl.RecorderService5def recorder = new RecorderService()6recorder.recordVideo()7import org.cerberus.engine.execution.impl.RecorderService8def recorder = new RecorderService()9recorder.recordLog()10import org.cerberus.engine.execution.impl.RecorderService11def recorder = new RecorderService()12recorder.recordScreenshot()13import org.cerberus.engine.execution.impl.RecorderService14def recorder = new RecorderService()15recorder.recordVideo()16import org.cerberus.engine.execution.impl.RecorderService17def recorder = new RecorderService()18recorder.recordLog()19import org.cerberus.engine.execution.impl.RecorderService20def recorder = new RecorderService()21recorder.recordScreenshot()22import org.cerberus.engine.execution.impl.RecorderService23def recorder = new RecorderService()24recorder.recordVideo()25import org.cerberus.engine.execution.impl.RecorderService26def recorder = new RecorderService()27recorder.recordLog()28import org.cerberus.engine.execution.impl.RecorderService29def recorder = new RecorderService()30recorder.recordScreenshot()31import org.cerberus.engine.execution.impl.RecorderService32def recorder = new RecorderService()33recorder.recordVideo()
recordScreenshot
Using AI Code Generation
1import org.cerberus.engine.execution.impl.RecorderService2import org.cerberus.engine.execution.impl.element.*3import org.cerberus.engine.execution.impl.action.*4import org.cerberus.engine.execution.impl.action.interaction.*5import org.cerberus.engine.execution.impl.action.interaction.impl.*6import org.cerberus.engine.execution.impl.action.interaction.impl.assertion.*7import org.cerberus.engine.execution.impl.action.interaction.impl.wait.*8import org.cerberus.engine.execution.impl.action.interaction.impl.assertion.*9import org.cerberus.engine.execution.impl.action.interaction.impl.assertion.impl.*10import org.cerberus.engine.execution.impl.action.interaction.impl.wait.impl.*11import org.cerberus.engine.execution.impl.action.interaction.impl.assertion.impl.*12import org.cerberus.engine.execution.impl.action.interaction.impl.assertion.impl.*13import org.cerberus.engine.execution.impl.action.interaction.impl.wait.impl.*14import org.cerberus.engine.ExecutionStatus
recordScreenshot
Using AI Code Generation
1import org.cerberus.engine.execution.impl.RecorderService2import org.cerberus.util.TestData3import org.openqa.selenium.OutputType4import org.openqa.selenium.TakesScreenshot5import org.openqa.selenium.WebDriverException6import org.apache.commons.codec.binary.Base647import java.util.Date8import java.text.SimpleDateFormat9def driver = cerberus.getDriver()10def record = new RecorderService()11def screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64)12def date = new Date()13def dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss")14def fileName = "screenshot_" + dateFormat.format(date) + ".png"15record.recordScreenshot(fileName, screenshot)16import org.cerberus.engine.execution.impl.RecorderService17import org.apache.commons.codec.binary.Base6418import java.util.Date19import java.text.SimpleDateFormat20def record = new RecorderService()21def base64Video = record.recordVideo()22def date = new Date()23def dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss")24def fileName = "video_" + dateFormat.format(date) + ".mp4"25record.recordVideo(fileName, base64Video)26import org.cerberus.engine.execution.impl.RecorderService27import org.apache.commons.codec.binary.Base6428import java.util.Date29import java.text.SimpleDateFormat30def record = new RecorderService()31def base64Video = record.recordVideo()32def date = new Date()33def dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss")34def fileName = "video_" + dateFormat.format(date) + ".mp4"35record.recordVideo(fileName, base64Video)36import org.cerberus.engine.execution.impl.RecorderService37import org.apache.commons.codec.binary.Base6438import java.util.Date39import java.text.SimpleDateFormat40def record = new RecorderService()41def base64Video = record.recordVideo()42def date = new Date()43def dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss")44def fileName = "video_" + dateFormat.format(date) + ".mp4"45record.recordVideo(fileName, base64Video)
recordScreenshot
Using AI Code Generation
1def currentTestCase = cerberusTest.getCurrentTestCase()2def currentExecution = cerberusTest.getCurrentExecution()3def screenshotFolder = cerberusTest.getApplicationObject("screenshotFolder")4cerberusTest.getApplicationObject("recorderService").recordScreenshot(currentExecutionId, currentTestCaseName, screenshotFolder)5cerberusTest.getApplicationObject("recorderService").addScreenshotToReport(currentExecutionId, currentTestCaseName, screenshotFolder)6cerberusTest.getApplicationObject("recorderService").addCommentToReport(currentExecutionId, currentTestCaseName, "Screenshot of the current page")7cerberusTest.getApplicationObject("recorderService").addFileToReport(currentExecutionId, currentTestCaseName, "C:\\temp\\test.txt", "Test file")8cerberusTest.getApplicationObject("recorderService").addScreenshotToReport(currentExecutionId, currentTestCaseName, screenshotFolder)9cerberusTest.getApplicationObject("recorderService").addPageSourceToReport(currentExecutionId, currentTestCaseName, screenshotFolder)10cerberusTest.getApplicationObject("recorderService").addVideoToReport(currentExecutionId, currentTestCaseName, "C:\\temp\\test.mp4", "Test video")11cerberusTest.getApplicationObject("recorderService").addFileToReport(currentExecutionId, currentTestCaseName, "C:\\temp\\test.txt", "Test file")12cerberusTest.getApplicationObject("recorderService").addFileToReport(currentExecutionId, currentTestCaseName
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!