I am trying to figure out how to verify the sorting of time and/or a date using java and selenium. Here is my situation... So if I receive an email today, my Inbox displays the time the message was received. However if I received an email yesterday, the Inbox would display yesterday's date. I am trying to verify that in descending order, the emails with a time would appear first, followed by emails with dates.
Here is my code which works if there is only dates. Can someone please help me with figuring out how to verify the time as well?
protected void validateDateDescendingOrder(String className) {
// create a list
List<WebElement> messageElements = driver.findElements(By.cssSelector("div.scrollable-panel div." + className));
List<String> messageList = new ArrayList<String>();
for (WebElement element : messageElements) {
messageList.add(element.getText());
}
// create a new list and sort
List<String> sortedmessageList = new ArrayList<String>();
sortedmessageList.addAll(messageList);
Collections.sort(sortedmessageList, new Comparator<String>() {
DateFormat f = new SimpleDateFormat("MM/dd/yy");
@Override
public int compare(String o1, String o2) {
try {
return f.parse(o2).compareTo(f.parse(o1));
} catch (ParseException e) {
throw new IllegalArgumentException(e);
}
}
});
// compare the original list order with the sorted list to make sure they match
assertEquals(sortedmessageList, messageList);
}