TestNG - Parameterization
~30 mins
Parameterization
What is parameterization
- To pass external test data to the testcases.
Why do we need to use it?
- To test the same functionality with different set of data or for running the same test with different configurations.
How to do parametrization?
- Using TestNg annotation based on the type of data
Types of Parameterization:
There are two ways by which we can achieve parameterization in TestNG
- Static Parameterization
- Dynamic Parameterization
1. Static parameterization:
- To pass the data through xml file
- Can be achieved through @Parameters annotation in testmethod
- Syntax:
@Parameters({"url", "username","Password")}
2. Dynamic parameterization
What is Dynamic parameterization?
- To pass external test data to the testcases.
Why do we need to use it?
- To test the same functionality with different set of data or for running the same test with different configurations.
How to do parametrization?
- Using TestNg annotation based on the type of data
Steps to achieve dynamic parametrization
- Step:1 Create a normal method with return type of String[][]
- Step:2 Declare and assign the value to the 2D Dimensional array
- Step:3 Add @DataProvider annotation on top of the method
- Step:4 Add dataProvider attribute the @Test Method
- Step:5 Add arguments to @test method to pass data from the DataProvider Method