Friday, July 7, 2017

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

We know how to execute the test cases from IDE like eclipse o IntelliJ. We just have to either right click on the test case and select the Run option or right right click on the testng.xml file and select TestNG --> Run as --> TestNG suite option.

In this post we will learn how to execute the scripts from command prompt.

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 steps one by one to run the testng.xml file through 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, this is how we can execute TestNG tests through command prompt.

Thanks for reading. Hope this post helped you to execute the testng.xml from command prompt.

#HappyLearning #HappyTesting #qababu


  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


Selenium4: Working with two parallel windows in Selenium Automation

A new method newWindow() is introduced in Selenium 4 (Alpha). Using this method we can open a new tab or new window from the current window...