Pass Multiple data through Data Provider - Bug Reaper

                  Bug Reaper

Lean about Automation Testing,Selenium WebDriver,RestAssured,Appium,Jenkins,JAVA,API Automation,TestNG,Maven, Rest API, SOAP API,Linux,Maven,Security Testing,Interview Questions

Tuesday 6 February 2018

Pass Multiple data through Data Provider

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class myclass {

@DataProvider(name="my")
public Object[][] myprovider(){
return new Object[][] {{"one","ok","cool"},
{"two","",""},
{"three","",""}};
}
@Test(dataProvider="my")
public void hello(String here, String again,String cool ){
System.out.println("here is"+here);
System.out.println("again is"+again);
System.out.println("cool is"+cool);

}
}


Data Provider with List

import java.util.ArrayList;
import java.util.List;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class myclass {

@DataProvider(name="my")
public Object[][] myprovider(){
List<Integer> ls=new ArrayList<>();
ls.add(1);
ls.add(2);
ls.add(3);
return new Object[][] {{"one","ok","cool",ls},
{"two","","",ls},
{"three","","",ls}};
}
@Test(dataProvider="my")
public void hello(String here, String again,String cool, ArrayList<Integer> ls ){
System.out.println("here is"+here);
System.out.println("again is"+again);
System.out.println("cool is"+cool);
System.out.println("ls is"+ls);

}
}


Data Provider with HashMap
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class myclass {

@DataProvider(name="my")
public Object[][] myprovider(){
HashMap<String, String> hm=new HashMap<>();
hm.put("one", "1");
hm.put("two", "2");
return new Object[][] {{"one","ok","cool",hm},
{"two","","",hm},
{"three","","",hm}};
}
@Test(dataProvider="my")
public void hello(String here, String again,String cool, HashMap<String, String> hm  ){
System.out.println("here is"+here);
System.out.println("again is"+again);
System.out.println("cool is"+cool);

for(Map.Entry<String, String> entry:hm.entrySet()){
System.out.println("hm is"+entry.getKey());
System.out.println("hm is"+entry.getValue());

}

}
}

IN Below method No need to Call multiple Parameters

@DataProvider(name = "category")
public static Object[][]Jobs()
{
    return new Object[][]
            {
                    {"Cars", new String[]{"",""}},
                    {"Mobiles", new String[]{"",""}},
                    {"Electronics", new String[]{"",""}},
                    {"Entertainment", new String[]{"",""}},
                    {"Education", new String[]{"",""}},
                    {"Pets", new String[]{"",""}},
                    {"Matrimonial", new String[]{"",""}},
                    {""}
            };
}

Use Data Provider

@Test(dataProvider = "", dataProviderClass = Data.class)
public void test(String cat, String[] subCat)
{

}



No comments:

Post a Comment