Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

TestNG Data Provider

// You can set the dataprovider to be an array of Object and use ArrayList> to have your parameters in key value pairs.
@DataProvider
public Object[][] getTestData()
{
    List<HashMap<String, String>> arrayMapList = new ArrayList<HashMap<String, String>>();
    HashMap<String, String> hashMapItems = new HashMap<String, String>();

    //use a loop to fill in all the parameter name and value pairs
    hashMapItems.put("parameterName1", "parameterValue");
    hashMapItems.put("parameterName2", "parameterValue");
    //--------------More put statements here------
    //finally add hash map to the list
    arrayMapList.add(hashMapItems);

    //Iterate the array list and store each HashMap object in an object array. First dimension is the iterator value.
    Object [][] hashMapObj = new Object [arrayMapList.size()][1];

    for(int i=0; i<arrayMapList.size() ; i++) {
        hashMapObj[i][0] = arrayMapList(i);
    }

    return hashMapObj;
}

// For each hashmap value in the array list, the test method will be run with its own set of parameters.
@Test (dataProvider = "getTestData", enabled = true)
public void testDataRead(HashMap<String,String> hashMapValue)
{
    System.out.println(hashMapValue.get(parameterNameKey));  //parameter 1
    System.out.println(hashMapValue.get(parameterNameKey));  //parameter 2
}
Comment

PREVIOUS NEXT
Code Example
Java :: super class and concrete class in java 
Java :: java interview question answer 
Java :: what are construtcor java 
Java :: retrofit gradle 
Java :: how to create gravity in Java 
Java :: number pattern in java 
Java :: javalin pom 
Java :: reading data from wsdl in java 
Java :: adding matrix 
Java :: variables en java 
Java :: last resultset method 
Java :: format code netbean 
Java :: intellij evaluate expression 
Java :: could not initialize defaultkotlinsourcesetkt intelij 
Java :: Java Public Access Modifier package one 
Java :: ASCII PrintWriter java.io examples 
Java :: java assert keyword 
Java :: what is the types of intent in android java 
Java :: @column spring boot jpa 
Java :: Bad JNI version returned from JNI_OnLoad in 
Java :: Java how to handle HTTP GET request after establishing TCP connection 
Java :: string split to list java 
Java :: initialize generic array java 
Java :: java running sum 
Java :: how to search element in jtablejava 
Java :: reading txt file javafx 
Java :: Obtaining all data in a table with Hibernate 
Java :: what does import com.sun.glass do 
Java :: confirmation dialog android 
Java :: how to install java jdk 8 on ubuntu 20.04 for spark 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =