I have a project where i have used selenium to automate my web application using testng i need to run the same using a .bat file which i can directly execute using command line or integrate the same in jenkins
Asked
Active
Viewed 1,304 times
1 Answers
1
1.You can create a single executable jar file for your project. However this jar requires a class with main()method to start the execution. Since here you are using testng, you need to execute it programmatically as below. You can execute this jar from command line as java -jar filename.jar
OR write same command in batch file.
public class MainTest
{
public static void main(String[] args)
{
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { AnnotationTest.class });
testng.addListener(tla);
testng.run();
}
}
2. If it is maven project, then maven provides plugins to create single executable jar file for you. Make sure you refer testng.xml file in your project's pom.xml file. Maven plugin for example : Maven Shade plugin
Please note, in both cases you need to have class with main()method.

MKay
- 818
- 9
- 32
-
Is your project a simple java project or maven project? you will get many blogs providing step by step solutions if you search accordingly OR here is direct link on SO question [How to make a jar file for project](http://stackoverflow.com/questions/5258159/how-to-make-an-executable-jar-file) – MKay Sep 16 '15 at 07:07
-
but @Mk08 it shows configuration failure in my testng. my project is not a maven project. I have a testng.xml file. the above class is working fine when I am running this class from IDE and but after making jar it showing configuration issue – Shubham Jain Sep 16 '15 at 10:50
-
Actually above function is running the class but we need a code which can execute the testng.xml file – Shubham Jain Sep 16 '15 at 10:55
-
@Shubham Jain : Check the updated solution in this SO question : [testng.xml from main method](http://stackoverflow.com/questions/28942467/testng-how-do-i-run-a-custom-testng-xml-file-programmatically) . – MKay Sep 16 '15 at 11:07