vendredi 23 mars 2018

How can I return an Iterator over a List of Mappings

The method looks like this. I just want to return an Object[] or an Object[][] or an Iterator< Object[]> with each row containing one of the three mappings that are created in for loop. I need all fields (category, usage, country) to be sent together.

@DataProvider(name = "NewListings")
public Iterator<Object[]> AddNewListings(){
    List<Map<String,String>> listings = new ArrayList<Map<String,String>>();
    Map<String,String> listing = new HashMap<String, String>();
    Random rand = new Random();

    for (int i=0;i<3;i++){
        listing.put("category", Integer.toString(rand.nextInt(8)+1));
        listing.put("usage", Integer.toString(rand.nextInt(8)+1));
        listing.put("country", Integer.toString(rand.nextInt(8)+1));

        listings.add(listing);
        listing.clear();
    }
    return something;
}

@Test(dataProvider = "NewListings")
public void addListing(Map<String, String> field){
    //do stuff
}

Aucun commentaire:

Enregistrer un commentaire