Concept of TestNG Parameters

Last updated on Nov 28 2021
Vidhya Prakesh

Table of Contents

Concept of TestNG Parameters

TestNG Parameters are the arguments that we pass to the test methods. There are two ways through which we will pass the parameters to the test methods:

  • TestNG Parameters
  • TestNG DataProviders

In this blog , we’ll study the TestNG Parameters. we’ll study the parameterization within the xml file.

Suppose we would like to line the worldwide variables such url settings, username, password or API Keys, there are some values which are constant altogether the test cases, in such case we use the TestNG Parameters.

TestNG Parameters are present within the xml file. they will be applied either inside the tag or tag. If we would like to use the parameters to all or any the test cases, then the parameters are applied inside the tag. If the parameter is restricted to a specific folder, then the parameter is applied within a tag.

Let’s understand through an example.

First case: When Parameters are applied below the tag.

Step 1: Open the Eclipse.

Step 2: We create three class files, i.e., Sum.java, Subtract.java, and Multiply.java.

Sum.java

package com.tecklearn;
import org.testng.annotations.Test;
import org.testng.annotations.Parameters;
public class Sum
{
@Test
@Parameters({"a","b"})
public void add(int c, int d)
{
int sum=c+d;
System.out.println("Sum of two numbers : "+sum);
}
}

Substract.java

package com.tecklearn;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class Subtract
{
@Test
@Parameters({"a","b"})
public void add(int c, int d)
{
int subtract=c-d;
System.out.println("Subtraction of two numbers : "+subtract);
}
}

Multiply.java

package com.tecklearn;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class Multiply
{
@Test
@Parameters({"a","b"})
public void add(int c, int d)
{
int mul=c*d;
System.out.println("Multiplication of two numbers : "+mul);
}
}

Step 3: Now, we create the testng.xml file.

testng.xml

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

In the above testng.xml file, we pass the parameters which are valid to all or any the classes.

Step 4: Run the testng.xml file.

Output

1 64

Second case: When parameters are specific.

Step 1: Open the Eclipse.

Step 2: We create two class files. i.e., Fruits.java and Vegetable.java.

Fruits.java

package com.tecklearn;
import org.testng.annotations.Test;
import org.testng.annotations.Parameters;
public class Fruits
{
@Test
@Parameters("mango")
public void mango(String m)
{
System.out.println("Fruits names are: ");
System.out.println(m);
}
@Test

@Parameters("orange")
public void orange(String o)
{
System.out.println(o);
}
}

Vegetable.java

package com.tecklearn;
import org.testng.annotations.Test;
import org.testng.annotations.Parameters;
public class Vegetable
{
@Test
@Parameters("Cauliflower")
public void c(String m)
{
System.out.println("Vegetable names are :");
System.out.println(m);
}
@Test
@Parameters("Ladyfinger")
public void orange(String l)
{
System.out.println(l);
}
}

Step 3: Now, we create the testng.xml file.

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

In the above testng.xml, we specify the parameters during a particular folder means the parameters are applied to those classes which are specific thereto folder.

Step 4: Run the testng.xml file.

Output

2 63

Concept of TestNG Parameters

TestNG Parameters are the arguments that we pass to the test methods. There are two ways through which we will pass the parameters to the test methods:

  • TestNG Parameters
  • TestNG DataProviders

In this blog , we’ll study the TestNG Parameters. we’ll study the parameterization within the xml file.

Suppose we would like to line the worldwide variables such url settings, username, password or API Keys, there are some values which are constant altogether the test cases, in such case we use the TestNG Parameters.

TestNG Parameters are present within the xml file. they will be applied either inside the tag or tag. If we would like to use the parameters to all or any the test cases, then the parameters are applied inside the tag. If the parameter is restricted to a specific folder, then the parameter is applied within a tag.

Let’s understand through an example.

First case: When Parameters are applied below the tag.

Step 1: Open the Eclipse.

Step 2: We create three class files, i.e., Sum.java, Subtract.java, and Multiply.java.

Sum.java

package com.tecklearn;
import org.testng.annotations.Test;
import org.testng.annotations.Parameters;
public class Sum
{
@Test
@Parameters({"a","b"})
public void add(int c, int d)
{
int sum=c+d;
System.out.println("Sum of two numbers : "+sum);
}
}

Subtract.java

package com.tecklearn;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class Subtract
{
@Test
@Parameters({"a","b"})
public void add(int c, int d)
{
int subtract=c-d;
System.out.println("Subtraction of two numbers : "+subtract);
}
}

Multiply.java

package com.tecklearn;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class Multiply
{
@Test
@Parameters({"a","b"})
public void add(int c, int d)
{
int mul=c*d;
System.out.println("Multiplication of two numbers : "+mul);
}
}

Step 3: Now, we create the testng.xml file.

testng.xml

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

In the above testng.xml file, we pass the parameters which are valid to all or any the classes.

Step 4: Run the testng.xml file.

Output 

Second case: When parameters are specific.

Step 1: Open the Eclipse.

Step 2: We create two class files. i.e., Fruits.java and Vegetable.java.

Fruits.java

package com.tecklearn;
import org.testng.annotations.Test;
import org.testng.annotations.Parameters;
public class Fruits
{
@Test
@Parameters("mango")

public void mango(String m)
{
System.out.println("Fruits names are: ");
System.out.println(m);
}

@Test
@Parameters("orange")
public void orange(String o)
{
System.out.println(o);
}
}

Vegetable.java

package com.tecklearn;
import org.testng.annotations.Test;
import org.testng.annotations.Parameters;
public class Vegetable
{
@Test
@Parameters("Cauliflower")
public void c(String m)
{
System.out.println("Vegetable names are :");
System.out.println(m);
}
@Test
@Parameters("Ladyfinger")
public void orange(String l)
{
System.out.println(l);
}
}

Step 3: Now, we create the testng.xml file.

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

In the above testng.xml, we specify the parameters during a particular folder means the parameters are applied to those classes which are specific thereto folder.

Step 4: Run the testng.xml file.

Output

2 63

So, this brings us to the end of blog. This Tecklearn ‘Concept of TestNG Parameters’ 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 "Concept of TestNG Parameters"

Leave a Message

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