On one fine Friday evening you planned to leave the office by 5.30 pm to have dinner with your girlfriend, 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 girlfriend 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("https://www.google.com");
Reporter.log("google opened");
}
@Test
public void openGmail()
{
Reporter.log("opening gmail");
driver.get("https://gmail.com");
Reporter.log("gmail opened'");
}
}
1.Gather all the jars to a single folder(jars) under the 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
1.Open CMD
2.Navigate to the folder where you have the project
3.Write the write below code in CMD and hit enter button,
java -cp bin; jars/* org.testng.TestNG testng.xml
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");
}
}
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
1.Open notepad
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 be considered as a single command
3.Save the notepad file as "run.bat"
4.Double click the run.bat or Right click -> Open