I have written a code to fetch the value from a table and place it in a map with a key-value pair and return the map.
public Map<String, BigDecimal> fnFetchCartSummary() throws Exception {
Map<String, BigDecimal> mCartSummaryMap = new HashedMap<String, BigDecimal>();
int iCartCount = client.getElementCount(CartTotal);
if (iCartCount > 1) {
client.ValidateTest(true, "Service charges are getting displayed for Cart. Total entries = " + iCartCount);
for (int i = 1; i <= iCartCount; i++) {
String sVariablexpath = sRowKey.replaceAll("<REPLACE>", Integer.toString(i));
String sVariableName = client.getText(sVariablexpath).replace(":", "");
String sCharges = RowValue.replaceAll("<REPLACE>", Integer.toString(i));
double sPrice =Double.parseDouble( client.getText(sCharges).replaceAll("[^0-9.]+", ""));
BigDecimal bdPrice = new BigDecimal(sPrice);
mCartSummaryMap.put(sVariableName, bdPrice);
}
}
return mCartSummaryMap;
}
This will return the Map with values like this
{MPVPERTKTF=10, Subtotal=1200, MPVEVTF=15, Total Amount Due=1227, MPV SC001 SPD=2}
But when I trying to catch the same map and trying to get the value from it.
Map<String, BigDecimal> mCartValue1 = client.shoppingCart.fnFetchCartSummary();
BigDecimal Subtotal1_1 = mCartValue1.get("Subtotal");
System.out.println(Subtotal1_1);
It will show null to every key-value pair like this
null
If anyone comes across the same issue please suggest me a solution.🙁
mCartValue1contains? (Or simply print it out)System.out.println(mCartValue1);on the line right beforeBigDecimal Subtotal1_1 = mCartValue1.get("Subtotal");and add it to your post