Saturday, July 18, 2020

How To Create And Use TestNG.Xml File and different Test Suite Level TestNG xml files

What Is TestNG.Xml?

TestNG.xml file is a configuration file that helps in organizing our tests. It allows testers to create and handle multiple test classes, define test suites and tests.
It makes a tester's job easier by controlling the execution of tests by putting all the test cases together and run it under one XML file. This is a beautiful concept, without which, it is difficult to work in TestNG.
How to create TestNg.xml file 
Step1: Right-click on the Project folder, go to New and select ‘File’ as shown in the below image.
Step 2: Add the file name as ‘TestNG.xml’ as shown in the below image and click on the Finish button.


Step 3: Now you can add the below XML code in your testng.xml file. You can choose your Test suite name and the Test name as per the requirements.
TestNG XML file @ Method Level 
<suite name="Test cases execution @ Method Level">
<test name="Method Level Test Suites">
<classes>
<class name="com.testng.pages.TestNgSuite">
<methods>
<include name="method1" />
<include name="method2" />
<include name="method3" />
<include name="method4" />
<exclude name="divisiblebyZero" />
</methods>
</class>
<class name="com.testng.tests.RetryLogicTest">
<methods>
<include name="retryTestMethod" />
<exclude name="retryTestMethod1" />
</methods>
</class>
</classes>
</test>
</suite>

TestNG XML file @ Package Level 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="Test cases execution @  Package Level">
<test name="Package Level Test Suites">
<packages>
<!-- <package name = "com.testng.pages"/> -->
<package name="com.testng.tests" />
</packages>
</test>
</suite>
TestNG XML file @ Class Level 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="TestNG Suite">
<test name="Sample Test">
<classes> <!-- Test cases will execute within specified class -->
<class name="com.testng.pages.TestNgSuite" />
</classes>
</test>
</suite>
TestNG XML file @ Groups Level 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Test cases execution @ Groups Level">
<test name="Groups Level Test Suites">
<groups>
<run>
<!-- <include name="smoke" /> -->
<include name="Testing Tools" />
</run>
</groups>
<classes>
<class name="com.testng.pages.TestNgSuite" />
</classes>
</test>
</suite>

No comments:

Post a Comment

How to install and setup Kubernetes cluster using kOps in AWS environment

  Kops: Kops is also known as Kubernetes Operations, it is an open-source project which helps you to create, upgrade, destroy, and maintain ...