diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/testrunner/MosipTestRunner.java b/api-test/src/main/java/io/mosip/testrig/apirig/testrunner/MosipTestRunner.java index 00fac30f4f..7b3f38482a 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/testrunner/MosipTestRunner.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/testrunner/MosipTestRunner.java @@ -10,6 +10,7 @@ import java.security.PublicKey; import java.security.interfaces.RSAPublicKey; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Properties; @@ -185,27 +186,43 @@ public static void startTestRunner() { homeDir = new File(dir.getParent() + "/mosip/testNgXmlFiles"); LOGGER.info("ELSE :" + homeDir); } - for (File file : homeDir.listFiles()) { - TestNG runner = new TestNG(); - List suitefiles = new ArrayList<>(); - - if (file.getName().toLowerCase().contains("auth")) { - if (file.getName().toLowerCase().contains("prerequisite")) { - BaseTestCase.setReportName("auth-prerequisite"); - } else { - // if the prerequisite total skipped/failed count is greater than zero - if (EmailableReport.getFailedCount() > 0 || EmailableReport.getSkippedCount() > 0) { -// skipAll = true; + // List and sort the files + File[] files = homeDir.listFiles(); + if (files != null) { + Arrays.sort(files, (f1, f2) -> { + // Customize the comparison based on file names + if (f1.getName().contains("prerequisite")) { + return -1; // f1 should come before f2 + } else if (f2.getName().contains("prerequisite")) { + return 1; // f2 should come after f1 + } + return f1.getName().compareTo(f2.getName()); // default alphabetical order + }); + + for (File file : files) { + TestNG runner = new TestNG(); + List suitefiles = new ArrayList<>(); + + if (file.getName().toLowerCase().contains("auth")) { + if (file.getName().toLowerCase().contains("prerequisite")) { + BaseTestCase.setReportName("auth-prerequisite"); + } else { + // Check if prerequisite suite failed or skipped + if (EmailableReport.getFailedCount() > 0 || EmailableReport.getSkippedCount() > 0) { + // skipAll = true; + } + + BaseTestCase.setReportName("auth"); } - - BaseTestCase.setReportName("auth"); + suitefiles.add(file.getAbsolutePath()); + runner.setTestSuites(suitefiles); + System.getProperties().setProperty("testng.output.dir", "testng-report"); + runner.setOutputDirectory("testng-report"); + runner.run(); } - suitefiles.add(file.getAbsolutePath()); - runner.setTestSuites(suitefiles); - System.getProperties().setProperty("testng.outpur.dir", "testng-report"); - runner.setOutputDirectory("testng-report"); - runner.run(); } + } else { + LOGGER.error("No files found in directory: " + homeDir); } }