Saturday 23 January 2016

How to run TestNG using batch file



We can run the selenium TestNg framework by using command prompt. Also we can run the Selenium TestNG by using batch file (.bat).

From this approach we no need to open the Eclipse. We can run the script by double click on the batch file. Then its automatically get run.


Follow the below steps for run TestNG from batch file

For Ex: Consider the project path will be

E:\SeleniumTestNG

1) Create the folder with the name of "lib" and paste all required .jar files needs to be run Selenium script(include all selenium required jar files).


2) Create Run.bat batch file under same project path with below code

set javaTestProjectPath=E:\SeleniumTestNG
E:
cd %javaTestProjectPath%
set path=C:\Program Files\Java\jdk1.8.0\bin
set classpath=%javaTestProjectPath%\bin;%javaTestProjectPath%\Lib\*;
javac -verbose %javaTestProjectPath%\src\driverFiles\TestNGExecution.java -d %javaTestProjectPath%\bin
java org.testng.TestNG %javaTestProjectPath%\testng.xml

Here TestNGExecution.java file contains the main TestNg annotations code.

we can run above same code in command line also.

3) Once we double click on Run.bat file in project path, then its starts the automation execution.





1 comment: