How to Run testng.xml File Without using IDE or Build Tool?

Purpose

The article shows how you can run our testng.xml file without using any IDE (Eclipse, NetBeans, etc.) or Build tools (Ant or Maven). You often face a situation where you are assigned a new Virtual machine and you are asked to run your created Selenium scripts on it without any IDE or Build tool. In addition, you are also expected to compile and run the scripts using the command prompt.

Solution

If you want to run your testng.xml files without any IDE or build tool, first you need to install Java on the system. In addition, you also need to set its path into environment variable.

Let’s consider the below-mentioned code for a Selenium project.

PROJECT_HOME

-> libs (all supported jar files)

-> src1 (java code source directory)

        -> com

        -> example

        -> tests (this folder contains .java files)

  -> src2 (java code source directory)

    -> com1

      -> example1

        -> tests1 (this folder contains .java files))

  -> TestNG

        -> testng.xml

Compile Code

First, you need to compile Java code using the command prompt. For this, you need to open the command prompt and go to the PROJECT_HOME directory.

In order to compile the code, you need to type the following command:

javac -classpath libs/* -d ./bin ./src1/com/example/tests/*.java ./src2/com1/example1/tests1/*.java

How to Run testng.xml File Without using IDE or Build Tool?Command Explanation

Last argument “./src1/com/example/tests/*.java ./src2/com1/example1/tests1/*.java” is the complete path, where the Java file exists.

Note: Above command will work on all operating systems.

Code Compilation on Windows Machine

You can also compile the code on a Windows machine. For this, open the command prompt and reach at project directory. Then, type command the following command:

dir /s /B *.java > javaFilePath.txt

How to Run testng.xml File Without using IDE or Build Tool?The above command will search all the .java files in current and subdirectory and put the entire Java file path in ‘javaFilePath.txt’ file. You can compile the entire Java file using the below-mentioned command.

javac -classpath libs/* -d ./bin @javaFilePath.txt

How to Run testng.xml File Without using IDE or Build Tool?For Linux System $ find -name “*.java” > sources.txt$ javac -classpath libs/* -d ./bin @javaFilePath.txt Note: You should not put any space while naming the directory; else the above compilation command will not work.

Run the testing.xml file

To run the testing.xml file, you can use the following command:

 java -cp bin;libs/* org.testng.TestNG TestNG/testng.xml

How to Run testng.xml File Without using IDE or Build Tool?Now with the help of the above information, you can run your testng.xml files without any IDE or build tool.

SHARE THIS

Get A Free Quote

2 thoughts on “How to Run testng.xml File Without using IDE or Build Tool?

  1. Could you please explain the same with Maven Project.

    It is very well explained and perfectly works with Java project.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.