-
The root tag of this file is <suite>.
-
<suite> tag can contain one or more <test> tags.
-
<test> tag can contain one or more <classes> tags.
-
<classes> tag can contain one or more <method> tags.
For more information on Tags and other tags that you can use in your XML file, check out the details here
Your xml file with just one test in a one class file will look something like this.

Try Running Test using Testng.xml
Just right click on the testng.xml file in package explorer of Eclipse and select Run As Testng Suite, the test will run and show the report as shown below.
package Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;
public class NewTest {
@Test
public void OpenBrowser() {
System.out.println("In Open Browser ....");
WebDriver driver = new InternetExplorerDriver();
driver.get("www.executeautomation.com");
driver.close();
}
}
Now the testng report looks like this.

TestNG to run Multiple Classes and Methods using testng.xml file
Now let’s try adding some more test method and classes. The testng.xml file looks something like this. As you could see there are lot of new tags in testng.xml like “parameter”, “method” etc.
package Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;
public class NewTest {
@Test
@Parameters({"SiteAddress"})
public void OpenBrowser(String value) {
System.out.println("In Open Browser ...." + value);
WebDriver driver = new InternetExplorerDriver();
driver.get(value);
driver.close();
}
@Test(dataProvider="DataFactory")
@Parameters({"SearchData"})
public void EnterSearchData(String value) {
System.out.println("Came to Search Data in IE ..." + value);
}
@DataProvider(name = "DataFactory")
public Object[][] CreateData()
{
return new Object[][]
{
new Object[] {"TestData1"},
new Object[] {"TestData2"}
};
}
}
Our NewTest2.java file looks something like this.
package Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.Test;
import org.testng.annotations.Parameters;
public class NewTest2 {
@Test
@Parameters({"SiteAddress1"})
public void OpenNewBrowser(String value) {
System.out.println("In Open New Browser" + value);
WebDriver driver = new InternetExplorerDriver();
driver.get(value);
}
}
Now lets run the test using testng.xml file as done before.
Now TestNg will genereate two report for us, since we have run two test as shown in the XML file.
The first report looks something like this.


Hi Karthik,
The Reports are not getting displayed on the website. I can only see images for the code.
Please fix this.
Thanks
Pankaj Sharma
Sure Pankaj.
Will do it !!!
Thanks for bring it up !!
Thanks,
Karthik KK
Hello Karthik,
While viewing the page, I have gone through below link – but its giving 404 error.
http://executeautomation.com/blogold/blog_mod/how-to-run-test-using-testng-in-selenium/
at
**************************************
Before running TestNG test, first you need to configure the TestNG with Selenium, check out the article here for step by step procedure.
**************************************
Requesting you to provide me proper link.
Oops !!!
Thanks for bringing to my notice, please check now, its updated !!!
Thanks,
Karthik KK
Hi…
Do you have any example for testng fraame work using POM?
Hi Karthik
Images are giving error
Hello Karthik,
Can’t see the images. Could you please fix it?
Can’t view the images
This looks like it might be an excellent tutorial… too bad there are images missing.
Yes I know Callie, its really my bad, I have covered a lot in this course https://www.udemy.com/automation-framework-with-selenium/
Thanks,
Karthik KK
Hi,
Can you do a tutorial in intellij for this?
Thanks!
Aman
Hi guys
when am Convert TestNG to TestNg Xml it displays like this for Cross Browser testing