Importance of XML file in TestNG Configuration

Last updated on Nov 28 2021
Vidhya Prakesh

Table of Contents

Importance of XML file in TestNG Configuration

In TestNG, you’ll define multiple test cases during a single class whereas, in Java, you’ll define just one test during a single class within the main() method. In Java, if you would like to make another test, then you would like to make another java file and define the test within the main() method.

Instead of creating test cases in several classes, we recommend you to use TestNG framework that permits you to make multiple test cases during a single class.

You can create multiple test cases with the assistance of @Test annotation.

Let’s understand through an example.

public class test

{

@Test

public void test1() // First test suit .

{

System.out.println("test1");

}

@Test

public void test2() // Second test suit .

{

System.out.println("test2");

}}

The above code consists of a category test. the category test consists of two test cases, i.e., test1() and test2(). you’ll differentiate the test cases by considering the sequence of test cases. within the above code, the test suit test2() is written within the second @Test annotation, so this test suit are going to be considered because the second case.

Source code

1 70

Output

2 69

Note: you’ll trigger all the test cases from one file referred to as xml file. Xml file is that the heart of TestNG framework.

 

How to create a xml file

  • Right click on the project. Move your cursor down, and you’ll see TestNG then click on the Convert to TestNG.

3 68

  • The below screen shows the preview of the xml file. Click on subsequent button.

4 62

  • Click on the Finish button.

5 57

  • The testing.xml file is shown below:

6 48

In the above ASCII text file of xml file, suite is at the upper hierarchy in TestNG. Inside the , you’ve got to define the test name folder. This test name folder is that the name of the folder. for instance , during a loan company, there are three differing types of modules like consumer loan , home equity credit and automobile loan , and every module contain its own test cases. of these test cases are defined within the test name folder.

Now we’ll create the module of private loan.

Step 1: We first create two java files and both the files contain test cases.

test1.java

package day1;
import org.testng.annotations.Test;
public class module1
{
@Test
public void test1()
{
System.out.println("Hello tecklearn!!");
}

@Test
public void test2()
{
System.out.println("JTP Travels");
}
}

test2.java

package day1;
import org.testng.annotations.Test;
public class module2
{
@Test
public void test3()
{
System.out.println("hindi100.com");
}
}

Step 2: Now we’ll create the xml file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<!-- Test -->
<!-- Suite -->

In the above XML file, we’ve created the suite “loan_department“. we’ve created the module “Personal loan” inside the suite and within this module, we’ve created the test cases defined within the classes day1.module1 and day1.module2, where day1 is that the package name and module1 and module2, are the classes.

Step 3: during this step, we’ll run the test cases. Now we don’t got to run the java files individually. we’ve to run the XML file which can automatically execute all the test cases as we’ve configured all the category files inside the XML file that are containing test cases.

Right click on the testng.xml file then move right down to the Run As then click on the1 TestNG Suite.

7 40

Output

8 36

In the above output, we observe that each one the test cases run successfully with none failure.

So, this brings us to the end of blog. This Tecklearn ‘Importance of XML file in TestNG Configuration’ blog helps you with commonly asked questions if you are looking out for a job in Selenium and Automation Testing. If you wish to learn Selenium and build a career in Automation Testing domain, then check out our interactive, Selenium Certification Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/selenium-training-certification/

Selenium Certification Training

About the Course

Tecklearn’s Selenium Certification Training enables you to master the complete Selenium suite. The Selenium Training is designed to train developers and manual testers to learn how to automate web applications with a robust framework, and integrate it within the DevOps processes of an organization. This Selenium Certification Training will also help you master important concepts such as TestNG, Selenium IDE, Selenium Grid, Selenium WebDriver, etc. Get hands-on experience on widely used automation frameworks such as Data-Driven Framework, Keyword-Driven Framework, Hybrid Framework, and Behavior Driven Development (BDD) Framework. Throughout this online Instructor-led Selenium Certification Training, you will be working on real-life industry use cases.

Why Should you take Selenium Certification Training?

  • The average salary of a Selenium Test Automation Engineer is $94k per year – Indeed.com.
  • Automation Testing Market is expected to grow at a Compound Annual Growth Rate (CAGR) of 18.0% in the next three years.
  • Global software testing market to reach $50 billion by 2020 – NASSCOM. Selenium tool supports more browsers and languages than any other testing tool.

What you will Learn in this Course?

Getting started with Selenium

  • Introduction to Selenium testing
  • Significance of automation testing
  • Comparison of Manual and Automation Testing
  • Installation of Java JDK, JRE and Eclipse

Setting the environment in Eclipse for Selenium

  • Java Introduction
  • Creating a Java function and executing
  • Concepts of Java
  • Properties File
  • Reading Data from Excel File
  • Database Connection
  • Hands On

Advantages of Selenium automation testing

  • Selenium Features
  • Concept of Selenium Integrated Development Environment
  • Understanding of the Selenium IDE features
  • Addition of Script assertions and general commands
  • Deploying the first Selenium Script
  • Sample project IDE
  • Recording Selenium test case
  • Hands On

Selenium Web driver Automation

  • Architecture of Selenium Web Driver
  • Download and installation
  • Creating a Java function using Selenium and execution
  • Hands On

Deploying Web Drivers for scripting

  • Getting the HTML source of Web Element
  • Table and Form Elements
  • Firebug extension and Fire Path installation
  • Advance User Interactions and Cross Browser Testing
  • Hands On

Deep dive into Selenium Web Driver

  • Action Commands
  • Web Table / Date Picker
  • How to Implement Switching Commands in WebDriver
  • Alerts
  • Frames
  • Hands On

Switching Operations in WebDriver using Window

  • Selenium Webdriver Wait
  • Implicit wait, Explicit wait
  • Deploying searching elements using the link text, name, using XPath
  • Calendar
  • Hands On

Introduction to TestNG Framework

  • Introduction to TestNG
  • Advantages of TestNG
  • Installing TestNG on Eclipse
  • Rules to write TestNG
  • TestNG Features
  • Annotations
  • Grouping
  • Sequencing: Prioritization and Dependency
  • Enable/Disable a test case
  • Parameterization: Using Xml file and DataProvider
  • Parallel Testing & Cross Browser Testing
  • TestNG Report: HTML Report, Console Report, XML Report

JUnit Operations and Test Framework

  • Annotations, Methods in JUnit
  • Junit Test Suites, ANT Build and JUNIT reporting
  • Types of Test Automation Framework
  • Module Based Testing Framework
  • Data Driven Testing Framework
  • Keyword Driven Testing Framework
  • Hybrid Driven Testing Framework
  • How to implement Testing Framework in Project

Object Repository

  • Understanding of Object Repository
  • Learning sample scripts using object repository
  • Page Object Modelling
  • Page Factory

JavaScript Functions

  • Autosuggestion
  • Headless Browser
  • Sikuli
  • XPath

Got a question for us? Please mention it in the comments section and we will get back to you.

 

 

0 responses on "Importance of XML file in TestNG Configuration"

Leave a Message

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