Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Java TestNG Data provider Provider with multiple variables

// 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 :: arraylistof objects 
Java :: trémaux’ method java 
Java :: 111111000 
Java :: how to refresh activity intent in android 
Java :: Example of ArrayDeque 
Java :: bukkit detect block that nowbal hit 
Java :: system.out.println(h [2] [1] [1] [0]); 
Java :: java code file 
Java :: hibernate getList of a table 
Java :: java isalphanum 
Java :: how to take input an array in java 
Java :: how to get map with string as key and Arraylist as value in java 
Java :: quadratic program 
Java :: correct lcd initialize 
Java :: Which Is Better to Configure a Spring Boot Project — Properties or YAML? 
Java :: how to use protobuf in java 
Java :: run java in cmd 
Java :: /= java 
Java :: remove part of string java 
Java :: matrix rotation in java 
Java :: what is operator overloading in java 
Java :: how to make 2d array of strings in java 
Java :: number of digits program in java 
Java :: how to create a derived class in Java 
Java :: int in string umwandeln 
Java :: partioning operation Java 
Sql :: stop mysql service ubuntu 
Sql :: guid to string sql 
Sql :: drop stored procedure mysql 
Sql :: sql server conection string 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =