Run TestNG from CMD

On one fine Friday evening you planned to leave the office by 5.30 pm to have dinner with your girl friend , so you closed all the application in your system just shut-down is left , at 5.29 your manager asks you to run the script and go but you do not have the time at that time you can do two things

1.Tell your junior to run the script but you knew that he never gonna obey what you tell,

2.Stay for half an hour and run the script in this case your girl friend gonna have dinner with someone else.

So in such situation you will be helpless, so to avoid such situation we used to go for running the script from CMD.


						import org.openqa.selenium.WebDriver;
						import org.openqa.selenium.firefox.FirefoxDriver;
						import org.testng.Reporter;
						import org.testng.annotations.Test;

						public class TestNGClass 
						{
							WebDriver driver=new FirefoxDriver();
							@Test
							public void openSeleniumMentor()
							{
								Reporter.log("opening chercher.tech");
								driver.get("https://chercher.tech");
								Reporter.log("selenium-webdriver.coom opened");
							}
							
							@Test
							public void openGoogle()
							{
								Reporter.log("opening google.com");
								driver.get("http://www.google.com");
								Reporter.log("google opened");
							}
							@Test
							public void openGmail()
							{
								Reporter.log("opening gmail");
								driver.get("http://gmail.com");
								Reporter.log("gmail opened'");
							}

						}
					


1.Gather all the jars to single folder(jars) under project folder before writing any code
i.selenium server

ii.testng jar

iii. jcommander jar

With latest TestNG, it is mandatory to place the Jcommander along with other jars, otherwise you will face below error.


						Error: Could not find or load main class org.testng.TestNG
						Caused by: java.lang.ClassNotFoundException: org.testng.TestNG		
						


all jars testng selenium webdriver

all jars folder testng selenium webdriver

1.Open CMD
cmd testng selenium webdriver

2.Navigate to the folder where you have the project
cmd testng selenium webdriver

cmd project in testng selenium webdriver

3.Write the write below code in CMD and hit enter button,

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

code to run on cmd testng selenium webdriver

3.script starts running
cmd execution testng selenium webdriver

4.After brunning it prints result on cmd terminal
cmd result testng selenium webdriver

Printing on the CMD
What ever you are printing on console will be printed onto CMD terminal if you run script from CMD

Create QR Code

Run TestNG From CMD


						import org.testng.annotations.Test;

						public class Simple 
						{

							@Test
							public void openSeleniumMentor()
							{
								System.out.println("open Selenium Mentor method");
							}
							
							@Test
							public void openGoogle()
							{
								System.out.println("open Google method");
							}
							@Test
							public void openGmail()
							{
								System.out.println("open gmail method");
							}
						}
					

print on cmd testng selenium webdriver

Make it Simple :
In the above scenario you have to run the script after opening the specified path and then type the code to run. It becomes lengthy if you run all the time

Follow the steps to short it


1.Open notepad
open notepad testng selenium webdriver

2.Write the below code into notepad(same as we used before),we should give newline between the lines then only it presses enter after the cd command line,if there is no line gap means it will considered as single command
testng suite testng selenium webdriver

3.Save the notepad file as "run.bat"
save as bat file testng selenium webdriver

4.Double click the run.bat or Right click -> Open
batch folder testng selenium webdriver

open testng batch file selenium webdriver

Option Present or Not in Dropdown in seleium

 
Join My Facebook Group
Join Group
 

About Author

Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.

Share this Article Facebook
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions
Copyright © CherCher Tech