Friday, July 7, 2017

How to execute Selenium test cases from Command Prompt using testng.xml?

Generally we do not run our scripts always from eclipse in real world. The test suite or test scripts are triggered using a third party tools like Jenkins.

A batch file will be created to the project and scripts can be triggered either configuring the batch file in CI tools like Jenkins or double clicking the batch file. So you should know how to execute the scripts from command prompt.

We have seen in the previous posts about Create TestNG project for Selenium Automation and Writing the First Selenium Test Case with testNG. These two posts are prerequisites for the current tutorial post. Please refer them before going further. Let’s get started with main topic

Step 1: Create a TestNG project.

Step 2: Go to project home directory path, create a folder say libs and keep the required TestNG and Selenium jar file as shown below.

You can download Selenium Jar file from click here. And the TestNG jar files (testng.jar and jcommander.jar) can be taken from the eclipse plugins location as show below.

 Add these three jar files in the Java Build Path

Step 3: Create a sample Selenium test as shown below.  Please copy and paste the below code in the test you created.

This sample selenium test launches Google application and searches for the Selenium Babu Page

Step 4: Create a testng.xml file to run the test. Please refer my previous post How to create testng.xml? to know how to create it.

On the next popup window, click OK. The testng.xml should be created, you can verify it in eclipse and project directory path. You should is the testng.xml file in the project directory path.

Step 5: Open the command prompt, and follow the below three steps to run the testng.xml file through command prompt.
  • Change the directory to the project home directory, run the command the below command                cd (Project_Directory_Path)
  • We must set the classpath for project to run testng.xml file from command propmpt, run the below command set classpath= (Project_Directory_Path)\jenkinsDemoProject\bin;    (Project_Directory_Path)\jenkinsDemoProject\libs\*
  • Now run the command java org.tetsng.TestNG testng.xml in the command prompt. You should is the test execution starting, launching Firefox, opening the Facebook application and then closing the browser. You can observe the results now in the command prompt

That’s it. That is how we execute TestNG tests through command prompt. In the next session we will see how to execute these test from Jenkins.


  1. The future of automation testing tool is on the positive tool. As the demand of quality web application keeps on increasing, the tool like Selenium IDE is getting very popular all over the world. Thus, taking Selenium Training in Chennai will help you to enter software testing industry.Best Selenium training institute in Chennai

  2. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command.

    software testing course in chennai

  3. I simply wanted to thank you so much again. I am not sure the things that I might have gone through without the type of hints revealed by you regarding that situation.
    Best Python training Institute in chennai

  4. This is Very Useful blog, Thank you to Share this.

    R Training in Chennai


Java Program 5: How to reverse given string and each word of it?

Let us understand the problem with an example, suppose "Learn Core Java" is the given string then the expected output should be &...