Skip to content

Commit

Permalink
Merge pull request #335 from jayesh12234/release-1.3.x
Browse files Browse the repository at this point in the history
MOSIP-36399
  • Loading branch information
aranaravi authored Oct 8, 2024
2 parents e9a95cc + bcc3240 commit 6e614e8
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 69 deletions.
29 changes: 16 additions & 13 deletions uitest-admin/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
FROM selenium/standalone-chrome:127.0.6533.119
# Start with a base image that includes Java 21
FROM openjdk:21-slim

# Install additional dependencies, such as Selenium, Chrome, and kubectl
USER root

# Define build-time arguments
RUN apt-get update && \
apt-get install -y wget curl unzip xvfb libxi6 libgconf-2-4 chromium chromium-driver

# Install kubectl
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \
chmod +x kubectl && \
mv kubectl /usr/local/bin/kubectl

# Define build-time arguments and labels
ARG SOURCE
ARG COMMIT_HASH
ARG COMMIT_ID
Expand All @@ -23,28 +33,21 @@ ARG container_user_gid=1001
# Set working directory for the user
ENV work_dir=/home/${container_user}/

ARG KUBECTL_VERSION=1.22.9

# install packages and create user
# Create a new user with specified permissions
RUN groupadd -g ${container_user_gid} ${container_user_group} \
&& useradd -u ${container_user_uid} -g ${container_user_group} -s /bin/bash -m ${container_user} -d ${work_dir} \
&& chown -R ${container_user}:${container_user} /home/${container_user} \
&& curl -LO "https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL_VERSION}/bin/linux/amd64/kubectl" \
&& chmod +x kubectl \
&& mv kubectl /usr/local/bin/
&& chown -R ${container_user}:${container_user} /home/${container_user}/

# Switch to the specified user for the subsequent commands
USER ${container_user_uid}:${container_user_gid}

# Copy files
# Copy your application files into the container
COPY --chown=${container_user_uid}:${container_user} --chmod=771 ./entrypoint.sh ${work_dir}/entrypoint.sh
COPY --chown=${container_user}:${container_user} ./src/main/resources/ ${work_dir}/resources/
COPY --chown=${container_user_uid}:${container_user} ./target/*.jar ${work_dir}

# Set working directory
# Set the working directory
WORKDIR /home/${container_user}/



# Entrypoint for the container
ENTRYPOINT ["/bin/bash", "-c", "./entrypoint.sh"]
3 changes: 2 additions & 1 deletion uitest-admin/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash

java --version
java -jar adminui-*-jar-with-dependencies.jar
java -jar adminui-*-jar-with-dependencies.jar

10 changes: 10 additions & 0 deletions uitest-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>com.github.jknack</groupId>
<artifactId>handlebars</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.github.mifmif</groupId>
<artifactId>generex</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.text.NumberFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.testng.IReporter;
import org.testng.ISuite;
Expand All @@ -34,6 +39,7 @@




/**
* Reporter that generates a single-page HTML report of the test results.
*/
Expand All @@ -55,7 +61,7 @@ public class EmailableReport implements IReporter {
int totalSkippedTests = 0;
int totalFailedTests = 0;



public void setFileName(String fileName) {
this.fileName = fileName;
Expand Down Expand Up @@ -91,7 +97,7 @@ public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String
File orignialReportFile = new File(System.getProperty("user.dir") + "/"
+ System.getProperty("testng.outpur.dir") + "/" + System.getProperty("emailable.report2.name"));
logger.info("reportFile is::" + System.getProperty("user.dir") + "/" + System.getProperty("testng.outpur.dir")
+ "/" + System.getProperty("emailable.report2.name"));
+ "/" + System.getProperty("emailable.report2.name"));

File newReportFile = new File(
System.getProperty("user.dir") + "/" + System.getProperty("testng.outpur.dir") + "/" + newString);
Expand All @@ -114,9 +120,9 @@ public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String

/* Need to figure how to handle EXTENT report handling */







} catch (Exception e) {
logger.error("error occured while pushing the object" + e.getMessage());
Expand All @@ -139,16 +145,12 @@ private String getCommitId() {
Properties properties = new Properties();
try (InputStream is = EmailableReport.class.getClassLoader().getResourceAsStream("git.properties")) {
properties.load(is);
Process process = Runtime.getRuntime().exec("git rev-parse --abbrev-ref HEAD");

// Read the output of the command
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String branch = reader.readLine();
return "Commit Id is: " + properties.getProperty("git.commit.id.abbrev") + " & Branch Name is:"
+ branch;
+ properties.getProperty("git.branch");

} catch (IOException io) {
logger.error(io.getMessage());
} catch (IOException e) {
logger.error(e.getMessage());
return "";
}

Expand Down Expand Up @@ -178,24 +180,31 @@ protected void writeHead() {

protected void writeStylesheet() {
writer.print("<style type=\"text/css\">");
writer.print("table {margin-bottom:10px;border-collapse:collapse;empty-cells:show}");
writer.print("th,td {border:1px solid #009;padding:.25em .5em}");
writer.print("th {vertical-align:bottom}");
writer.print("td {vertical-align:top}");
writer.print("table a {font-weight:bold}");
writer.print(".stripe td {background-color: #E6EBF9}");
writer.print(".num {text-align:center}");
writer.print(".passedodd td {background-color: #3F3}");
writer.print(".passedeven td {background-color: #0A0}");
writer.print(".skippedodd td {background-color: #FFA500}");
writer.print(".skippedeven td {background-color: #FFA500}");
writer.print(".failedodd td,.attn {background-color: #F33}");
writer.print(".failedeven td,.stripe .attn {background-color: #D00}");
writer.print(".stacktrace {white-space:pre;font-family:monospace}");
writer.print(".totop {font-size:85%;text-align:center;border-bottom:2px solid #000}");
writer.print(".orange-bg {background-color: #FFA500}");
writer.print(".green-bg {background-color: #0A0}");
writer.print("</style>");
writer.print("table {margin-bottom:10px;border-collapse:collapse;empty-cells:show;width: 100%;}");
writer.print("th,td {border:1px solid #009;padding:.25em .5em;width: 25%;}"); // Set a fixed width for uniform cell sizes
writer.print("th {vertical-align:bottom}");
writer.print("td {vertical-align:top}");
writer.print("table a {font-weight:bold}");
writer.print(".stripe td {background-color: #E6EBF9}");
writer.print(".num {text-align:center}");
writer.print(".orange-bg {background-color: #FFA500}");
writer.print(".grey-bg {background-color: #808080}");
writer.print(".thich-orange-bg {background-color: #CC5500}");
writer.print(".green-bg {background-color: #0A0}");
writer.print(".attn {background-color: #D00}");
writer.print(".passedodd td {background-color: #3F3}");
writer.print(".passedeven td {background-color: #0A0}");
writer.print(".skippedodd td {background-color: #FFA500}");
writer.print(".skippedeven td,.stripe {background-color: #FFA500}");
writer.print(".failedodd td {background-color: #F33}");
writer.print(".failedeven td,.stripe {background-color: #D00}");
writer.print(".ignoredodd td {background-color: #808080}");
writer.print(".ignoredeven td {background-color: #808080}");
writer.print(".known_issuesodd td {background-color: #CC5500}");
writer.print(".known_issueseven td {background-color: #CC5500}");
writer.print(".stacktrace {white-space:pre;font-family:monospace}");
writer.print(".totop {font-size:85%;text-align:center;border-bottom:2px solid #000}");
writer.print("</style>");
}

protected void writeBody() {
Expand All @@ -213,7 +222,21 @@ protected void writeDocumentEnd() {
protected void writeSuiteSummary() {
NumberFormat integerFormat = NumberFormat.getIntegerInstance();
NumberFormat decimalFormat = NumberFormat.getNumberInstance();

String formattedDate =null;
LocalDate currentDate = LocalDate.now();
String branch = null;

try {

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
formattedDate = currentDate.format(formatter);
Process process = Runtime.getRuntime().exec("git rev-parse --abbrev-ref HEAD");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
branch = reader.readLine();
}
catch (Exception e) {
// TODO: handle exception
}
totalPassedTests = 0;
totalSkippedTests = 0;
totalFailedTests = 0;
Expand All @@ -223,16 +246,18 @@ protected void writeSuiteSummary() {
for (SuiteResult suiteResult : suiteResults) {

writer.print("<tr><th colspan=\"7\">");
writer.print(Utils.escapeHtml(suiteResult.getSuiteName() + "-" + getCommitId()));
writer.print("</th></tr>");
writer.print(Utils.escapeHtml(suiteResult.getSuiteName() + " ---- " + "Report Date: " + formattedDate
+ " ---- " + "Tested Environment: "
+ ConfigManager.getiam_apienvuser().replaceAll(".*?\\.([^\\.]+)\\..*", "$1") + " ---- "
+ getCommitId())); writer.print("</th></tr>");

writer.print("<tr><th colspan=\"7\"><span class=\"not-bold\"><pre>");
writer.print(Utils.escapeHtml("Server Component Details " + AdminTestUtil.getServerComponentsDetails()));
writer.print("</pre></span>");
// writer.print(GlobalConstants.TRTR);
writer.print("</th></tr>");

writer.print("<tr>");
// writer.print("<th>Test Suite</th>");
// writer.print("<th>Test Suite</th>");
writer.print("<th># Passed</th>");
writer.print("<th># Skipped</th>");
writer.print("<th># Failed</th>");
Expand All @@ -254,8 +279,8 @@ protected void writeSuiteSummary() {
writer.print(">");

buffer.setLength(0);
// writeTableData(buffer.append("<a href=\"#t").append(testIndex).append("\">")
// .append(Utils.escapeHtml(testResult.getTestName())).append("</a>").toString());
// writeTableData(buffer.append("<a href=\"#t").append(testIndex).append("\">")
// .append(Utils.escapeHtml(testResult.getTestName())).append("</a>").toString());
writeTableData(integerFormat.format(passedTests), (passedTests > 0 ? "num green-bg" : "num"));
writeTableData(integerFormat.format(skippedTests), (skippedTests > 0 ? "num orange-bg" : "num"));
writeTableData(integerFormat.format(failedTests), (failedTests > 0 ? "num attn" : "num"));
Expand Down Expand Up @@ -360,7 +385,7 @@ private int writeScenarioSummary(String description, List<ClassResult> classResu
buffer.setLength(0);
int scenariosPerClass = 0;
int methodIndex = 0;

for (MethodResult methodResult : classResult.getMethodResults()) {
List<ITestResult> results = methodResult.getResults();
int resultsCount = results.size();
Expand All @@ -370,23 +395,23 @@ private int writeScenarioSummary(String description, List<ClassResult> classResu
// Write the remaining scenarios for the method

for (int i = 0; i < resultsCount; i++) {

ITestResult result = results.get(i);
// String [] scenarioDetails = getScenarioDetails(result);
// String scenarioName = Utils.escapeHtml("Scenario_" + scenarioDetails[0]);
// String scenarioDescription = Utils.escapeHtml(scenarioDetails[1]);
// String [] scenarioDetails = getScenarioDetails(result);

// String scenarioName = Utils.escapeHtml("Scenario_" + scenarioDetails[0]);
// String scenarioDescription = Utils.escapeHtml(scenarioDetails[1]);

long scenarioStart = result.getStartMillis();
long scenarioDuration = result.getEndMillis() - scenarioStart;

// buffer.append("<tr class=\"").append(cssClass).append("\">").append("<td><a href=\"#m")
// .append(scenarioIndex).append("\">").append(scenarioName).append("</a></td>")
// .append("<td>").append(scenarioDescription).append("</td>")
// .append("<td>").append(scenarioDuration).append("</td></tr>");
// buffer.append("<tr class=\"").append(cssClass).append("\">").append("<td><a href=\"#m")
// .append(scenarioIndex).append("\">").append(scenarioName).append("</a></td>")
// .append("<td>").append(scenarioDescription).append("</td>")
// .append("<td>").append(scenarioDuration).append("</td></tr>");
buffer.append("<tr class=\"").append(cssClass).append("\">") // Start of table row with a specified CSS class
.append("<td><a href=\"#m").append(scenarioIndex).append("\">").append(methodName).append("</a></td>") // Table cell with a hyperlink
.append("<td>").append(scenarioDuration).append("</td></tr>"); // Table cell with scenario duration
.append("<td><a href=\"#m").append(scenarioIndex).append("\">").append(methodName).append("</a></td>") // Table cell with a hyperlink
.append("<td>").append(scenarioDuration).append("</td></tr>"); // Table cell with scenario duration

scenarioIndex++;
}
Expand All @@ -403,7 +428,7 @@ private int writeScenarioSummary(String description, List<ClassResult> classResu
return scenarioCount;
}



/**
* Writes the details for all test scenarios.
Expand All @@ -422,7 +447,7 @@ protected void writeScenarioDetails() {
scenarioIndex += writeScenarioDetails(testResult.getFailedTestResults(), scenarioIndex);
scenarioIndex += writeScenarioDetails(testResult.getSkippedConfigurationResults(), scenarioIndex);
scenarioIndex += writeScenarioDetails(testResult.getSkippedTestResults(), scenarioIndex);
// scenarioIndex += writeScenarioDetails(testResult.getPassedTestResults(), scenarioIndex);
// scenarioIndex += writeScenarioDetails(testResult.getPassedTestResults(), scenarioIndex);
}
}
}
Expand All @@ -438,8 +463,8 @@ private int writeScenarioDetails(List<ClassResult> classResults, int startingSce
for (MethodResult methodResult : classResult.getMethodResults()) {
List<ITestResult> results = methodResult.getResults();
assert !results.isEmpty();
// ITestResult firstResult = results.iterator().next();
// String methodName=firstResult.getName();
// ITestResult firstResult = results.iterator().next();
// String methodName=firstResult.getName();
String label = Utils
.escapeHtml(className + "#" + results.iterator().next().getMethod().getMethodName());
for (ITestResult result : results) {
Expand All @@ -459,7 +484,7 @@ private void writeScenario(int scenarioIndex, String label, ITestResult result)
writer.print("<h3 id=\"m");
writer.print(scenarioIndex);
writer.print("\">");
writer.print(label);
writer.print(label);
writer.print("</h3>");

writer.print("<table class=\"result\">");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void startTestRunner() throws Exception {
TestNG runner = new TestNG();
if(!ConfigManager.gettestcases().equals("")) {
XmlSuite suite = new XmlSuite();
suite.setName("MySuite");
suite.setName("ADMIN-UI-AUTOMATION");
suite.addListener("io.mosip.testrig.adminui.utility.EmailableReport");
XmlClass blocklistedwordsCRUD = new XmlClass("io.mosip.testrig.adminui.testcase.BlockListTest");
XmlClass bulkUploadCRUD = new XmlClass("io.mosip.testrig.adminui.testcase.BulkUploadTest");
Expand Down

0 comments on commit 6e614e8

Please sign in to comment.