Selenium Webdriver Appium Complete TutorialSelenium Webdriver Appium Complete Tutorial
Automation Testing
  • Tools
    • Selenium
      • Selenium Java Tutorial
      • Selenium C# Tutorial
    • Appium
      • Appium Java Tutorial
      • Appium C#Tutorial
    • Katalon
  • Trainings
  • TestNG
  • Reports
    • Extent Reports
      • Extent Reports – Java
      • Extent Reports – Java -Version3
      • Extent Reports – C#
    • Vigo Reports
    • AT Excel Report
  • Excel
    • Apache POI – Java
    • Excel With C#
  • Interview Questions
    • Selenium Interview Questions
    • Java Interview Questions
    • C# Interview Questions
  • Demo Site
  • Practice Site
  • More…
    • AutoIt
    • Sikuli
    • Robot Class
    • File Upload
    • ScreenShot
      • AShot
      • ShutterBug
  • About
December 13, 2016

Running testng.xml using Command Prompt





Running testng.xml using command prompt will discuss about how to execute xml file from the command prompt. In our previous blogs we just created testng.xml file but did not verified it by running testng.xml file. In this blog will discuss how to run testng.xml configuration file. There are multiple ways of running the testng.xml file.

There are 2 ways to run the testng.xml file:

  1. Using Command Prompt
  2. Using IDE (i.e. Eclipse)

Using Command Prompt:

We can execute the testng.xml file through the command prompt. This way  allows the use of multiple testng.xml files to execute simultaneously through TestNG. Before running a testng.xml suite through the command prompt, we need to compile our project code. The code compiled by Eclipse can be found under a folder named “bin” inside your Java project folder.

Below are the steps to run the testng.xml from command prompt:

1. Open the command prompt on your system.

2. Go to the Java project folder where the new testng.xml is created.

Note:  To work with command prompt commands need to download testng.jar file and jcommander.jar files. Place these files in one separate folder (here we will place in libs folder under the project folder).

3. Now type the below command(s) in the command prompt. Here you have 2 ways to execute the testng.xml from command prompt.

a) First, we need to set the classpath from the command prompt. For this we need to mention the bin (all compiled files will be resides in this) folder path and required jar files folder.

set classpath=[Project Folder]\bin;[Project Folder]\libs\*   

Example:

set classpath=D:\TestProject\bin;D:\TestProject\libs\*

Second, execute the testng.xml file from the command prompt.

java org.testng.TestNG testng.xml

b) Instead giving 2 different commands, we can combine and run as a single command to execute the testng.xml file.

Find the command below:

Here, we are in the project folder. So, no need to mention the project folder path explicitly.

java -cp “.\bin;.\libs\*” org.testng.TestNG testng.xml

In the above command we are adding the TestNG JAR and the project compiled code to the Java classpath by using the -cp option of Java.

4. In the both ways you can find the result screen as belowResult from Command Prompt

5. Here org.testng.TestNG consists of the main method that Java will use to execute the testng.xml file, which is passed as an argument at the command line.

6. After execution an HTML report is generated by TestNG in a folder named test-output under the same directory where you had run the command.

The following is the HTML test report generated by TestNG:

Sample HTML Report




7. In case you would like to execute multiple testng.xml files, you can use the previous command by passing the other XML files as added arguments to the command line.

The following is a sample command:

java -cp “.\bin;.\libs\*” org.testng.TestNG testng.xml testng1.xml

Result from Command Prompt with multiple xmls

And you can see the HTML report from the test-output folder.

8. TestNG also allows executing a particular test from the testng.xml file. To execute a particular test from the testng XML file, use the option -testnames at the command line with comma-separated names of tests that need to be executed. The following is a sample command:

java -cp “.\bin;.\libs\*” org.testng.TestNG -testnames “SampleTest” testng.xml

The preceding command will execute a test with the name SampleTest from testng.xml if it exists in the defined suite.

Below is the screenshot for the same:

Result from Command Prompt with particular test

Please watch the YouTube video for better understanding.



Share this post: on Twitter on Facebook

Understanding testng.xml file Running testng.xml using Eclipse

Related Posts

Excel to DataProvider

TestNG

Read data from Excel to DataProvider in Selenium

Running TestNG programmatically

TestNG

Running TestNG Tests Programmatically

EXECUTING ONLY FAILED TESTS

TestNG

Executing Only Failed Tests in TestNG

Capture Screenshot for Failed Tests

TestNG

Capture Screenshot for Failed Tests in TestNG

Preserve Order in TestNG

TestNG

Preserve Order in TestNG

PRIORITIZING TESTS

TestNG

Prioritizing Tests in TestNg

EXECUTE MULTIPLE XML FILES

TestNG

Execute Multiple XML files in TestNG

CUSTOM REPORTER IN TESTNG (1)

TestNG

Custom Reporter in TestNG

CUSTOM LOGGER IN TESTNG

TestNG

Custom Logger in TestNG

ASSERTIONS

TestNG

TestNG Assertions

Newsletter

Recent Posts

  • TAKING WEB ELEMENT SCREENSHOT IN SELENIUMHow to Capture WebElement Screenshot in Selenium Webdriver using selenium 4
    December 15, 2019
  • How To SWAP Two Numbers in Java Without using Temp VariableHow to SWAP Two Numbers in Java Without Temp variable or Without Third variable
    December 8, 2019
  • How to Swap Two Numbers in Java with Temp VariableHow to SWAP Two Numbers in Java using Temp Variable
    December 1, 2019
  • How to Read Properties file in JavaHow to Read Data From Properties File in Java
    November 27, 2019
  • Compare two arrays in java with out inbuilt functionsHow to Compare Two Arrays in Java without built-in functions
    November 16, 2019
© Selenium Webdriver Appium Complete Tutorial 2025