Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Appium中,我尝试从元素名称按字母顺序排列名字和姓氏时出错_Java_Selenium_Appium - Fatal编程技术网

Java 在Appium中,我尝试从元素名称按字母顺序排列名字和姓氏时出错

Java 在Appium中,我尝试从元素名称按字母顺序排列名字和姓氏时出错,java,selenium,appium,Java,Selenium,Appium,我有3个元素,它们有3个名字和姓氏,这是一个按钮。我需要弄清楚如何检查它们是否先按名字排序,然后按姓氏排序。元素的页面对象是ListV_排序的。我想我只是按名字元素排序。0个元素=杰克·丹尼尔斯,1个元素=约翰·费拉,2个元素=迈克·杜洛夫。ListV是元素的页面对象。它说预期为真,但发现为假 //验证AP名称是否按字母顺序排序 @抑制警告(“未选中”) 公共无效排序令(){ Log.Log(driver.info)(“即将进行Alphebetically排序”); 列出产品_MobileEle

我有3个元素,它们有3个名字和姓氏,这是一个按钮。我需要弄清楚如何检查它们是否先按名字排序,然后按姓氏排序。元素的页面对象是ListV_排序的。我想我只是按名字元素排序。0个元素=杰克·丹尼尔斯,1个元素=约翰·费拉,2个元素=迈克·杜洛夫。ListV是元素的页面对象。它说预期为真,但发现为假

//验证AP名称是否按字母顺序排序 @抑制警告(“未选中”) 公共无效排序令(){

Log.Log(driver.info)(“即将进行Alphebetically排序”);
列出产品_MobileElements=newlinkedlist();
产品/移动设备=(列表)票证组件;
LinkedList产品名称=新LinkedList();
对于(int i=0;i 0){
firstName=tokens[0];
lastName=tokens[tokens.length-1];
产品名称。添加;
产品名称。添加(名字);
产品名称。添加(姓氏);
}
}
布尔结果=检查字母顺序(产品名称);
Assert.assertEquals(检查字母顺序(产品名称),true);
Log.Log(driver.info)(“票证通行证名称按字母顺序排列”);
系统输出打印项次(结果);
}
//方法接受按字母顺序排序的字符串
公共静态布尔检查字母顺序(LinkedList产品名称){
字符串previous=”“;//空字符串
for(当前最终字符串:产品名称){
如果(当前与上一个相比)<0
返回false;
先前=当前;
}
返回true;
}

你能把System.out.println(current+“”+previous)放进去检查打印的内容吗?它有助于调试current和previous给我错误的语句。它如何通过测试。for(最终字符串current:product_names){if(current.compareTo(previous)<0)返回false;previous=current;System.out.println(current);System.out.println(previous);}返回true;你能把System.out.println(current+“”+previous)放进去检查打印的内容吗?它有助于调试current和previous给我错误的语句。它如何通过测试。for(最终字符串current:product_names){if(current.compareTo(previous)<0)返回false;previous=current;System.out.println(current);System.out.println(previous);}返回true;
      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;

            }