From df14332082600ee4d0f87a9dfacc4e254e975052 Mon Sep 17 00:00:00 2001 From: Jayesh Kharode Date: Mon, 30 Sep 2024 11:22:25 +0530 Subject: [PATCH 1/4] MOSIP-36166 Signed-off-by: Jayesh Kharode --- uitest-admin/Dockerfile | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/uitest-admin/Dockerfile b/uitest-admin/Dockerfile index 4651387e..5475b9d4 100644 --- a/uitest-admin/Dockerfile +++ b/uitest-admin/Dockerfile @@ -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 @@ -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"] From 2ba5e2648b5cdfe2c879079944094650941ad0f6 Mon Sep 17 00:00:00 2001 From: Jayesh Kharode Date: Mon, 30 Sep 2024 12:40:16 +0530 Subject: [PATCH 2/4] MOSIP-36031 Signed-off-by: Jayesh Kharode --- uitest-admin/entrypoint.sh | 2 +- uitest-admin/pom.xml | 12 +- .../adminui/utility/EmailableReport.java | 133 +++++++++++------- .../testrig/adminui/utility/TestRunner.java | 2 +- 4 files changed, 92 insertions(+), 57 deletions(-) diff --git a/uitest-admin/entrypoint.sh b/uitest-admin/entrypoint.sh index d9c22cdc..cd298f2c 100644 --- a/uitest-admin/entrypoint.sh +++ b/uitest-admin/entrypoint.sh @@ -1,4 +1,4 @@ #!/bin/bash java --version -java -jar adminui-*-jar-with-dependencies.jar \ No newline at end of file +java -jar uitest-admin-*-jar-with-dependencies.jar \ No newline at end of file diff --git a/uitest-admin/pom.xml b/uitest-admin/pom.xml index 0923ff45..846706e2 100644 --- a/uitest-admin/pom.xml +++ b/uitest-admin/pom.xml @@ -41,7 +41,7 @@ 3.0.7 6.11 1.13 - adminui-1.2.1-SNAPSHOT-jar-with-dependencies + uitest-admin-1.2.1-SNAPSHOT-jar-with-dependencies 21 @@ -199,6 +199,16 @@ javax.validation validation-api + + com.github.jknack + handlebars + 3.0.0 + + + com.github.mifmif + generex + 1.0.2 + diff --git a/uitest-admin/src/main/java/io/mosip/testrig/adminui/utility/EmailableReport.java b/uitest-admin/src/main/java/io/mosip/testrig/adminui/utility/EmailableReport.java index 6f52df0b..ff185b2c 100644 --- a/uitest-admin/src/main/java/io/mosip/testrig/adminui/utility/EmailableReport.java +++ b/uitest-admin/src/main/java/io/mosip/testrig/adminui/utility/EmailableReport.java @@ -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; @@ -34,6 +39,7 @@ + /** * Reporter that generates a single-page HTML report of the test results. */ @@ -55,7 +61,7 @@ public class EmailableReport implements IReporter { int totalSkippedTests = 0; int totalFailedTests = 0; - + public void setFileName(String fileName) { this.fileName = fileName; @@ -91,7 +97,7 @@ public void generateReport(List xmlSuites, List 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); @@ -114,9 +120,9 @@ public void generateReport(List xmlSuites, List suites, String /* Need to figure how to handle EXTENT report handling */ - - + + } catch (Exception e) { logger.error("error occured while pushing the object" + e.getMessage()); @@ -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 ""; } @@ -178,24 +180,31 @@ protected void writeHead() { protected void writeStylesheet() { writer.print(""); + 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(""); } protected void writeBody() { @@ -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; @@ -223,16 +246,18 @@ protected void writeSuiteSummary() { for (SuiteResult suiteResult : suiteResults) { writer.print(""); - writer.print(Utils.escapeHtml(suiteResult.getSuiteName() + "-" + getCommitId())); - writer.print(""); + writer.print(Utils.escapeHtml(suiteResult.getSuiteName() + " ---- " + "Report Date: " + formattedDate + + " ---- " + "Tested Environment: " + + ConfigManager.getiam_apienvuser().replaceAll(".*?\\.([^\\.]+)\\..*", "$1") + " ---- " + + getCommitId())); writer.print(""); writer.print("
");
 			writer.print(Utils.escapeHtml("Server Component Details " + AdminTestUtil.getServerComponentsDetails()));
 			writer.print("
"); -// writer.print(GlobalConstants.TRTR); + writer.print(""); writer.print(""); -// writer.print("Test Suite"); + // writer.print("Test Suite"); writer.print("# Passed"); writer.print("# Skipped"); writer.print("# Failed"); @@ -254,8 +279,8 @@ protected void writeSuiteSummary() { writer.print(">"); buffer.setLength(0); -// writeTableData(buffer.append("") -// .append(Utils.escapeHtml(testResult.getTestName())).append("").toString()); + // writeTableData(buffer.append("") + // .append(Utils.escapeHtml(testResult.getTestName())).append("").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")); @@ -360,7 +385,7 @@ private int writeScenarioSummary(String description, List classResu buffer.setLength(0); int scenariosPerClass = 0; int methodIndex = 0; - + for (MethodResult methodResult : classResult.getMethodResults()) { List results = methodResult.getResults(); int resultsCount = results.size(); @@ -370,23 +395,23 @@ private int writeScenarioSummary(String description, List 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("").append("").append(scenarioName).append("") -// .append("").append(scenarioDescription).append("") -// .append("").append(scenarioDuration).append(""); + // buffer.append("").append("").append(scenarioName).append("") + // .append("").append(scenarioDescription).append("") + // .append("").append(scenarioDuration).append(""); buffer.append("") // Start of table row with a specified CSS class - .append("").append(methodName).append("") // Table cell with a hyperlink - .append("").append(scenarioDuration).append(""); // Table cell with scenario duration + .append("").append(methodName).append("") // Table cell with a hyperlink + .append("").append(scenarioDuration).append(""); // Table cell with scenario duration scenarioIndex++; } @@ -403,7 +428,7 @@ private int writeScenarioSummary(String description, List classResu return scenarioCount; } - + /** * Writes the details for all test scenarios. @@ -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); } } } @@ -438,8 +463,8 @@ private int writeScenarioDetails(List classResults, int startingSce for (MethodResult methodResult : classResult.getMethodResults()) { List 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) { @@ -459,7 +484,7 @@ private void writeScenario(int scenarioIndex, String label, ITestResult result) writer.print("

"); - writer.print(label); + writer.print(label); writer.print("

"); writer.print(""); diff --git a/uitest-admin/src/main/java/io/mosip/testrig/adminui/utility/TestRunner.java b/uitest-admin/src/main/java/io/mosip/testrig/adminui/utility/TestRunner.java index 7955993b..97bba12a 100644 --- a/uitest-admin/src/main/java/io/mosip/testrig/adminui/utility/TestRunner.java +++ b/uitest-admin/src/main/java/io/mosip/testrig/adminui/utility/TestRunner.java @@ -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"); From caf425cc261f649100bd0ddfa93d8b10a1bb7def Mon Sep 17 00:00:00 2001 From: jayesh12234 <111957576+jayesh12234@users.noreply.github.com> Date: Tue, 8 Oct 2024 15:29:26 +0530 Subject: [PATCH 3/4] Update entrypoint.sh Signed-off-by: jayesh12234 <111957576+jayesh12234@users.noreply.github.com> --- uitest-admin/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uitest-admin/entrypoint.sh b/uitest-admin/entrypoint.sh index cd298f2c..c829f358 100644 --- a/uitest-admin/entrypoint.sh +++ b/uitest-admin/entrypoint.sh @@ -1,4 +1,4 @@ #!/bin/bash java --version -java -jar uitest-admin-*-jar-with-dependencies.jar \ No newline at end of file +java -jar adminui-*-jar-with-dependencies.jar From bcc324016051270a33b89233db57f709cbe118ed Mon Sep 17 00:00:00 2001 From: jayesh12234 <111957576+jayesh12234@users.noreply.github.com> Date: Tue, 8 Oct 2024 15:30:46 +0530 Subject: [PATCH 4/4] Update entrypoint.sh Signed-off-by: jayesh12234 <111957576+jayesh12234@users.noreply.github.com> --- uitest-admin/entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/uitest-admin/entrypoint.sh b/uitest-admin/entrypoint.sh index c829f358..65a0e948 100644 --- a/uitest-admin/entrypoint.sh +++ b/uitest-admin/entrypoint.sh @@ -2,3 +2,4 @@ java --version java -jar adminui-*-jar-with-dependencies.jar +