Hi everyone,
I’m facing an issue while trying to dynamically select and run specific test classes using TestNG based on checkboxes in a web UI. I'm attempting to run only the selected classes, but I'm encountering several errors related to missing resources and class not found exceptions.
Here’s what I’ve done:
- I have a servlet that receives selected test classes from checkboxes in the web UI and passes those classes to TestNG for execution.
- TestNG runs programmatically using the TestNG and XmlSuite classes.
- However, when I run the selected tests, I get the following errors:
[ERROR org.testng.reporters.SuiteHTMLReporter - test-output\testng.css]
[ERROR org.testng.reporters.jq.Main - test-output\jquery-3.6.0.min.js]
java.nio.file.NoSuchFileException: test-output\jquery-3.6.0.min.js
[ERROR org.testng.internal.Utils - The system cannot find the path specified]
java.io.IOException: The system cannot find the path specified
[ERROR org.testng.reporters.EmailableReporter2 - Unable to create output file]
java.nio.file.NoSuchFileException: test-output\emailable-report.html
Steps Taken:
- I’ve confirmed that the selected classes exist and are correctly passed to TestNG.
- I’ve tried setting a custom output directory for the test reports.
- I made sure the testng.xml is configured properly and is being referenced with the correct path.
- Checked file permissions and ensured that the servlet has write access to the directories.
The Issue:
- The system cannot find the required files like testng.css, jquery-3.6.0.min.js, or even emailable-report.html in the test-output folder.
- Additionally, I get class not found exceptions when running selected test classes.
My Question:
- Is this a TestNG configuration issue, or am I missing something with the file generation?
- How can I ensure that TestNG generates the necessary files like CSS and JS for the HTML reports?
- Any insights into resolving the class not found issue when running dynamically selected test classes?
Code for Running TestNG :
TestNG testng = new TestNG();
XmlSuite suite = new XmlSuite();
suite.setName("Sabhyasha Test Suite");
// Dynamically setting classes based on selected checkboxes
List<XmlClass> classes = new ArrayList<>();
// Assume selectedClasses is a List<String> from UI input
for (String className : selectedClasses) {
classes.add(new XmlClass(className));
}
XmlTest test = new XmlTest(suite);
test.setXmlClasses(classes);
testng.setXmlSuites(Collections.singletonList(suite));
testng.setOutputDirectory("test-output");
testng.run();
Thanks in advance for your help! Any suggestions or advice would be greatly appreciated.