Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execution summary report enhancements #1363

Merged
merged 5 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/com/shaft/listeners/JunitListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@
String caseName = testIdentifier.getDisplayName();
String caseDescription = testIdentifier.getLegacyReportingName();
String statusMessage = statusIcon.getValue() + status.name();
Boolean hasIssue = false;
ExecutionSummaryReport.casesDetailsIncrement(caseSuite, caseName, caseDescription, errorMessage, statusMessage, hasIssue);
// Will add empty strings o the tmsLink and issue params until we figure out how to get the values of the annotations using JUnit
ExecutionSummaryReport.casesDetailsIncrement("", caseSuite, caseName, caseDescription, errorMessage, statusMessage, "");

Check warning on line 137 in src/main/java/com/shaft/listeners/JunitListener.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/shaft/listeners/JunitListener.java#L137

Added line #L137 was not covered by tests
}

}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/shaft/listeners/TestNGListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,29 +214,29 @@
public void onTestSuccess(ITestResult result) {
// if (isTestNGRun()) {
passedTests.add(result.getMethod());
ExecutionSummaryReport.casesDetailsIncrement(result.getMethod().getQualifiedName().replace("." + result.getMethod().getMethodName(), ""),
ExecutionSummaryReport.casesDetailsIncrement(TestNGListenerHelper.getTmsLinkAnnotationValue(result), result.getMethod().getQualifiedName().replace("." + result.getMethod().getMethodName(), ""),
result.getMethod().getMethodName(), result.getMethod().getDescription(), "",
ExecutionSummaryReport.StatusIcon.PASSED.getValue() + ExecutionSummaryReport.Status.PASSED.name(), TestNGListenerHelper.testHasIssueAnnotation(result));
ExecutionSummaryReport.StatusIcon.PASSED.getValue() + ExecutionSummaryReport.Status.PASSED.name(), TestNGListenerHelper.getIssueAnnotationValue(result));
// }
}

@Override
public void onTestFailure(ITestResult result) {
// if (isTestNGRun()) {
failedTests.add(result.getMethod());
ExecutionSummaryReport.casesDetailsIncrement(result.getMethod().getQualifiedName().replace("." + result.getMethod().getMethodName(), ""),
ExecutionSummaryReport.casesDetailsIncrement(TestNGListenerHelper.getTmsLinkAnnotationValue(result), result.getMethod().getQualifiedName().replace("." + result.getMethod().getMethodName(), ""),

Check warning on line 227 in src/main/java/com/shaft/listeners/TestNGListener.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/shaft/listeners/TestNGListener.java#L227

Added line #L227 was not covered by tests
result.getMethod().getMethodName(), result.getMethod().getDescription(), result.getThrowable().getMessage(),
ExecutionSummaryReport.StatusIcon.FAILED.getValue() + ExecutionSummaryReport.Status.FAILED.name(), TestNGListenerHelper.testHasIssueAnnotation(result));
ExecutionSummaryReport.StatusIcon.FAILED.getValue() + ExecutionSummaryReport.Status.FAILED.name(), TestNGListenerHelper.getIssueAnnotationValue(result));

Check warning on line 229 in src/main/java/com/shaft/listeners/TestNGListener.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/shaft/listeners/TestNGListener.java#L229

Added line #L229 was not covered by tests
// }
}

@Override
public void onTestSkipped(ITestResult result) {
// if (isTestNGRun()) {
skippedTests.add(result.getMethod());
ExecutionSummaryReport.casesDetailsIncrement(result.getMethod().getQualifiedName().replace("." + result.getMethod().getMethodName(), ""),
ExecutionSummaryReport.casesDetailsIncrement(TestNGListenerHelper.getTmsLinkAnnotationValue(result), result.getMethod().getQualifiedName().replace("." + result.getMethod().getMethodName(), ""),

Check warning on line 237 in src/main/java/com/shaft/listeners/TestNGListener.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/shaft/listeners/TestNGListener.java#L237

Added line #L237 was not covered by tests
result.getMethod().getMethodName(), result.getMethod().getDescription(), result.getThrowable().getMessage(),
ExecutionSummaryReport.StatusIcon.SKIPPED.getValue() + ExecutionSummaryReport.Status.SKIPPED.name(), TestNGListenerHelper.testHasIssueAnnotation(result));
ExecutionSummaryReport.StatusIcon.SKIPPED.getValue() + ExecutionSummaryReport.Status.SKIPPED.name(), TestNGListenerHelper.getIssueAnnotationValue(result));

Check warning on line 239 in src/main/java/com/shaft/listeners/TestNGListener.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/shaft/listeners/TestNGListener.java#L239

Added line #L239 was not covered by tests
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.shaft.tools.io.internal.ReportManagerHelper;
import io.qameta.allure.Issue;
import io.qameta.allure.Issues;
import io.qameta.allure.TmsLink;
import io.qameta.allure.TmsLinks;
import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.Browser;
import org.testng.*;
Expand Down Expand Up @@ -259,10 +261,38 @@
}
}

public static Boolean testHasIssueAnnotation(ITestResult iTestResult) {
public static String getIssueAnnotationValue(ITestResult iTestResult) {
var method = iTestResult.getMethod().getConstructorOrMethod().getMethod();
Issue issue = method.getAnnotation(Issue.class);
return issue != null;
Issues issues = method.getAnnotation(Issues.class);
if (issues != null) {
return Arrays.toString(issues.value())
.replace("[@io.qameta.allure.Issue(\"", "")
.replace("@io.qameta.allure.Issue(\"", "")
.replace("\")]", "")
.replace("\"),", ",");
} else if (issue != null) {
return issue.value();
} else {
return "";
}
}

public static String getTmsLinkAnnotationValue(ITestResult iTestResult) {
var method = iTestResult.getMethod().getConstructorOrMethod().getMethod();
TmsLink tmsLink = method.getAnnotation(TmsLink.class);
TmsLinks tmsLinks = method.getAnnotation(TmsLinks.class);
if (tmsLinks != null) {
return Arrays.toString(tmsLinks.value())
.replace("[@io.qameta.allure.TmsLink(\"", "")
.replace("@io.qameta.allure.TmsLink(\"", "")
.replace("\")]", "")
.replace("\"),", ",");

Check warning on line 290 in src/main/java/com/shaft/listeners/internal/TestNGListenerHelper.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/shaft/listeners/internal/TestNGListenerHelper.java#L286-L290

Added lines #L286 - L290 were not covered by tests
} else if (tmsLink != null) {
return tmsLink.value();

Check warning on line 292 in src/main/java/com/shaft/listeners/internal/TestNGListenerHelper.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/shaft/listeners/internal/TestNGListenerHelper.java#L292

Added line #L292 was not covered by tests
} else {
return "";
}
}

public static void failFast(ITestResult iTestResult) {
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/com/shaft/tools/internal/support/HTMLHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,10 @@ public enum HTMLHelper {
.piechart1 {
display: block;
position: relative;
width: 120px;
height: 120px;
width: 100px;
height: 100px;
border-radius: 50%;
margin-top: 20px;
background-image: conic-gradient(
MediumSeaGreen ${VALIDATION_PASSED_PERCENTAGE_PIE}deg,
Tomato 0);
Expand Down Expand Up @@ -461,15 +462,18 @@ public enum HTMLHelper {
.table100.ver5 .ps__rail-y .ps__thumb-y::before{
background-color:#ccc
}
.column0{
width:5%;
padding-left:20px
}
.column1{
width:5%;
padding-left:40px
}
.column2{
width:20%
}
.column3{
width:35%
width:30%
}
.column4{
width:25%
Expand All @@ -478,7 +482,7 @@ public enum HTMLHelper {
width:10%
}
.column6{
width:5%
width:10%
}
hr.rounded {
border-top: 8px solid #bbb;
Expand Down Expand Up @@ -529,10 +533,8 @@ public enum HTMLHelper {
<font style="color:MediumSeaGreen;"><b>Passed:</b>&nbsp${VALIDATION_PASSED}</font>&nbsp|
<font style="color:Tomato;"><b>Failed:</b>&nbsp${VALIDATION_FAILED}</font>&nbsp]
</h4>
<br>
<div class="piechart1"></div>
<br>
<h4>${VALIDATION_PASSED_PERCENTAGE}% Passed</h4>
<h5 style="padding-top: 5px;">${VALIDATION_PASSED_PERCENTAGE}% Passed</h5>
<hr class="rounded1">
<h5><b title="&#9432; Issues are problems that may relate to the tests and should be investigated further to open or close bugs; Issues are divided between the three following categories. (directly related to the @Issue annotation)">&#9432; </b><b>Total Issues</b>:&nbsp${TOTAL_ISSUES}&nbsp&nbsp[
<font style="color:Tomato;"><b title="&#9432; Defining the Failed tests that are not linked to bugs. (need to investigate and if needed, open new bugs and link them to the related tests using the @Issue annotation)">&#9432; </b><b>Tests that should Pass:</b>&nbsp${NO_OPEN_ISSUES_FAILED}</font>&nbsp|
Expand Down Expand Up @@ -561,12 +563,13 @@ public enum HTMLHelper {
<table>
<thead>
<tr class="row100 head">
<th class="cell100 column0"></th>
<th class="cell100 column1">Id</th>
<th class="cell100 column2">Suite</th>
<th class="cell100 column3">Name</th>
<th class="cell100 column4">Error</th>
<th class="cell100 column5">Status</th>
<th class="cell100 column6">Has issue</th>
<th class="cell100 column6">issue id</th>
</tr>
</thead>
<tbody id="table">${CASES_DETAILS}</tbody>
Expand Down Expand Up @@ -602,7 +605,7 @@ public enum HTMLHelper {
</body>
</html>
"""),
EXECUTION_SUMMARY_DETAILS_FORMAT("<tr class=\"row100 body\"><td class=\"cell100 column1\">%d</td><td class=\"cell100 column2\">%s</td><td class=\"cell100 column3\">%s</td><td class=\"cell100 column4\">%s</td><td class=\"cell100 column5\">%s</td><td class=\"cell100 column6\">%s</td></tr>");
EXECUTION_SUMMARY_DETAILS_FORMAT("<tr class=\"row100 body\"><td class=\"cell100 column0\">%d</td><td class=\"cell100 column1\">%s</td><td class=\"cell100 column2\">%s</td><td class=\"cell100 column3\">%s</td><td class=\"cell100 column4\">%s</td><td class=\"cell100 column5\">%s</td><td class=\"cell100 column6\">%s</td></tr>");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ public class ExecutionSummaryReport {
private static int failedValidations = 0;
private static final String SHAFT_LOGO_URL = "https://github.com/ShaftHQ/SHAFT_ENGINE/raw/main/src/main/resources/images/shaft.png";

public static void casesDetailsIncrement(String caseSuite, String caseName, String caseDescription,String errorMessage, String status, Boolean hasIssue) {
public static void casesDetailsIncrement(String tmsLink, String caseSuite, String caseName, String caseDescription,String errorMessage, String status, String issue) {
ArrayList<String> entry = new ArrayList<>();
entry.add(tmsLink);
entry.add(caseSuite);
if (caseDescription != null && !caseDescription.isEmpty()) {
entry.add(caseDescription);
Expand All @@ -26,11 +27,7 @@ public static void casesDetailsIncrement(String caseSuite, String caseName, Stri
}
entry.add(errorMessage);
entry.add(status);
if (hasIssue) {
entry.add("Yes");
} else {
entry.add("No");
}
entry.add(issue);
casesDetails.put(casesDetails.size() + 1, entry);
}

Expand All @@ -49,7 +46,7 @@ public static void generateExecutionSummaryReport(int passed, int failed, int sk
int total = passed + failed + skipped;

StringBuilder detailsBuilder = new StringBuilder();
casesDetails.forEach((key, value) -> detailsBuilder.append(String.format(HTMLHelper.EXECUTION_SUMMARY_DETAILS_FORMAT.getValue(), key, value.get(0), value.get(1), value.get(2), value.get(3), value.get(4))));
casesDetails.forEach((key, value) -> detailsBuilder.append(String.format(HTMLHelper.EXECUTION_SUMMARY_DETAILS_FORMAT.getValue(), key, value.get(0), value.get(1), value.get(2), value.get(3), value.get(4), value.get(5))));

SHAFT.CLI.file().writeToFile(SHAFT.Properties.paths.executionSummaryReport(),
"ExecutionSummaryReport_" + new SimpleDateFormat("dd-MM-yyyy_HH-mm-ss-SSSS-aaa").format(System.currentTimeMillis()) + ".html",
Expand Down
Loading