Tuesday 15 October 2013

Batch file[.bat] to invoke testng.xml and run tests | TestNG

Executing tests from a .bat file is familiar or useful while using GRID. There are couple of ways to execute this.

1| Copy any one of the below methods in text file
2| Edit the drive location
3| Save it as yourtext.bat
4| Now, double click on the batch file created.

Note: Its better to execute from cmd prompt before try

Method #1
cd C:\Workspace\projectname
java -cp C:\Workspace\projectname\lib\*;C:\Workspace\projectname\bin org.testng.TestNG testng.xml

Method #2
cd C:\Workspace\projectname
set ProjectPath=C:\Workspace\projectname
echo %ProjectPath%
set classpath=%ProjectPath%\bin;%ProjectPath%\lib\*
echo %classpath%
java org.testng.TestNG %ProjectPath%\testng.xml

4 comments:

  1. which lib folder are you referring to here?
    I am running my selenium script from eclipse and I can't find any lib folder in my workspace project folder.
    Any help would be appreciated.
    Thanks,
    Sumit

    ReplyDelete
  2. could not find or load main class org.testng.Testng

    whats this mean

    ReplyDelete
  3. My Eclipse script reads data from Excel through DataProvider. Testng.xml works fine when i run it from Eclipse>Run As>TestNG Suite. But if i try to run it from bat file it fails with no error message.

    ReplyDelete
  4. to execute maven project through jenkin what to write in .bat file

    ReplyDelete