Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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 :: the crystallization in time is the phenomenon that we call synchronization 
Java :: image show by timer android studio 
Java :: return string consistent of n lowercase letters such is all letters occurs an odd number 
Java :: sha1 
Java :: springboot request list 
Java :: cgange background from button click java fx 
Java :: Java Remove Elements 
Java :: what is collection fromework 
Java :: mysqld always running 
Java :: difference between compile and execute in java 
Java :: retrofit with api key post 
Java :: @exceptionhandler spring boot annotation not found 
Java :: HOW TO CODE WORKING PLUGIN IN MINECRAFT 
Java :: sort a list according to location 
Java :: The root directory of the External Storage on every android version 
Java :: anulom vilom in english 
Java :: android studio call on a string 
Java :: how to avoid outside click of alerdialoge android 
Java :: repository null when testing service 
Java :: difference between string vs stringbuffer 
Java :: Simple java questionnaire using json 
Java :: run app by package android 
Java :: geometric primitive 
Java :: How to handle exception if message lost during publishing to kafka 
Java :: list to vector java 
Java :: open application programelly android studio 
Java :: springboot getting body value 
Java :: what does put extra do? 
Java :: bakht k takht sy yaklakht utara hwa shaks tuny dekha hai kbi jeet k hara hwa shaks in urdu 
Java :: codegrepper java instanceof 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =