0

I'm currently developing a portable software that runs Selenium and TestNG tests on a web page. I am using the maven-surefire-plugin and maven-assembly-plugin plugins in my Maven project. I would like to know how to configure my TestNG XML file containing the entire test suite to be located in src/test/resources, and how can I ensure that by simply executing the JAR file using 'java -jar', it automatically runs the entire test suite. I have already generated a JAR with all the necessary dependencies included.

my App.class:

List<String> suiteFiles = new ArrayList<String>();

    String testXml = "testng.xml";

    if (args.length == 0) {
        //suiteFiles.add(testXml.toString());
        suiteFiles.add(testXml);
    } else {
        for (int i = 0; i < args.length; i++) {
            suiteFiles.add(args[0]);
        }
    }

// for (int i = 0; i < args.length; i++) {
//paramList.add(args[i]);
//}
TestNG test = new TestNG();

// Para obtener los recursos del jar usamos la función getResourceAsStream();
//this.getClass().getResourceAsStream("");
// Es obligatorio que el primer argumento sea el fichero de configuración de TestNG .xml a ejecutar.
//suiteFiles.add(args[0]);
test.setTestSuites(suiteFiles);
test.run();
}

I expected the TestNG framework to run the test suites specified in the 'suiteFiles' list. If no command-line arguments are provided, it should run the default 'testng.xml' file. If command-line arguments are provided, it should run the specified testng.xml files. I have already included the necessary TestNG dependencies in the project, and the 'testng.xml' files are located in the 'src/test/resources' directory.

Yorye
  • 1
  • 1
  • Wrote long back - you can try this : https://niharikawhatsnext.wordpress.com/2015/03/11/running-maven-testng-tests-as-a-jar/ – niharika_neo Jul 25 '23 at 04:33

0 Answers0