How to use generateTestCaseExecutionTable method of org.cerberus.servlet.crud.testexecution.ReadTestCaseExecutionByTag class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.testexecution.ReadTestCaseExecutionByTag.generateTestCaseExecutionTable

Source:ReadTestCaseExecutionByTag.java Github

copy

Full Screen

...105 //Get Data from database106 List<TestCaseExecution> testCaseExecutions = testCaseExecutionService.readLastExecutionAndExecutionInQueueByTag(Tag);107 // Table that contain the list of testcases and corresponding executions108 if (outputReport.isEmpty() || outputReport.contains("table")) {109 jsonResponse.put("table", generateTestCaseExecutionTable(appContext, testCaseExecutions, statusFilter, countryFilter));110 }111 // Executions per Function (or Test).112 if (outputReport.isEmpty() || outputReport.contains("functionChart")) {113 jsonResponse.put("functionChart", generateFunctionChart(testCaseExecutions, Tag, statusFilter, countryFilter));114 }115 // Global executions stats per Status116 if (outputReport.isEmpty() || outputReport.contains("statsChart")) {117 jsonResponse.put("statsChart", generateStats(request, testCaseExecutions, statusFilter, countryFilter, true));118 }119 // BugTracker Recap120 if (outputReport.isEmpty() || outputReport.contains("bugTrackerStat")) {121 jsonResponse.put("bugTrackerStat", generateBugStats(request, testCaseExecutions, statusFilter, countryFilter));122 }123 // Labels Stats124 if (outputReport.isEmpty() || outputReport.contains("labelStat")) {125 jsonResponse.put("labelStat", generateLabelStats(appContext, request, testCaseExecutions, statusFilter, countryFilter));126 }127 if (!outputReport.isEmpty()) {128 //currently used to optimize the homePage129 if (outputReport.contains("totalStatsCharts") && !outputReport.contains("statsChart")) {130 jsonResponse.put("statsChart", generateStats(request, testCaseExecutions, statusFilter, countryFilter, false));131 }132 //currently used to optimize the homePage133 if (outputReport.contains("resendTag")) {134 jsonResponse.put("tag", Tag);135 }136 }137 Tag mytag = tagService.convert(tagService.readByKey(Tag));138 JSONObject tagJSON = convertTagToJSONObject(mytag);139 jsonResponse.put("tagObject", tagJSON);140 jsonResponse.put("tagDuration", (mytag.getDateEndQueue().getTime() - mytag.getDateCreated().getTime()) / 60000);141 answer.setItem(jsonResponse);142 answer.setResultMessage(answer.getResultMessage().resolveDescription("ITEM", "Tag Statistics").resolveDescription("OPERATION", "Read"));143 jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());144 jsonResponse.put("message", answer.getResultMessage().getDescription());145 jsonResponse.put("sEcho", echo);146 response.getWriter().print(jsonResponse.toString());147 } catch (ParseException ex) {148 LOG.error("Error on main call : " + ex);149 } catch (CerberusException ex) {150 LOG.error("Error on main call : " + ex);151 } catch (JSONException ex) {152 LOG.error("Error on main call : " + ex);153 } catch (Exception ex) {154 LOG.error("Error on main call : " + ex);155 }156 }157 private JSONObject testCaseExecutionToJSONObject(TestCaseExecution testCaseExecution) throws JSONException {158 JSONObject result = new JSONObject();159 result.put("ID", String.valueOf(testCaseExecution.getId()));160 result.put("QueueID", String.valueOf(testCaseExecution.getQueueID()));161 result.put("Test", JavaScriptUtils.javaScriptEscape(testCaseExecution.getTest()));162 result.put("TestCase", JavaScriptUtils.javaScriptEscape(testCaseExecution.getTestCase()));163 result.put("Environment", JavaScriptUtils.javaScriptEscape(testCaseExecution.getEnvironment()));164 result.put("Start", testCaseExecution.getStart());165 result.put("End", testCaseExecution.getEnd());166 result.put("Country", JavaScriptUtils.javaScriptEscape(testCaseExecution.getCountry()));167 result.put("RobotDecli", JavaScriptUtils.javaScriptEscape(testCaseExecution.getRobotDecli()));168 result.put("ControlStatus", JavaScriptUtils.javaScriptEscape(testCaseExecution.getControlStatus()));169 result.put("ControlMessage", JavaScriptUtils.javaScriptEscape(testCaseExecution.getControlMessage()));170 result.put("Status", JavaScriptUtils.javaScriptEscape(testCaseExecution.getStatus()));171 result.put("NbExecutions", String.valueOf(testCaseExecution.getNbExecutions()));172 if (testCaseExecution.getQueueState() != null) {173 result.put("QueueState", JavaScriptUtils.javaScriptEscape(testCaseExecution.getQueueState()));174 }175 String bugId;176 String comment;177 String function;178 String shortDesc;179 if ((testCaseExecution.getTestCaseObj() != null) && (testCaseExecution.getTestCaseObj().getTest() != null)) {180 if (testCaseExecution.getApplicationObj() != null && testCaseExecution.getApplicationObj().getBugTrackerUrl() != null181 && !"".equals(testCaseExecution.getApplicationObj().getBugTrackerUrl()) && testCaseExecution.getTestCaseObj().getBugID() != null) {182 bugId = testCaseExecution.getApplicationObj().getBugTrackerUrl().replace("%BUGID%", testCaseExecution.getTestCaseObj().getBugID());183 bugId = new StringBuffer("<a href='")184 .append(bugId)185 .append("' target='reportBugID'>")186 .append(testCaseExecution.getTestCaseObj().getBugID())187 .append("</a>")188 .toString();189 } else {190 bugId = testCaseExecution.getTestCaseObj().getBugID();191 }192 comment = JavaScriptUtils.javaScriptEscape(testCaseExecution.getTestCaseObj().getComment());193 function = JavaScriptUtils.javaScriptEscape(testCaseExecution.getTestCaseObj().getFunction());194 shortDesc = testCaseExecution.getTestCaseObj().getDescription();195 } else {196 bugId = "";197 comment = "";198 function = "";199 shortDesc = "";200 }201 result.put("BugID", bugId);202 result.put("Priority", JavaScriptUtils.javaScriptEscape(String.valueOf(testCaseExecution.getTestCaseObj().getPriority())));203 result.put("Comment", comment);204 result.put("Function", function);205 result.put("ShortDescription", shortDesc);206 result.put("Application", JavaScriptUtils.javaScriptEscape(testCaseExecution.getApplication()));207 return result;208 }209 private JSONObject getStatusList(HttpServletRequest request) {210 JSONObject statusList = new JSONObject();211 try {212 statusList.put("OK", ParameterParserUtil.parseStringParam(request.getParameter("OK"), "off"));213 statusList.put("KO", ParameterParserUtil.parseStringParam(request.getParameter("KO"), "off"));214 statusList.put("NA", ParameterParserUtil.parseStringParam(request.getParameter("NA"), "off"));215 statusList.put("NE", ParameterParserUtil.parseStringParam(request.getParameter("NE"), "off"));216 statusList.put("PE", ParameterParserUtil.parseStringParam(request.getParameter("PE"), "off"));217 statusList.put("FA", ParameterParserUtil.parseStringParam(request.getParameter("FA"), "off"));218 statusList.put("CA", ParameterParserUtil.parseStringParam(request.getParameter("CA"), "off"));219 statusList.put("QU", ParameterParserUtil.parseStringParam(request.getParameter("QU"), "off"));220 } catch (JSONException ex) {221 LOG.error("Error on getStatusList : " + ex);222 }223 return statusList;224 }225 private JSONObject getCountryList(HttpServletRequest request, ApplicationContext appContext) {226 JSONObject countryList = new JSONObject();227 try {228 IInvariantService invariantService = appContext.getBean(InvariantService.class);229 AnswerList answer = invariantService.readByIdname("COUNTRY"); //TODO: handle if the response does not turn ok230 for (Invariant country : (List<Invariant>) answer.getDataList()) {231 countryList.put(country.getValue(), ParameterParserUtil.parseStringParam(request.getParameter(country.getValue()), "off"));232 }233 } catch (JSONException ex) {234 LOG.error("Error on getCountryList : " + ex);235 }236 return countryList;237 }238 private JSONObject generateTestCaseExecutionTable(ApplicationContext appContext, List<TestCaseExecution> testCaseExecutions, JSONObject statusFilter, JSONObject countryFilter) {239 JSONObject testCaseExecutionTable = new JSONObject();240 LinkedHashMap<String, JSONObject> ttc = new LinkedHashMap<String, JSONObject>();241 LinkedHashMap<String, JSONObject> columnMap = new LinkedHashMap<String, JSONObject>();242 testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);243 AnswerList testCaseLabelList = testCaseLabelService.readByTestTestCase(null, null);244 for (TestCaseExecution testCaseExecution : testCaseExecutions) {245 try {246 String controlStatus = testCaseExecution.getControlStatus();247 // We check is Country and status is inside the fitered values.248 if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {249 JSONObject executionJSON = testCaseExecutionToJSONObject(testCaseExecution);250 String execKey = testCaseExecution.getEnvironment() + " " + testCaseExecution.getCountry() + " " + testCaseExecution.getRobotDecli();251 String testCaseKey = testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase();252 JSONObject execTab = new JSONObject();253 JSONObject ttcObject = new JSONObject();254 if (ttc.containsKey(testCaseKey)) {255 // We add an execution entry into the testcase line.256 ttcObject = ttc.get(testCaseKey);257 execTab = ttcObject.getJSONObject("execTab");258 execTab.put(execKey, executionJSON);259 ttcObject.put("execTab", execTab);260 Integer toto = (Integer) ttcObject.get("NbExecutionsTotal");261 toto += testCaseExecution.getNbExecutions() - 1;262 ttcObject.put("NbExecutionsTotal", toto);263 } else {264 // We add a new testcase entry (with The current execution).265 ttcObject.put("test", testCaseExecution.getTest());266 ttcObject.put("testCase", testCaseExecution.getTestCase());267 ttcObject.put("shortDesc", testCaseExecution.getDescription());268 ttcObject.put("status", testCaseExecution.getStatus());269 ttcObject.put("application", testCaseExecution.getApplication());270 boolean testExist = ((testCaseExecution.getTestCaseObj() != null) && (testCaseExecution.getTestCaseObj().getTest() != null));271 if (testExist) {272 ttcObject.put("function", testCaseExecution.getTestCaseObj().getFunction());273 ttcObject.put("priority", testCaseExecution.getTestCaseObj().getPriority());274 ttcObject.put("comment", testCaseExecution.getTestCaseObj().getComment());275 if ((testCaseExecution.getApplicationObj() != null) && (testCaseExecution.getApplicationObj().getBugTrackerUrl() != null) && (testCaseExecution.getTestCaseObj().getBugID() != null)) {276 ttcObject.put("bugId", new JSONObject("{\"bugId\":\"" + testCaseExecution.getTestCaseObj().getBugID() + "\",\"bugTrackerUrl\":\"" + testCaseExecution.getApplicationObj().getBugTrackerUrl().replace("%BUGID%", testCaseExecution.getTestCaseObj().getBugID()) + "\"}"));277 } else {278 ttcObject.put("bugId", new JSONObject("{\"bugId\":\"\",\"bugTrackerUrl\":\"\"}"));279 }280 } else {281 ttcObject.put("function", "");282 ttcObject.put("priority", 0);283 ttcObject.put("comment", "");284 ttcObject.put("bugId", new JSONObject("{\"bugId\":\"\",\"bugTrackerUrl\":\"\"}"));285 }286 // Flag that report if test case still exist.287 ttcObject.put("testExist", testExist);288 // Adding nb of execution on retry.289 ttcObject.put("NbExecutionsTotal", (testCaseExecution.getNbExecutions() - 1));290 execTab.put(execKey, executionJSON);291 ttcObject.put("execTab", execTab);292 /**293 * Iterate on the label retrieved and generate HashMap294 * based on the key Test_TestCase295 */296 LinkedHashMap<String, JSONArray> testCaseWithLabel = new LinkedHashMap();297 for (TestCaseLabel label : (List<TestCaseLabel>) testCaseLabelList.getDataList()) {298 if (Label.TYPE_STICKER.equals(label.getLabel().getType())) { // We only display STICKER Type Label in Reporting By Tag Page..299 String key = label.getTest() + "_" + label.getTestcase();300 JSONObject jo = new JSONObject().put("name", label.getLabel().getLabel()).put("color", label.getLabel().getColor()).put("description", label.getLabel().getDescription());301 if (testCaseWithLabel.containsKey(key)) {302 testCaseWithLabel.get(key).put(jo);303 } else {304 testCaseWithLabel.put(key, new JSONArray().put(jo));305 }306 }307 }308 ttcObject.put("labels", testCaseWithLabel.get(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase()));309 }310 ttc.put(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase(), ttcObject);311 JSONObject column = new JSONObject();312 column.put("country", testCaseExecution.getCountry());313 column.put("environment", testCaseExecution.getEnvironment());314 column.put("robotDecli", testCaseExecution.getRobotDecli());315 columnMap.put(testCaseExecution.getRobotDecli() + "_" + testCaseExecution.getCountry() + "_" + testCaseExecution.getEnvironment(), column);316 }317 Map<String, JSONObject> treeMap = new TreeMap<String, JSONObject>(columnMap);318 testCaseExecutionTable.put("tableContent", ttc.values());319 testCaseExecutionTable.put("iTotalRecords", ttc.size());320 testCaseExecutionTable.put("iTotalDisplayRecords", ttc.size());321 testCaseExecutionTable.put("tableColumns", treeMap.values());322 } catch (JSONException ex) {323 LOG.error("Error on generateTestCaseExecutionTable : " + ex);324 } catch (Exception ex) {325 LOG.error("Error on generateTestCaseExecutionTable : " + ex);326 }327 }328 return testCaseExecutionTable;329 }330 private JSONObject generateFunctionChart(List<TestCaseExecution> testCaseExecutions, String tag, JSONObject statusFilter, JSONObject countryFilter) throws JSONException {331 JSONObject jsonResult = new JSONObject();332 Map<String, JSONObject> axisMap = new HashMap<String, JSONObject>();333 String globalStart = "";334 String globalEnd = "";335 long globalStartL = 0;336 long globalEndL = 0;337 String globalStatus = "Finished";338 for (TestCaseExecution testCaseExecution : testCaseExecutions) {339 String key;...

Full Screen

Full Screen

generateTestCaseExecutionTable

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.crud.testexecution.ReadTestCaseExecutionByTag;2import org.cerberus.servlet.crud.testexecution.ReadTestCaseExecutionByTag;3import org.cerberus.util.answer.AnswerItem;4import org.cerberus.util.answer.AnswerList;5import org.cerberus.util.answer.AnswerUtil;6import org.cerberus.util.answer.Item;7import java.util.ArrayList;8import java.util.HashMap;9import java.util.List;10import java.util.Map;11String test = "test";12String testCase = "testCase";13String country = "country";14String environment = "environment";15String tag = "tag";16String build = "build";17String revision = "revision";18String browser = "browser";19String browserVersion = "browserVersion";20String platform = "platform";21String active = "active";22String verbose = "verbose";23String outputFormat = "outputFormat";24String outputFileName = "outputFileName";25Map<String, String[]> map = new HashMap<String, String[]>();26map.put(test, new String[]{"test"});27map.put(testCase, new String[]{"testCase"});28map.put(country, new String[]{"country"});29map.put(environment, new String[]{"environment"});30map.put(tag, new String[]{"tag"});31map.put(build, new String[]{"build"});32map.put(revision, new String[]{"revision"});33map.put(browser, new String[]{"browser"});34map.put(browserVersion, new String[]{"browserVersion"});35map.put(platform, new String[]{"platform"});36map.put(active, new String[]{"Y"});37map.put(verbose, new String[]{"Y"});38map.put(outputFormat, new String[]{"HTML"});39map.put(outputFileName, new String[]{"test.html"});40ReadTestCaseExecutionByTag readTestCaseExecutionByTag = new ReadTestCaseExecutionByTag();41AnswerItem<Map<String, String>> answer = readTestCaseExecutionByTag.generateTestCaseExecutionTable(map);42Map<String, String> result = answer.getItem();43String htmlTable = result.get("htmlTable");44email.setTemplateFile("testEmailTemplate.html");45email.setTemplateParameter("htmlTable", htmlTable);46email.sendEmail();47package org.cerberus.util.email;48import org.apache.logging.log4j.LogManager;49import org.apache

Full Screen

Full Screen

generateTestCaseExecutionTable

Using AI Code Generation

copy

Full Screen

1$(document).ready(function() {2 $.ajax({3 success: function(data) {4 var table = generateTestCaseExecutionTable(data);5 $('#table').append(table);6 $('#myModal').modal('show');7 }8 });9});10function generateTestCaseExecutionTable(data) {11 var table = document.createElement('table');12 table.setAttribute('class', 'table table-bordered');13 var thead = document.createElement('thead');14 var tr = document.createElement('tr');15 var th = document.createElement('th');16 th.innerHTML = "Test";17 tr.appendChild(th);18 var th = document.createElement('th');19 th.innerHTML = "Test Case";20 tr.appendChild(th);21 var th = document.createElement('th');22 th.innerHTML = "Country";23 tr.appendChild(th);24 var th = document.createElement('th');25 th.innerHTML = "Environment";26 tr.appendChild(th);27 var th = document.createElement('th');28 th.innerHTML = "Browser";29 tr.appendChild(th);30 var th = document.createElement('th');31 th.innerHTML = "Version";32 tr.appendChild(th);33 var th = document.createElement('th');34 th.innerHTML = "Platform";35 tr.appendChild(th);36 var th = document.createElement('th');37 th.innerHTML = "Control Status";38 tr.appendChild(th);39 var th = document.createElement('th');40 th.innerHTML = "Control Message";41 tr.appendChild(th);42 var th = document.createElement('th');43 th.innerHTML = "Application";44 tr.appendChild(th);45 var th = document.createElement('th');46 th.innerHTML = "Build";47 tr.appendChild(th);48 var th = document.createElement('th');49 th.innerHTML = "Revision";50 tr.appendChild(th);51 var th = document.createElement('th');52 th.innerHTML = "Status";53 tr.appendChild(th);54 var th = document.createElement('th');55 th.innerHTML = "Start";56 tr.appendChild(th);

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