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 :: random years java 
Java :: exit for loop java stack overflow 
Java :: how to make jframe full screen 
Java :: how to find the maximum value of an attribute of an item in a stream java 
Java :: cancel javafx stage exit request 
Java :: nsxt resource relationships in java 
Java :: Mirror Inverse Program in java 
Java :: xml cant change button background 
Java :: java memory cleaner 
Java :: Java (sun-jdk-1.8.0_51) sample 
Java :: Log exception details to string 
Java :: dependency maven mvn assertj asserting testing framework 
Java :: how to scroll down chrome browser in selenium java 
Java :: what is the process of mvvm in android 
Java :: How do you input numbers into an array? 
Java :: serilize filke in java 
Java :: java.lang.NullPointerException at org.openqa.selenium.support.pagefactory.findElement(DefaultElementLocator.java:69) 
Java :: run jar with logback config file 
Java :: ternärer operator java 
Java :: fab icon color 
Java :: Fast Search in java 
Java :: javafx.controls,javafx.fxml caused by: java.lang.classnotfoundexception: javafx.controls,javafx.fxml 
Java :: Dhttps.protocols=TLSv1.2 
Java :: determine the distance between two circles in java 
Java :: how do I change the opacity of a JButton 
Java :: java :: operator 
Java :: java polymorphism nedir 
Java :: java method exercises 
Java :: alert dialog not displayed android 
Java :: button event 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =