How To Create TestNG XML File And Execute TestNG.XML File



How To Create TestNG XML File And Execute TestNG.XML File

In this tutorial, you will learn How to Create TestNG XML file and how to execute Test cases from TestNG.XML file.

 Create TestNG XML file:

In TestNG framework, we need to create Testng xml file to create and handle multiple test classes. We do configure our test run, set test dependency, include or exclude any test, method, class or package and set priority etc in the xml file.

Steps to create TestNG XML file 

Step 1: Create testng xml file

  1. Right click on Project folder, go to Newand select ‘File‘ as shown in below image.

 

CreateTestNGFile

  1. In New file wizard, add file name as ‘testng xml‘ as shown in below given image and click on Finish button.

 

 

iii. It will add testng xml file under your project folder.

 

Step 2 : Write xml code: 

  1. Now add below given code in your testng xml file.

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd”>

<suite name=”LoginPageSuite” parallel=”tests”>

<test name=”test1″>

<parameter name=”policyNumber” value=”12345″/>

<parameter name=”policyType” value=”Auto”/>

<parameter name=”BillDate” value=”23Nov”/>

<parameter name=”BillAmt” value=”200″/>

<classes>

<class name=”DemoPackage.clsLogin”>

<methods>

<include name=”VerifyPolicyDetails” />

</methods>

</class>

</classes>

</test>

</suite>

 

  1. Note:You can choose any name for your Test Suite & Test Name as per your need.
  2. After giving appropriate names, now your testng xml file will looks like this:

 

The hierarchy in the testng xml file is very simple to understand.

Very first tag is the Suite tag<suite>, under that it is the Test tag<test> and then the Class tag<classes>. You can give any name to the suite and the test but you need to provide the correct name to the <classes> tag which is a combination of your Package name and Test Case name.

  1. Package Nameis “DemoPackage”Test Class Name is “clsLogin”. So the Class Nameshould be DemoPackage.clsLogin

Step 3 : Execute a testng xml

Now let’s run the xml. Run the test by right click on the testng xml file and select Run As > TestNG Suite.

CreatetestNGFile

Once the execution is done, you could view test result under the TestNg console.

CreateTestNGFile

 

CreateTestNGFile

Tags:
Leave a comment

Your email address will not be published. Required fields are marked *

Subscribe now

Receive weekly newsletter with educational materials, new courses, most popular posts, popular books and much more!

https://bridgejunks.com/ https://crownmakesense.com/ https://brithaniabookjudges.com/ https://hughesroyality.com/ https://rhythmholic.com/ https://bandar89.simnasfikpunhas.com/ https://www.100calshop.co.il/products/thailand/ https://myasociados.com/ https://solyser.com/ http://konfidence.cz/ https://muscadinepdx.com/ https://bandar89.parajesandinos.com.ve/ https://goremekoop.com/ https://oncoswisscenter.com/ https://www.turunclifehotel.com/bandar89/ https://www.houseofproducts.biz/ https://taimoormphotography.com/
BIJI18 BIJI18 BIJI18