- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to perform data parameterization in TestNG?
We can perform data parameterization in TestNG. The parameterization in execution in TestNG can be done in the following ways −
data parameterization with @Parameters annotation.
data parameterization with @DataProvider annotation.
Example
Code Implementation of TestNG xml file with @Parameter annotation.
<?xml version = "1.0" encoding = "UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name = "Tutorialspoint Test"> <parameter name = "Url" value="https://www.tutorial.com"/> <test name = "Regression Cycle 1"> <classes> <class name = "TestParameter" /> </classes> </test> </suite>
We can pass values at runtime to the test methods by defining <parameter> in the TestNG xml file.
Example
import org.testng.annotations.Parameters; import org.testng.annotations.Test; public class TestParameter { @Test @Parameters("Url") public void loginwithUrl(String urlname) { System.out.println("The value of url is : " + urlname);} }
Java class files have @Parameters with (“Url”).
Code Implementation with @DataProvider annotation.
@DataProvider(name = "QuestionSearch") public Object[][] quest_anssearch(){ return new Object[][] { { “Tutorialspoint”, “Java”}, { “Python”, “PyCharm”}, }; } @Test(dataProvider = "QuestionSearch ") public void userInput(String subject, String lang){ System.out.println("The values are : " + subject +”“+ lang); }
We can pass multiple data at runtime with the help of @DataProvider in the Java class file.
- Related Articles
- How to perform parameterization in execution in TestNG?
- How to use TestNG data providers for parameterization in Rest Assured?
- How to do single data parameterization without Examples in Cucumber?
- How to perform data-driven testing in Cypress?
- How to generate JSON data and perform Schema Validation in Oracle?
- How to use TestNG SkipException?
- How to achieve parallel execution in TestNG?
- How to set Thread name in TestNG?
- How to run test groups in TestNG?
- How to install TestNG in eclipse using Selenium?
- How to run multiple test classes in TestNG?
- How to specify method name sequence in TestNG?
- How can Tensorflow be used with Estimators to perform data transformation?
- How to perform group-wise linear regression for a data frame in R?
- How to perform Wilcoxon test for all columns in an R data frame?

Advertisements