diff --git a/src/com/soapuiextentter/reporter/Report.java b/src/com/soapuiextentter/reporter/Report.java index dd23932..e44d53d 100644 --- a/src/com/soapuiextentter/reporter/Report.java +++ b/src/com/soapuiextentter/reporter/Report.java @@ -19,6 +19,7 @@ import com.eviware.soapui.SoapUI; import com.eviware.soapui.model.testsuite.TestProperty; import com.eviware.soapui.model.testsuite.TestStepResult; +import com.soapuiextentter.utilities.StringUtils; /* * Author : Akshay Sharma @@ -79,12 +80,12 @@ public Report(String reportPath, String reportName, HashMap klov } } - public static String getReportName(String reportName) { + private static String getReportName(String reportName) { String fileName = "AutomationReport_" + reportName + "_" + java.time.LocalDate.now() + ".html"; return fileName; } - public void assignCategory(String testSuiteId, String categoryName) { + private void assignCategory(String testSuiteId, String categoryName) { try { getTest(testSuiteId).assignCategory(categoryName); } catch (Exception e) { @@ -93,7 +94,7 @@ public void assignCategory(String testSuiteId, String categoryName) { } } - public void assignAuthor(String testSuiteId, String authorName) { + private void assignAuthor(String testSuiteId, String authorName) { try { getTest(testSuiteId).assignAuthor(authorName); } catch (Exception e) { @@ -209,9 +210,10 @@ public void logPass(TestStepResult testStepContext, String testSuiteId, String t if (GroovyScript == null) { actualReq = Request.getValue(); actualRes = Response.getValue(); - Markup mReqRes = MarkupHelper.createCodeBlock(actualReq, actualRes); + Markup mReqRes = MarkupHelper.createCodeBlock(formatXmlOrJson(actualReq), + formatXmlOrJson(actualRes)); endPoint = testStepContext.getTestStep().getProperty("Endpoint").getValue(); - + if (AuthType == null) { assignCategory(testSuiteId, "REST"); } else { @@ -257,7 +259,7 @@ public void logPass(TestStepResult testStepContext, String testSuiteId, String t ResponseAsXML = testStepContext.getTestStep().getProperty("ResponseAsXml"); getTestNode(testSuiteId, testCaseId).pass(logText + " - JDBC Response as below"); actualRespAsXml = ResponseAsXML.getValue(); - Markup mSqlResponse = MarkupHelper.createCodeBlock(actualRespAsXml); + Markup mSqlResponse = MarkupHelper.createCodeBlock(formatXmlOrJson(actualRespAsXml)); getTestNode(testSuiteId, testCaseId).info(mSqlResponse); assignCategory(testSuiteId, "JDBC"); } else { @@ -318,7 +320,8 @@ public void logFail(TestStepResult testStepContext, String testSuiteId, String t if (GroovyScript == null) { actualReq = Request.getValue(); actualRes = Response.getValue(); - Markup mReqRes = MarkupHelper.createCodeBlock(actualReq, actualRes); + Markup mReqRes = MarkupHelper.createCodeBlock(formatXmlOrJson(actualReq), + formatXmlOrJson(actualRes)); endPoint = testStepContext.getTestStep().getProperty("Endpoint").getValue(); if (AuthType == null) { @@ -497,4 +500,14 @@ private String getEndpointRef(String endPoint) { } return actualEndRef; } + + private String formatXmlOrJson(String unformattedStr) { + String formattedXMl = unformattedStr; + if (unformattedStr.startsWith("[") || unformattedStr.startsWith("{")) { + formattedXMl = StringUtils.prettyPrintJson(unformattedStr); + } else if (unformattedStr.startsWith("<")) { + formattedXMl = StringUtils.prettyPrintXML(unformattedStr); + } + return formattedXMl; + } } \ No newline at end of file diff --git a/src/com/soapuiextentter/utilities/StringUtils.java b/src/com/soapuiextentter/utilities/StringUtils.java new file mode 100644 index 0000000..6c9ed86 --- /dev/null +++ b/src/com/soapuiextentter/utilities/StringUtils.java @@ -0,0 +1,41 @@ +package com.soapuiextentter.utilities; + +import javax.xml.parsers.DocumentBuilderFactory; + +import org.json.JSONObject; +import org.w3c.dom.bootstrap.DOMImplementationRegistry; +import org.w3c.dom.ls.DOMImplementationLS; +import org.w3c.dom.ls.LSSerializer; +import org.xml.sax.InputSource; + +public class StringUtils { + + public static String prettyPrintXML(String xmlString) { + String preetyXML = xmlString; + try { + InputSource src = new InputSource(new String(xmlString)); + org.w3c.dom.Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src) + .getDocumentElement(); + Boolean keepDeclaration = Boolean.valueOf(xmlString.startsWith("