Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Java TestNG Data Provider example

// 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 :: pass data to layout from navigation android studio 
Java :: " meaning in java 
Java :: save file to disk java 
Java :: what does system.out.println(y + " ") result 
Java :: Reconstruct Binary Tree With Levelorder And Inorder leetcode 
Java :: jdsu software download 
Java :: convert code from kotlin to java 
Java :: kingkaihockey 
Java :: exoplayer how to put loader while video is still loading android java 
Java :: Algorithms - sum 
Java :: set java time complexity 
Java :: what is a callable in java 
Java :: location.href webview android studio 
Java :: bukkit api listener 
Java :: influx cli with docker container 
Java :: unirest javafx 
Java :: exchangerate api 
Java :: format string precision double java 
Java :: java scanner class time 
Java :: how to install openjdk 16 
Java :: adding prefix zeros 
Java :: do i have to import files from the same package in java 
Java :: how to know what a valid name for a variable is in java 
Java :: re-loop after last item in array java 
Java :: anulom vilom in english 
Java :: ex javaloop 
Java :: android studio press button programmatically 
Java :: java blocks 
Java :: android prevent screen from turning off programmatically 
Java :: setUndecorated java 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =