- 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 parameterization in execution in TestNG?
The parameterization in execution in TestNG can be done by the following ways −
data parameterization with @Parameters annotation.
data parameterization with @DataProvider annotation.
Example
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”).
Example
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 data parameterization in TestNG?
- How to use TestNG data providers for parameterization in Rest Assured?
- How to achieve parallel execution in TestNG?
- How to overlook a particular test method from execution in TestNG?
- How to skip or ignore the execution of tests in TestNG?
- How to retrieve test method description in TestNG before and after execution?
- How to retrieve test method name in TestNG before and after execution?
- How to get the test group name in TestNG before and after execution?
- What is the order of execution of tests in TestNG?
- What is the order of test execution with priority in TestNG?
- What is the order of execution of TestNG methods?
- How to incorporate and remove test methods from execution from a\ncollection of test cases in TestNG?
- How does the execution of a particular test method depend on other test\nmethods in TestNG?
- How to do single data parameterization without Examples in Cucumber?
- How to set Thread name in TestNG?

Advertisements