'how to use Springboot commandline argument to run the selenium testng suite

I have a Spring boot based Java selenium project which runs the test suites by using testng xml file. I want to use Spring boot command line arguments to give option for the user to run which suite to run. User will be listed all the test suites available, which user can select. I am building the application as war instead of jar for some reasons. when we run the war, using jar -xvf myapplication-local.war, it should print the following,

Chose the Test Suite to run from the following list of Test suites,

  1. Login
  2. Checkcustomerdetails
  3. Checkcustomeraddress

Test Suites are mapped as below:

  1. Login - login.xml
  2. Checkcustomerdetails - checkcustomerdetails.xml
  3. Checkcustomeraddress - checkcustomeraddress.xml

if user types 1 and clicks 'ENTER', should run login.xml if user types 2 and clicks 'ENTER', should run checkcustomerdetails.xml

The following command it is very lengthy, can we make it do a little better.

--java -cp "./WEB-INF/lib/*;./WEB-INF/classes;./myapplication-local.war" org.testng.TestNG "./WEB-INF/classes/testscripts/login.xml"

@SpringBootApplication
public class MyApplication implements CommandLineRunner {

    
    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);       
    }

    public void run(String... args) throws Exception {

    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source