//Get all the mobile phones links into a list before sorting
List<WebElement> mobilelinks=driver.findElements(("locator"));
Map maps = new LinkedHashMap();//use linked hash map as it preserves the insertion order
for(int i=0;i<mobilelinks.size();i++){
//store the name and price as key value pair in map
maps.put("mobilelinks.get(i).getAttribute('name')","mobilelinks.get(i).getAttribute('price')" );
}
/*sort the map based on keys(names) store it in a separate list
sort the map based on values(prices) store it in a separate list
*/
/* Using webdriver click the sort by name and compare it with the list which we got after sorting
and also click sort by prices and compare it with the list*/
--------------------------------------------------------------------------------------------------------------------
package com.readExcelFile;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
public class HashMapExample {
public static List<String> getKey() {
List<String> key = new ArrayList<>();
key.add("Amrit");
key.add("Amrit1");
return key;
}
public static List<String> getValue() {
List<String> value = new ArrayList<>();
value.add("Upadhyay");
value.add("Upadhyay1");
return value;
}
public static void getKeyValuePair() {
List<String> keyList = getKey();
List<String> valueList = getValue();
HashMap<List<String>, List<String>> hm = new HashMap();
hm.put(keyList, valueList);
for (Map.Entry<List<String>, List<String>> map : hm.entrySet()) {
System.out.println(map.getKey());
System.out.println(map.getValue());
}
}
public static void main(String[] args) {
getKeyValuePair();
}
}
No comments:
Post a Comment