From dc27b500ad16d7abf175c4caaf4e14f7576dceed Mon Sep 17 00:00:00 2001 From: seagull <24163551@qq.com> Date: Fri, 14 Sep 2018 10:53:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=A7=E8=A1=8C=E5=AE=89?= =?UTF-8?q?=E5=8D=93adb=E5=91=BD=E4=BB=A4=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复公共参数中,KEY值前N个字符一样,导致替换值不对的BUG --- .../AndroidEncapsulateOperation.java | 7 +- .../luckyclient/publicclass/ChangString.java | 311 ++++++++++-------- 2 files changed, 177 insertions(+), 141 deletions(-) diff --git a/src/main/java/luckyclient/caserun/exappium/androidex/AndroidEncapsulateOperation.java b/src/main/java/luckyclient/caserun/exappium/androidex/AndroidEncapsulateOperation.java index 595b994..0bff26e 100644 --- a/src/main/java/luckyclient/caserun/exappium/androidex/AndroidEncapsulateOperation.java +++ b/src/main/java/luckyclient/caserun/exappium/androidex/AndroidEncapsulateOperation.java @@ -196,8 +196,13 @@ public class AndroidEncapsulateOperation { result = "ִJS..." + operationValue + ""; luckyclient.publicclass.LogUtil.APP.info("ִJS..." + operationValue + ""); break; - // ģֻ + case "exAdbShell": + Runtime.getRuntime().exec(operationValue); + result = "ִа׿adb..." + operationValue + ""; + luckyclient.publicclass.LogUtil.APP.info("ִа׿adb..." + operationValue + ""); + break; case "keycode": + // ģֻ if (ChangString.isNumeric(operationValue)) { appium.pressKeyCode(Integer.valueOf(operationValue)); result = "ģ̷ָֻ...keycode" + operationValue + ""; diff --git a/src/main/java/luckyclient/publicclass/ChangString.java b/src/main/java/luckyclient/publicclass/ChangString.java index 345f654..ce5e9b2 100644 --- a/src/main/java/luckyclient/publicclass/ChangString.java +++ b/src/main/java/luckyclient/publicclass/ChangString.java @@ -1,8 +1,14 @@ package luckyclient.publicclass; import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.regex.Pattern; import com.alibaba.fastjson.JSONArray; @@ -11,10 +17,8 @@ import com.alibaba.fastjson.JSONObject; /** * ================================================================= * һƵκδǰ¶Գ޸ĺҵ;ҲԳ޸ĺκʽκĿĵٷ - * ΪߵͶɹLuckyFrameؼȨϢϽ۸ - * κʻӭϵۡ QQ:1573584944 seagull1985 + * ΪߵͶɹLuckyFrameؼȨϢϽ۸ κʻӭϵۡ QQ:1573584944 seagull1985 * ================================================================= - * * @author seagull * @date 2017121 9:29:40 */ @@ -22,180 +26,207 @@ public class ChangString { /** * 滻еַ + * * @param str * @param variable * @param changname * @return */ - public static String changparams(String str, Map variable, String changname) { - try { - if (null == str) { - return null; - } - str = str.replace(""", "\""); - str = str.replace("'", "\'"); - //@@ע@ - int varcount = counter(str, "@") - counter(str, "@@") * 2; + public static String changparams(String str, Map variable, String changname) { + try { + if (null == str) { + return null; + } + str = str.replace(""", "\""); + str = str.replace("'", "\'"); + // @@ע@ + int varcount = counter(str, "@") - counter(str, "@@") * 2; - //ڴΣд - if (varcount > 0) { - luckyclient.publicclass.LogUtil.APP.info("" + changname + "" + str + "ҵ" + varcount + "滻"); - int changcount = 0; - //Ӳбвƥ - for (Map.Entry entry : variable.entrySet()) { - if (str.contains("@" + entry.getKey())) { - if (str.contains("@@" + entry.getKey())) { - str = str.replace("@@" + entry.getKey(), "////CHANG////"); - } - //滻ַд\"\'ᵼ\ʧ - //entry.setValue(entry.getValue().replaceAll("\\\\\"", "\\"")); - //entry.setValue(entry.getValue().replaceAll("\\\\\'", "\\\\'")); - int viewcount = counter(str, "@" + entry.getKey()); - str = str.replace("@" + entry.getKey(), entry.getValue()); - luckyclient.publicclass.LogUtil.APP.info("" + changname + "ñ@" + entry.getKey() + "滻ֵ" + entry.getValue() + ""); - str = str.replace("////CHANG////", "@@" + entry.getKey()); - changcount = changcount + viewcount; - } - } + // ڴΣд + if (varcount > 0) { + luckyclient.publicclass.LogUtil.APP.info("" + changname + "" + str + "ҵ" + varcount + "滻"); + int changcount = 0; - if (varcount != changcount) { - luckyclient.publicclass.LogUtil.APP.error(changname + "ñδڲҵ飡" + str + ""); - } - } - str = str.replace("@@", "@"); - //ַָд\"\'ᵼ\ʧ - //str = str.replaceAll("\\"", "\\\\\""); - //str = str.replaceAll("\\'", "\\\\\'"); - return str; - } catch (Exception e) { - e.printStackTrace(); - return ""; - } - } + // ׼HASHMAPLINKMAPKEY򣬽Ҫ滻KEY + List> list = new ArrayList>(variable.entrySet()); + // ȻͨȽʵ + Collections.sort(list, new Comparator>() { + // KEYȽ + public int compare(Entry o1, Entry o2) { + return o2.getKey().length() - o1.getKey().length(); + } + }); - /** - * ͳַ - * @param str1 - * @param str2 - * @return - */ - public static int counter(String str1, String str2) { - int total = 0; - for (String tmp = str1; tmp != null && tmp.length() >= str2.length(); ) { - if (tmp.indexOf(str2) == 0) { - total++; - tmp = tmp.substring(str2.length()); - } else { - tmp = tmp.substring(1); - } - } - return total; - } + Map aMap2 = new LinkedHashMap(); + for (Map.Entry mapping : list) { + aMap2.put(mapping.getKey(), mapping.getValue()); + } - /** - * жǷ - * @param str - * @return - */ - public static boolean isNumeric(String str) { - for (int i = 0; i < str.length(); i++) { - if (!Character.isDigit(str.charAt(i))) { - return false; - } - } - return true; - } + // Ӳбвƥ + for (Map.Entry entry : aMap2.entrySet()) { + if (str.contains("@" + entry.getKey())) { + if (str.contains("@@" + entry.getKey())) { + str = str.replace("@@" + entry.getKey(), "////CHANG////"); + } + // 滻ַд\"\'ᵼ\ʧ + // entry.setValue(entry.getValue().replaceAll("\\\\\"", + // "\\"")); + // entry.setValue(entry.getValue().replaceAll("\\\\\'", + // "\\\\'")); + int viewcount = counter(str, "@" + entry.getKey()); + str = str.replace("@" + entry.getKey(), entry.getValue()); + luckyclient.publicclass.LogUtil.APP + .info("" + changname + "ñ@" + entry.getKey() + "滻ֵ" + entry.getValue() + ""); + str = str.replace("////CHANG////", "@@" + entry.getKey()); + changcount = changcount + viewcount; + } + } - /** - * жǷ - * @param str - * @return - */ - public static boolean isInteger(String str) { - Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); - return pattern.matcher(str).matches(); - } + if (varcount != changcount) { + luckyclient.publicclass.LogUtil.APP.error(changname + "ñδڲҵ飡" + str + ""); + } + } + str = str.replace("@@", "@"); + // ַָд\"\'ᵼ\ʧ + // str = str.replaceAll("\\"", "\\\\\""); + // str = str.replaceAll("\\'", "\\\\\'"); + return str; + } catch (Exception e) { + e.printStackTrace(); + return ""; + } + } - /** - * 滻 - * @param object - * @param str - * @return - */ - public static Object settype(Object object,String str){ - if(object instanceof Integer){ - return Integer.valueOf(str); - }else if(object instanceof Boolean){ - return Boolean.valueOf(str); - }else if(object instanceof Long){ - return Long.valueOf(str); - }else if(object instanceof Timestamp){ - return Timestamp.valueOf(str); - }else if(object instanceof JSONObject){ - return JSONObject.parseObject(str); - }else if(object instanceof JSONArray){ - return JSONArray.parseArray(str); - }else{ - return str; - } - } - - /** - * 滻jsonеı - * @param json - * @param key - * @param value - * @return - */ - public static Map changjson(String json, String key, String value) { - Map map=new HashMap(0); + /** + * ͳַ + * + * @param str1 + * @param str2 + * @return + */ + public static int counter(String str1, String str2) { + int total = 0; + for (String tmp = str1; tmp != null && tmp.length() >= str2.length();) { + if (tmp.indexOf(str2) == 0) { + total++; + tmp = tmp.substring(str2.length()); + } else { + tmp = tmp.substring(1); + } + } + return total; + } + + /** + * жǷ + * + * @param str + * @return + */ + public static boolean isNumeric(String str) { + for (int i = 0; i < str.length(); i++) { + if (!Character.isDigit(str.charAt(i))) { + return false; + } + } + return true; + } + + /** + * жǷ + * + * @param str + * @return + */ + public static boolean isInteger(String str) { + Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); + return pattern.matcher(str).matches(); + } + + /** + * 滻 + * + * @param object + * @param str + * @return + */ + public static Object settype(Object object, String str) { + if (object instanceof Integer) { + return Integer.valueOf(str); + } else if (object instanceof Boolean) { + return Boolean.valueOf(str); + } else if (object instanceof Long) { + return Long.valueOf(str); + } else if (object instanceof Timestamp) { + return Timestamp.valueOf(str); + } else if (object instanceof JSONObject) { + return JSONObject.parseObject(str); + } else if (object instanceof JSONArray) { + return JSONArray.parseArray(str); + } else { + return str; + } + } + + /** + * 滻jsonеı + * + * @param json + * @param key + * @param value + * @return + */ + public static Map changjson(String json, String key, String value) { + Map map = new HashMap(0); map.put("boolean", "false"); map.put("json", json); if (json.startsWith("{") && json.endsWith("}")) { try { JSONObject jsonStr = JSONObject.parseObject(json); - if(jsonStr.containsKey(key)){ - jsonStr.put(key, settype(jsonStr.get(key),value)); + if (jsonStr.containsKey(key)) { + jsonStr.put(key, settype(jsonStr.get(key), value)); map.put("boolean", "true"); map.put("json", jsonStr.toJSONString()); - luckyclient.publicclass.LogUtil.APP.info("JSONַ滻ɹԭʼJSON:"+json+" JSON:"+jsonStr.toJSONString()+""); + luckyclient.publicclass.LogUtil.APP + .info("JSONַ滻ɹԭʼJSON:" + json + " JSON:" + jsonStr.toJSONString() + ""); } } catch (Exception e) { - luckyclient.publicclass.LogUtil.APP.error("ʽJSON쳣"+json,e); + luckyclient.publicclass.LogUtil.APP.error("ʽJSON쳣" + json, e); return map; } } else if (json.startsWith("[") && json.endsWith("]")) { try { JSONArray jsonarr = JSONArray.parseArray(json); - JSONObject jsonStr=new JSONObject(); - int index=0; - if(key.indexOf("[")>=0 && key.endsWith("]")){ - index=Integer.valueOf(key.substring(key.lastIndexOf("[")+1,key.lastIndexOf("]"))); - key=key.substring(0, key.lastIndexOf("[")); - jsonStr = jsonarr.getJSONObject(index); - luckyclient.publicclass.LogUtil.APP.info("׼滻JSONArrayеIJֵδ⵽ָţĬ滻1..."); - }else{ + JSONObject jsonStr = new JSONObject(); + int index = 0; + if (key.indexOf("[") >= 0 && key.endsWith("]")) { + index = Integer.valueOf(key.substring(key.lastIndexOf("[") + 1, key.lastIndexOf("]"))); + key = key.substring(0, key.lastIndexOf("[")); jsonStr = jsonarr.getJSONObject(index); - luckyclient.publicclass.LogUtil.APP.info("׼滻JSONArrayеIJֵ滻ָ"+index+"..."); + luckyclient.publicclass.LogUtil.APP.info("׼滻JSONArrayеIJֵδ⵽ָţĬ滻1..."); + } else { + jsonStr = jsonarr.getJSONObject(index); + luckyclient.publicclass.LogUtil.APP.info("׼滻JSONArrayеIJֵ滻ָ" + index + "..."); } - - if(jsonStr.containsKey(key)){ - jsonStr.put(key, settype(jsonStr.get(key),value)); + + if (jsonStr.containsKey(key)) { + jsonStr.put(key, settype(jsonStr.get(key), value)); jsonarr.set(index, jsonStr); map.put("boolean", "true"); map.put("json", jsonarr.toJSONString()); } - luckyclient.publicclass.LogUtil.APP.info("JSONARRAYַ滻ɹԭʼJSONARRAY:"+json+" JSONARRAY:"+jsonarr.toJSONString()+""); + luckyclient.publicclass.LogUtil.APP.info( + "JSONARRAYַ滻ɹԭʼJSONARRAY:" + json + " JSONARRAY:" + jsonarr.toJSONString() + ""); } catch (Exception e) { - luckyclient.publicclass.LogUtil.APP.error("ʽJSONArray쳣"+json,e); + luckyclient.publicclass.LogUtil.APP.error("ʽJSONArray쳣" + json, e); return map; } } return map; } - - public static void main(String[] args) { - } + public static void main(String[] args) { + + } }