我有3个元素,他们有3个名字,姓氏是一个按钮。我需要弄清楚如何检查它们是按名字排序,然后按姓氏排序。元素的页面对象是ListV_Sorted。我想我只是按名字元素排序。 0元素= Jack Daniels,1元素= John Fera,2元素= Mike Durov。 ListV是元素的页面对象。它说预期是真的,但发现是假的。
//验证AP名称是否按字母顺序排序 @SuppressWarnings("未选中&#34) public void sortingOrder(){
Log.log(driver).info("About to Alphebetically Sort");
List<MobileElement> products_MobileElements = new LinkedList<MobileElement>();
products_MobileElements = (List<MobileElement>) TicketPassesNames;
LinkedList<String> product_names = new LinkedList<String>();
for(int i=0;i<products_MobileElements.size();i++){
String s = products_MobileElements.get(i).getAttribute("checked");
String[] tokens = s.split("");
String firstName = "";
String lastName = "";
if(tokens.length > 0) {
firstName = tokens[0];
lastName = tokens[tokens.length -1];
product_names.add(s);
product_names.add(firstName);
product_names.add(lastName);
}
}
boolean result = checkAlphabeticalOrder(product_names);
Assert.assertEquals(checkAlphabeticalOrder(product_names), true);
Log.log(driver).info("Tickest Passes names are in alphabetical order.");
System.out.println(result);
}
//Method takes a String to Sort AlphabeticalLy
public static boolean checkAlphabeticalOrder(LinkedList<String> product_names){
String previous = ""; // empty string
for (final String current: product_names) {
if (current.compareTo(previous) < 0)
return false;
previous = current;
}
return true;
}