TestNG XML example to execute Multiple Classes

What is TestNG?

TestNG is a testing framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful and easier to use



What is TestNG xml file?


In Testng xml we have to declare a suite where it is represented by one XML file.The suite can contain one or more tests and is defined by the "suite"  like <suite name> tag.A test is represented by <test> and can contain one or more TestNG classes.A TestNG class is a Java class that contains at least one TestNG annotation.

In our project we can have multiple TestNG classes and we can run specified classes using TestNg xml file.

Below is the example will provide complete knowledge on how to execute multiple classes in TestNG xml file

Create one package which is having three class as below

Package:com.future.SeleniumTest
Java Classes:
  1. TestOne
  2. TestTwo
  3. TestThree


now lets see the details for each class

Package: com.future.SeleniumTest
Class Name: TestOne

package com.future.SeleniumTest;
import org.testng.annotations.Test;
public class TestOne extends SeleniumWeb {
  @Test
  public void OpenUrl() {
 System.out.println("Page url is opened");
 
 }
  @Test
  public void OpenHomepage() {  
 System.out.println("Home page is opened"); 
  }
}

Package: com.future.SeleniumTest
Class Name: TestTwo

package com.future.SeleniumTest;

import org.testng.annotations.Test;

public class TestTwo {
  @Test
  public void VerifyAboutUspage() {
 System.out.println("Verify About Us page");
  }
  
  @Test
  public void VerifyUserpage() {
 
 System.out.println("Page url is opened");
 
 }
}

Package: com.future.SeleniumTest
Class Name: TestThree

package com.future.SeleniumTest;

import org.testng.annotations.Test;

public class TestThree {
@Test
 public void VerifyFAQSpage() {
 System.out.println("Verify About Us page");
 }
 
 @Test
 public void VerifyChangepasswordpage() {
 
 System.out.println("Page url is opened");
 
}
}

Now set up TestNG xml file as below

Test NG Xml format
TestNG Xml format


After saving the TestNG cml file run the file as Select TestNG xml file
Right Click
Select Run As --TestNG Suite

It will run all specified classes and will display results in Results of Running Suite as below.

Result of Test NG Suite
Result of Test NG Suite

Post a Comment

0 Comments