parent
bcea1f67ef
commit
dc27b500ad
|
@ -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 + "】";
|
||||
|
|
|
@ -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 2017年12月1日 上午9:29:40
|
||||
*/
|
||||
|
@ -22,6 +26,7 @@ public class ChangString {
|
|||
|
||||
/**
|
||||
* 替换变量中的字符
|
||||
*
|
||||
* @param str
|
||||
* @param variable
|
||||
* @param changname
|
||||
|
@ -41,18 +46,37 @@ public class ChangString {
|
|||
if (varcount > 0) {
|
||||
luckyclient.publicclass.LogUtil.APP.info("在" + changname + "【" + str + "】中找到" + varcount + "个可替换参数");
|
||||
int changcount = 0;
|
||||
|
||||
// 准备将HASHMAP换成LINKMAP,对KEY进行排序,解决要先替换最长KEY的问题
|
||||
List<Map.Entry<String, String>> list = new ArrayList<Map.Entry<String, String>>(variable.entrySet());
|
||||
// 然后通过比较器来实现排序
|
||||
Collections.sort(list, new Comparator<Map.Entry<String, String>>() {
|
||||
// 按KEY长度降序排序
|
||||
public int compare(Entry<String, String> o1, Entry<String, String> o2) {
|
||||
return o2.getKey().length() - o1.getKey().length();
|
||||
}
|
||||
});
|
||||
|
||||
Map<String, String> aMap2 = new LinkedHashMap<String, String>();
|
||||
for (Map.Entry<String, String> mapping : list) {
|
||||
aMap2.put(mapping.getKey(), mapping.getValue());
|
||||
}
|
||||
|
||||
// 从参数列表中查找匹配变量
|
||||
for (Map.Entry<String, String> entry : variable.entrySet()) {
|
||||
for (Map.Entry<String, String> 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("\\\\\'", "\\\\'"));
|
||||
// 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() + "】");
|
||||
luckyclient.publicclass.LogUtil.APP
|
||||
.info("将" + changname + "引用变量【@" + entry.getKey() + "】替换成值【" + entry.getValue() + "】");
|
||||
str = str.replace("////CHANG////", "@@" + entry.getKey());
|
||||
changcount = changcount + viewcount;
|
||||
}
|
||||
|
@ -75,6 +99,7 @@ public class ChangString {
|
|||
|
||||
/**
|
||||
* 统计字符
|
||||
*
|
||||
* @param str1
|
||||
* @param str2
|
||||
* @return
|
||||
|
@ -94,6 +119,7 @@ public class ChangString {
|
|||
|
||||
/**
|
||||
* 判断是否是数字
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
|
@ -108,6 +134,7 @@ public class ChangString {
|
|||
|
||||
/**
|
||||
* 判断是否是整数
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
|
@ -118,6 +145,7 @@ public class ChangString {
|
|||
|
||||
/**
|
||||
* 替换变量类型
|
||||
*
|
||||
* @param object
|
||||
* @param str
|
||||
* @return
|
||||
|
@ -142,6 +170,7 @@ public class ChangString {
|
|||
|
||||
/**
|
||||
* 替换json中的变量
|
||||
*
|
||||
* @param json
|
||||
* @param key
|
||||
* @param value
|
||||
|
@ -158,7 +187,8 @@ public class ChangString {
|
|||
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);
|
||||
|
@ -185,7 +215,8 @@ public class ChangString {
|
|||
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);
|
||||
return map;
|
||||
|
|
Loading…
Reference in New Issue