Skip to content

Commit

Permalink
Merge pull request #21 from iamakshayshar/feature/version-5.1
Browse files Browse the repository at this point in the history
Feature/version 5.1
  • Loading branch information
iamakshayshar authored Oct 30, 2023
2 parents a6ac456 + 2fc67ed commit 00d5dc4
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 17 deletions.
21 changes: 12 additions & 9 deletions Listener-XML/soapuiextentter-listeners.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<tns:soapui-listeners xmlns:tns="http://eviware.com/soapui/config">
<!--This will initialize TestStep level reporting-->
<tns:listener id="TestStepListener" listenerClass="com.soapuiextentter.listener.ExtenterTestRunListener"
listenerInterface="com.eviware.soapui.model.testsuite.TestRunListener" />
<!--This will initialize TestCase level reporting-->
<tns:listener id="TestCaseListener" listenerClass="com.soapuiextentter.listener.ExtenterTestSuiteRunListener"
listenerInterface="com.eviware.soapui.model.testsuite.TestSuiteRunListener" />
<!--This will initialize TestSuite level reporting-->
<tns:listener id="TestSuiteListener" listenerClass="com.soapuiextentter.listener.ExtenterProjectRunListener"
listenerInterface="com.eviware.soapui.model.testsuite.ProjectRunListener" />
<!--This will initialize TestStep level reporting-->
<tns:listener id="TestStepListener"
listenerClass="com.soapuiextentter.listener.ExtenterTestRunListener"
listenerInterface="com.eviware.soapui.model.testsuite.TestRunListener" />
<!--This will initialize TestCase level reporting-->
<tns:listener id="TestCaseListener"
listenerClass="com.soapuiextentter.listener.ExtenterTestSuiteRunListener"
listenerInterface="com.eviware.soapui.model.testsuite.TestSuiteRunListener" />
<!--This will initialize TestSuite level reporting-->
<tns:listener id="TestSuiteListener"
listenerClass="com.soapuiextentter.listener.ExtenterProjectRunListener"
listenerInterface="com.eviware.soapui.model.testsuite.ProjectRunListener" />
</tns:soapui-listeners>
30 changes: 22 additions & 8 deletions src/com/soapuiextentter/reporter/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,7 +30,6 @@
public class Report {

private ExtentReports reports;
private Object object;
private static Map extentNodeMap;
private static Map extentTestMap;
private String finalReportPath;
Expand Down Expand Up @@ -79,12 +79,12 @@ public Report(String reportPath, String reportName, HashMap<String, String> 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) {
Expand All @@ -93,7 +93,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) {
Expand Down Expand Up @@ -209,9 +209,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 {
Expand Down Expand Up @@ -257,7 +258,7 @@ public void logPass(TestStepResult testStepContext, String testSuiteId, String t
ResponseAsXML = testStepContext.getTestStep().getProperty("ResponseAsXml");
getTestNode(testSuiteId, testCaseId).pass(logText + " <b>- JDBC Response as below</b>");
actualRespAsXml = ResponseAsXML.getValue();
Markup mSqlResponse = MarkupHelper.createCodeBlock(actualRespAsXml);
Markup mSqlResponse = MarkupHelper.createCodeBlock(formatXmlOrJson(actualRespAsXml));
getTestNode(testSuiteId, testCaseId).info(mSqlResponse);
assignCategory(testSuiteId, "JDBC");
} else {
Expand Down Expand Up @@ -318,7 +319,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) {
Expand Down Expand Up @@ -445,6 +447,8 @@ private boolean envLogCheck(List<TestProperty> properties) {
"Invalid value specified for 'AddDataToReport' in project properties. Please check and correct.");
return propValue;
}
} else {
propValue = true;
}
}
}
Expand Down Expand Up @@ -497,4 +501,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;
}
}
41 changes: 41 additions & 0 deletions src/com/soapuiextentter/utilities/StringUtils.java
Original file line number Diff line number Diff line change
@@ -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("<?xml"));
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
LSSerializer writer = impl.createLSSerializer();
writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
writer.getDomConfig().setParameter("xml-declaration", keepDeclaration);
preetyXML = writer.writeToString(document);
} catch (Exception e) {
return preetyXML;
}
return preetyXML;
}

public static String prettyPrintJson(String jsonString) {
String preetyJson = jsonString;
try {
preetyJson = (new JSONObject(jsonString)).toString(4);
} catch (Exception e) {
return preetyJson;
}
return preetyJson;
}
}

0 comments on commit 00d5dc4

Please sign in to comment.