根据IDEA提示全面优化代码
This commit is contained in:
parent
6974d06d77
commit
60f7a1947e
|
@ -1,37 +1,49 @@
|
||||||
package luckyclient.driven;
|
package luckyclient.driven;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import luckyclient.utils.DbOperation;
|
import luckyclient.utils.DbOperation;
|
||||||
import luckyclient.utils.config.DrivenConfig;
|
import luckyclient.utils.config.DrivenConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提供数据库查询操作的默认测试驱动
|
* 提供数据库查询操作的默认测试驱动
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2020年2月17日
|
* @date 2020年2月17日
|
||||||
*/
|
*/
|
||||||
public class DbDriven {
|
public class DbDriven {
|
||||||
|
|
||||||
public String executeSql(String sql) throws Exception{
|
/**
|
||||||
Properties properties = DrivenConfig.getConfiguration();
|
* 执行SQL语句
|
||||||
String url = properties.getProperty("db.url");
|
* @param sql 执行SQL语句
|
||||||
String username = properties.getProperty("db.username");
|
* @return 返回执行结果条数才及提示
|
||||||
String password = properties.getProperty("db.password");
|
* @throws Exception 抛异常
|
||||||
DbOperation db=new DbOperation(url,username,password);
|
*/
|
||||||
return db.executeQuery(sql);
|
public String executeSql(String sql) throws Exception{
|
||||||
}
|
Properties properties = DrivenConfig.getConfiguration();
|
||||||
|
String url = properties.getProperty("db.url");
|
||||||
public String executeQuery(String sql) throws Exception{
|
String username = properties.getProperty("db.username");
|
||||||
Properties properties = DrivenConfig.getConfiguration();
|
String password = properties.getProperty("db.password");
|
||||||
String url = properties.getProperty("db.url");
|
DbOperation db=new DbOperation(url,username,password);
|
||||||
String username = properties.getProperty("db.username");
|
return db.executeSql(sql);
|
||||||
String password = properties.getProperty("db.password");
|
}
|
||||||
DbOperation db=new DbOperation(url,username,password);
|
|
||||||
return db.executeQuery(sql);
|
/**
|
||||||
}
|
* 查询SQL语句
|
||||||
|
* @param sql 查询SQL
|
||||||
}
|
* @return 返回查询结果
|
||||||
|
* @throws Exception 异常信息
|
||||||
|
*/
|
||||||
|
public String executeQuery(String sql) throws Exception{
|
||||||
|
Properties properties = DrivenConfig.getConfiguration();
|
||||||
|
String url = properties.getProperty("db.url");
|
||||||
|
String username = properties.getProperty("db.username");
|
||||||
|
String password = properties.getProperty("db.password");
|
||||||
|
DbOperation db=new DbOperation(url,username,password);
|
||||||
|
return db.executeQuery(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package luckyclient.driven;
|
package luckyclient.driven;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -32,10 +33,10 @@ public class SubString {
|
||||||
/**
|
/**
|
||||||
* 截取指定字符串的中间字段
|
* 截取指定字符串的中间字段
|
||||||
*
|
*
|
||||||
* @param str
|
* @param str 原始字符串
|
||||||
* @param startstr
|
* @param startstr 开始字符
|
||||||
* @param endstr
|
* @param endstr 结束字符
|
||||||
* @return
|
* @return 返回字符串截取结果
|
||||||
*/
|
*/
|
||||||
public static String subCentreStr(String str, String startstr, String endstr) {
|
public static String subCentreStr(String str, String startstr, String endstr) {
|
||||||
try{
|
try{
|
||||||
|
@ -47,8 +48,7 @@ public class SubString {
|
||||||
if(!"".equals(endstr)){
|
if(!"".equals(endstr)){
|
||||||
endnum=str.indexOf(endstr, str.indexOf(startstr) + startstr.length());
|
endnum=str.indexOf(endstr, str.indexOf(startstr) + startstr.length());
|
||||||
}
|
}
|
||||||
String getstr = str.substring(startnum,endnum);
|
return str.substring(startnum,endnum);
|
||||||
return getstr;
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
LogUtil.APP.error("subCentreStr截取字符串出现异常,请检查参数!",e);
|
LogUtil.APP.error("subCentreStr截取字符串出现异常,请检查参数!",e);
|
||||||
return "截取字符串出现异常,请检查参数!";
|
return "截取字符串出现异常,请检查参数!";
|
||||||
|
@ -58,14 +58,13 @@ public class SubString {
|
||||||
/**
|
/**
|
||||||
* 截取字符串从指定字符开始
|
* 截取字符串从指定字符开始
|
||||||
*
|
*
|
||||||
* @param str
|
* @param str 原始字符
|
||||||
* @param startstr
|
* @param startstr 开始字符
|
||||||
* @return
|
* @return 返回字符串截取结果
|
||||||
*/
|
*/
|
||||||
public static String subStartStr(String str, String startstr) {
|
public static String subStartStr(String str, String startstr) {
|
||||||
try{
|
try{
|
||||||
String getstr = str.substring(str.indexOf(startstr) + startstr.length());
|
return str.substring(str.indexOf(startstr) + startstr.length());
|
||||||
return getstr;
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
LogUtil.APP.error("subStartStr截取字符串出现异常,请检查参数!",e);
|
LogUtil.APP.error("subStartStr截取字符串出现异常,请检查参数!",e);
|
||||||
return "截取字符串出现异常,请检查参数!";
|
return "截取字符串出现异常,请检查参数!";
|
||||||
|
@ -75,14 +74,13 @@ public class SubString {
|
||||||
/**
|
/**
|
||||||
* 截取字符串到指定字符结束
|
* 截取字符串到指定字符结束
|
||||||
*
|
*
|
||||||
* @param str
|
* @param str 原始字符
|
||||||
* @param endstr
|
* @param endstr 结束字符
|
||||||
* @return
|
* @return 返回字符串截取结果
|
||||||
*/
|
*/
|
||||||
public static String subEndStr(String str, String endstr) {
|
public static String subEndStr(String str, String endstr) {
|
||||||
try{
|
try{
|
||||||
String getstr = str.substring(0, str.indexOf(endstr));
|
return str.substring(0, str.indexOf(endstr));
|
||||||
return getstr;
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
LogUtil.APP.error("subEndStr截取字符串出现异常,请检查参数!",e);
|
LogUtil.APP.error("subEndStr截取字符串出现异常,请检查参数!",e);
|
||||||
return "截取字符串出现异常,请检查参数!";
|
return "截取字符串出现异常,请检查参数!";
|
||||||
|
@ -92,13 +90,13 @@ public class SubString {
|
||||||
/**
|
/**
|
||||||
* 通过字符串位置截取指定字符串的中间字段
|
* 通过字符串位置截取指定字符串的中间字段
|
||||||
*
|
*
|
||||||
* @param str
|
* @param str 原始字符
|
||||||
* @param startnum
|
* @param startnum 开始字符位置
|
||||||
* @param endnum
|
* @param endnum 结果位置
|
||||||
* @return
|
* @return 返回字符串截取结果
|
||||||
*/
|
*/
|
||||||
public static String subCentreNum(String str, String startnum, String endnum) {
|
public static String subCentreNum(String str, String startnum, String endnum) {
|
||||||
String getstr = "";
|
String getstr;
|
||||||
if("".equals(startnum)){
|
if("".equals(startnum)){
|
||||||
startnum="0";
|
startnum="0";
|
||||||
}
|
}
|
||||||
|
@ -107,11 +105,11 @@ public class SubString {
|
||||||
}
|
}
|
||||||
try{
|
try{
|
||||||
if (isInteger(startnum) && isInteger(endnum)) {
|
if (isInteger(startnum) && isInteger(endnum)) {
|
||||||
int start = Integer.valueOf(startnum);
|
int start = Integer.parseInt(startnum);
|
||||||
int end = Integer.valueOf(endnum);
|
int end = Integer.parseInt(endnum);
|
||||||
if (start > end) {
|
if (start > end) {
|
||||||
getstr = "截取字符串开始位置数字不能大于结束位置数字";
|
getstr = "截取字符串开始位置数字不能大于结束位置数字";
|
||||||
} else if (start < 0 || end < 0) {
|
} else if (start < 0) {
|
||||||
getstr = "截取字符串位置的数字不能小于0";
|
getstr = "截取字符串位置的数字不能小于0";
|
||||||
} else if (start > str.length() || end > str.length()) {
|
} else if (start > str.length() || end > str.length()) {
|
||||||
getstr = "截取字符串位置的数字不能大于字符串本身的长度【" + str.length() + "】";
|
getstr = "截取字符串位置的数字不能大于字符串本身的长度【" + str.length() + "】";
|
||||||
|
@ -132,15 +130,15 @@ public class SubString {
|
||||||
/**
|
/**
|
||||||
* 通过字符串位置截取字符串从指定字符开始
|
* 通过字符串位置截取字符串从指定字符开始
|
||||||
*
|
*
|
||||||
* @param str
|
* @param str 原始字符
|
||||||
* @param startnum
|
* @param startnum 字符开始位置
|
||||||
* @return
|
* @return 返回字符串截取结果
|
||||||
*/
|
*/
|
||||||
public static String subStartNum(String str, String startnum) {
|
public static String subStartNum(String str, String startnum) {
|
||||||
String getstr = "";
|
String getstr;
|
||||||
try{
|
try{
|
||||||
if (isInteger(startnum)) {
|
if (isInteger(startnum)) {
|
||||||
int start = Integer.valueOf(startnum);
|
int start = Integer.parseInt(startnum);
|
||||||
if (start < 0) {
|
if (start < 0) {
|
||||||
getstr = "截取字符串位置的数字不能小于0";
|
getstr = "截取字符串位置的数字不能小于0";
|
||||||
} else if (start > str.length()) {
|
} else if (start > str.length()) {
|
||||||
|
@ -162,15 +160,15 @@ public class SubString {
|
||||||
/**
|
/**
|
||||||
* 截取字符串到指定字符结束
|
* 截取字符串到指定字符结束
|
||||||
*
|
*
|
||||||
* @param str
|
* @param str 原始字符
|
||||||
* @param endnum
|
* @param endnum 结束位置
|
||||||
* @return
|
* @return 返回字符串截取结果
|
||||||
*/
|
*/
|
||||||
public static String subEndNum(String str, String endnum) {
|
public static String subEndNum(String str, String endnum) {
|
||||||
String getstr = "";
|
String getstr;
|
||||||
try{
|
try{
|
||||||
if (isInteger(endnum)) {
|
if (isInteger(endnum)) {
|
||||||
int end = Integer.valueOf(endnum);
|
int end = Integer.parseInt(endnum);
|
||||||
if (end < 0) {
|
if (end < 0) {
|
||||||
getstr = "截取字符串位置的数字不能小于0";
|
getstr = "截取字符串位置的数字不能小于0";
|
||||||
} else if (end > str.length()) {
|
} else if (end > str.length()) {
|
||||||
|
@ -189,8 +187,15 @@ public class SubString {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 正则匹配字符串
|
||||||
|
* @param str 原始字符串
|
||||||
|
* @param rgex 正则表达式
|
||||||
|
* @param num 字符索引
|
||||||
|
* @return 匹配到的字符串
|
||||||
|
*/
|
||||||
public static String subStrRgex(String str, String rgex, String num) {
|
public static String subStrRgex(String str, String rgex, String num) {
|
||||||
List<String> list = new ArrayList<String>();
|
List<String> list = new ArrayList<>();
|
||||||
try{
|
try{
|
||||||
// 匹配的模式
|
// 匹配的模式
|
||||||
Pattern pattern = Pattern.compile(rgex);
|
Pattern pattern = Pattern.compile(rgex);
|
||||||
|
@ -201,9 +206,9 @@ public class SubString {
|
||||||
// i++;
|
// i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getstr = "";
|
String getstr;
|
||||||
if (isInteger(num)) {
|
if (isInteger(num)) {
|
||||||
int index = Integer.valueOf(num);
|
int index = Integer.parseInt(num);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
getstr = "截取字符串索引数字不能小于0";
|
getstr = "截取字符串索引数字不能小于0";
|
||||||
} else if (index > str.length()) {
|
} else if (index > str.length()) {
|
||||||
|
@ -223,8 +228,13 @@ public class SubString {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否是整型数字
|
||||||
|
* @param str 整形字符
|
||||||
|
* @return 返回布尔型结果
|
||||||
|
*/
|
||||||
private static boolean isInteger(String str) {
|
private static boolean isInteger(String str) {
|
||||||
String patternStr="^[-\\+]?[\\d]*$";
|
String patternStr="^[-+]?[\\d]*$";
|
||||||
Pattern pattern = Pattern.compile(patternStr);
|
Pattern pattern = Pattern.compile(patternStr);
|
||||||
return pattern.matcher(str).matches();
|
return pattern.matcher(str).matches();
|
||||||
}
|
}
|
||||||
|
@ -241,11 +251,10 @@ public class SubString {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 遍历JSON对象
|
* 遍历JSON对象
|
||||||
*
|
* @param json 原始JSON
|
||||||
* @param json
|
* @param key 查询key值
|
||||||
* @param key
|
* @param keyindex key值索引
|
||||||
* @param keyindex
|
* @return 返回json对象
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
private static JSONObject parseJsonString(String json, String key, int keyindex) {
|
private static JSONObject parseJsonString(String json, String key, int keyindex) {
|
||||||
LinkedHashMap<String, Object> jsonMap = JSON.parseObject(json,
|
LinkedHashMap<String, Object> jsonMap = JSON.parseObject(json,
|
||||||
|
@ -259,14 +268,12 @@ public class SubString {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 遍历后JSON对象中的key以及value
|
* 遍历后JSON对象中的key以及value
|
||||||
*
|
* @param entry json中所有的的key以及value
|
||||||
* @param entry
|
* @param key 需要提取的key
|
||||||
* @param key
|
* @param keyindex 提取key的索引
|
||||||
* @param keyindex
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
private static Map.Entry<String, Object> parseJsonMap(Map.Entry<String, Object> entry, String key, int keyindex) {
|
private static void parseJsonMap(Map.Entry<String, Object> entry, String key, int keyindex) {
|
||||||
// 如果是单个map继续遍历
|
// 如果是单个map继续遍历
|
||||||
if (entry.getValue() instanceof Map) {
|
if (entry.getValue() instanceof Map) {
|
||||||
LinkedHashMap<String, Object> jsonMap = JSON.parseObject(entry.getValue().toString(),
|
LinkedHashMap<String, Object> jsonMap = JSON.parseObject(entry.getValue().toString(),
|
||||||
|
@ -304,23 +311,22 @@ public class SubString {
|
||||||
COUNTER++;
|
COUNTER++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return entry;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取JSON或是JSONArray对象指定序号Key中的Value
|
* 获取JSON或是JSONArray对象指定序号Key中的Value
|
||||||
*
|
*
|
||||||
* @param json
|
* @param json 原始JSON
|
||||||
* @param key
|
* @param key 指定key
|
||||||
* @param indexstr
|
* @param indexstr key的索引
|
||||||
* @return
|
* @return 返回指定key的value字符
|
||||||
*/
|
*/
|
||||||
public static String getJsonValue(String json, String key, String indexstr) {
|
public static String getJsonValue(String json, String key, String indexstr) {
|
||||||
json = json.trim();
|
json = json.trim();
|
||||||
int index = 1;
|
int index;
|
||||||
String result = JSONVALUE;
|
String result = JSONVALUE;
|
||||||
if (isInteger(indexstr) && !"0".equals(indexstr)) {
|
if (isInteger(indexstr) && !"0".equals(indexstr)) {
|
||||||
index = Integer.valueOf(indexstr);
|
index = Integer.parseInt(indexstr);
|
||||||
} else {
|
} else {
|
||||||
result = JSONVALUE + "指定的key值序号不是大于0的整数(序号从1开始),请检查!";
|
result = JSONVALUE + "指定的key值序号不是大于0的整数(序号从1开始),请检查!";
|
||||||
return result;
|
return result;
|
||||||
|
@ -339,7 +345,7 @@ public class SubString {
|
||||||
try {
|
try {
|
||||||
// JSONArray jsonarr = JSONArray.parseArray(json);
|
// JSONArray jsonarr = JSONArray.parseArray(json);
|
||||||
// 直接使用fastjson的接口实现有序解析
|
// 直接使用fastjson的接口实现有序解析
|
||||||
JSONArray jsonarr = JSONArray.parseObject(json.getBytes("UTF-8"), JSONArray.class, Feature.OrderedField);
|
JSONArray jsonarr = JSONArray.parseObject(json.getBytes(StandardCharsets.UTF_8), JSONArray.class, Feature.OrderedField);
|
||||||
for (int i = 0; i < jsonarr.size(); i++) {
|
for (int i = 0; i < jsonarr.size(); i++) {
|
||||||
JSONObject jsonStr = jsonarr.getJSONObject(i);
|
JSONObject jsonStr = jsonarr.getJSONObject(i);
|
||||||
parseJsonString(jsonStr.toJSONString(), key, index);
|
parseJsonString(jsonStr.toJSONString(), key, index);
|
||||||
|
@ -367,14 +373,14 @@ public class SubString {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过jsonPath表达式获取JSON字符串指定值
|
* 通过jsonPath表达式获取JSON字符串指定值
|
||||||
* @param expressionParams
|
* @param expressionParams jsonPath表达式
|
||||||
* @param jsonString
|
* @param jsonString json原始字符串
|
||||||
* @return
|
* @return 返回提取到手字符
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年8月28日
|
* @date 2019年8月28日
|
||||||
*/
|
*/
|
||||||
public static String jsonPathGetParams(String expressionParams, String jsonString) {
|
public static String jsonPathGetParams(String expressionParams, String jsonString) {
|
||||||
String type="String";
|
String type;
|
||||||
String expression="";
|
String expression="";
|
||||||
if(expressionParams.endsWith("]")&&expressionParams.contains("[")){
|
if(expressionParams.endsWith("]")&&expressionParams.contains("[")){
|
||||||
try{
|
try{
|
||||||
|
@ -394,7 +400,7 @@ public class SubString {
|
||||||
List<Object> list = JsonPath.parse(jsonString).read(expression);
|
List<Object> list = JsonPath.parse(jsonString).read(expression);
|
||||||
jsonString="";
|
jsonString="";
|
||||||
for(Object result:list){
|
for(Object result:list){
|
||||||
result = (String)jsonString+result+",";
|
result = jsonString +result+",";
|
||||||
jsonString = (String)result;
|
jsonString = (String)result;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
@ -403,7 +409,7 @@ public class SubString {
|
||||||
}catch(PathNotFoundException pnfe){
|
}catch(PathNotFoundException pnfe){
|
||||||
LogUtil.APP.error("通过jsonPath获取JSON字符串指定值出现异常,没有找到对应参数路径,请确认JSON字符串【{}】表达式是否正确【{}】!",jsonString,expression);
|
LogUtil.APP.error("通过jsonPath获取JSON字符串指定值出现异常,没有找到对应参数路径,请确认JSON字符串【{}】表达式是否正确【{}】!",jsonString,expression);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
LogUtil.APP.error("通过jsonPath获取JSON字符串指定值出现异,请检查您的动作参数格式(String/List[表达式])或是被提取的json字符串是否正常!",expressionParams);
|
LogUtil.APP.error("通过jsonPath获取JSON字符串指定值出现异常,请检查您的动作参数格式(String/List[表达式])或是被提取的json字符串是否正常!");
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
LogUtil.APP.warn("获取JSON字符串指定jsonPath表达式【{}】异常,请检查您的动作参数格式(String/List[表达式])是否正常!",expressionParams);
|
LogUtil.APP.warn("获取JSON字符串指定jsonPath表达式【{}】异常,请检查您的动作参数格式(String/List[表达式])是否正常!",expressionParams);
|
||||||
|
@ -411,5 +417,4 @@ public class SubString {
|
||||||
LogUtil.APP.info("获取JSON字符串指定jsonPath表达式【{}】的值是:{}",expression,jsonString);
|
LogUtil.APP.info("获取JSON字符串指定jsonPath表达式【{}】的值是:{}",expression,jsonString);
|
||||||
return jsonString;
|
return jsonString;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,68 +1,68 @@
|
||||||
package luckyclient.execution;
|
package luckyclient.execution;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.apache.log4j.PropertyConfigurator;
|
import org.apache.log4j.PropertyConfigurator;
|
||||||
|
|
||||||
import luckyclient.execution.appium.androidex.AndroidBatchExecute;
|
import luckyclient.execution.appium.androidex.AndroidBatchExecute;
|
||||||
import luckyclient.execution.appium.iosex.IosBatchExecute;
|
import luckyclient.execution.appium.iosex.IosBatchExecute;
|
||||||
import luckyclient.execution.httpinterface.BatchTestCaseExecution;
|
import luckyclient.execution.httpinterface.BatchTestCaseExecution;
|
||||||
import luckyclient.execution.httpinterface.TestControl;
|
import luckyclient.execution.httpinterface.TestControl;
|
||||||
import luckyclient.execution.webdriver.ex.WebBatchExecute;
|
import luckyclient.execution.webdriver.ex.WebBatchExecute;
|
||||||
import luckyclient.remote.api.GetServerApi;
|
import luckyclient.remote.api.GetServerApi;
|
||||||
import luckyclient.remote.entity.TaskExecute;
|
import luckyclient.remote.entity.TaskExecute;
|
||||||
import luckyclient.remote.entity.TaskScheduling;
|
import luckyclient.remote.entity.TaskScheduling;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
import luckyclient.utils.config.AppiumConfig;
|
import luckyclient.utils.config.AppiumConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
*
|
*
|
||||||
* @date 2017年12月1日 上午9:29:40
|
* @date 2017年12月1日 上午9:29:40
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class BatchCaseExecute extends TestControl {
|
public class BatchCaseExecute extends TestControl {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
try {
|
try {
|
||||||
PropertyConfigurator.configure(System.getProperty("user.dir") + File.separator + "log4j.conf");
|
PropertyConfigurator.configure(System.getProperty("user.dir") + File.separator + "log4j.conf");
|
||||||
String taskid = args[0];
|
String taskid = args[0];
|
||||||
String batchcase = args[1];
|
String batchcase = args[1];
|
||||||
TaskExecute task = GetServerApi.cgetTaskbyid(Integer.valueOf(taskid));
|
TaskExecute task = GetServerApi.cgetTaskbyid(Integer.parseInt(taskid));
|
||||||
TaskScheduling taskScheduling = GetServerApi.cGetTaskSchedulingByTaskId(Integer.valueOf(taskid));
|
TaskScheduling taskScheduling = GetServerApi.cGetTaskSchedulingByTaskId(Integer.parseInt(taskid));
|
||||||
if (taskScheduling.getTaskType() == 0) {
|
if (taskScheduling.getTaskType() == 0) {
|
||||||
BatchTestCaseExecution.batchCaseExecuteForTast(taskScheduling.getProject().getProjectName(),
|
BatchTestCaseExecution.batchCaseExecuteForTast(
|
||||||
String.valueOf(task.getTaskId()), batchcase);
|
String.valueOf(task.getTaskId()), batchcase);
|
||||||
} else if (taskScheduling.getTaskType() == 1) {
|
} else if (taskScheduling.getTaskType() == 1) {
|
||||||
// UI测试
|
// UI测试
|
||||||
WebBatchExecute.batchCaseExecuteForTast(taskScheduling.getProject().getProjectName(),
|
WebBatchExecute.batchCaseExecuteForTast(
|
||||||
String.valueOf(task.getTaskId()), batchcase);
|
String.valueOf(task.getTaskId()), batchcase);
|
||||||
|
|
||||||
} else if (taskScheduling.getTaskType() == 2) {
|
} else if (taskScheduling.getTaskType() == 2) {
|
||||||
Properties properties = AppiumConfig.getConfiguration();
|
Properties properties = AppiumConfig.getConfiguration();
|
||||||
|
|
||||||
if ("Android".equals(properties.getProperty("platformName"))) {
|
if ("Android".equals(properties.getProperty("platformName"))) {
|
||||||
AndroidBatchExecute.batchCaseExecuteForTast(taskScheduling.getProject().getProjectName(),
|
AndroidBatchExecute.batchCaseExecuteForTast(
|
||||||
String.valueOf(task.getTaskId()), batchcase);
|
String.valueOf(task.getTaskId()), batchcase);
|
||||||
} else if ("IOS".equals(properties.getProperty("platformName"))) {
|
} else if ("IOS".equals(properties.getProperty("platformName"))) {
|
||||||
IosBatchExecute.batchCaseExecuteForTast(taskScheduling.getProject().getProjectName(),
|
IosBatchExecute.batchCaseExecuteForTast(
|
||||||
String.valueOf(task.getTaskId()), batchcase);
|
String.valueOf(task.getTaskId()), batchcase);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
LogUtil.APP.error("启动批量运行用例主函数出现异常,请检查!",e);
|
LogUtil.APP.error("启动批量运行用例主函数出现异常,请检查!",e);
|
||||||
} finally{
|
} finally{
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,68 +1,66 @@
|
||||||
package luckyclient.execution;
|
package luckyclient.execution;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.apache.log4j.PropertyConfigurator;
|
import org.apache.log4j.PropertyConfigurator;
|
||||||
|
|
||||||
import luckyclient.execution.appium.androidex.AndroidOneCaseExecute;
|
import luckyclient.execution.appium.androidex.AndroidOneCaseExecute;
|
||||||
import luckyclient.execution.appium.iosex.IosOneCaseExecute;
|
import luckyclient.execution.appium.iosex.IosOneCaseExecute;
|
||||||
import luckyclient.execution.httpinterface.TestCaseExecution;
|
import luckyclient.execution.httpinterface.TestCaseExecution;
|
||||||
import luckyclient.execution.httpinterface.TestControl;
|
import luckyclient.execution.httpinterface.TestControl;
|
||||||
import luckyclient.execution.webdriver.ex.WebOneCaseExecute;
|
import luckyclient.execution.webdriver.ex.WebOneCaseExecute;
|
||||||
import luckyclient.remote.api.GetServerApi;
|
import luckyclient.remote.api.GetServerApi;
|
||||||
import luckyclient.remote.entity.TaskExecute;
|
import luckyclient.remote.entity.TaskExecute;
|
||||||
import luckyclient.remote.entity.TaskScheduling;
|
import luckyclient.remote.entity.TaskScheduling;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
import luckyclient.utils.config.AppiumConfig;
|
import luckyclient.utils.config.AppiumConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
*
|
*
|
||||||
* @date 2017年12月1日 上午9:29:40
|
* @date 2017年12月1日 上午9:29:40
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class OneCaseExecute extends TestControl {
|
public class OneCaseExecute extends TestControl {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) {
|
||||||
// TODO Auto-generated method stub
|
try{
|
||||||
try{
|
PropertyConfigurator.configure(System.getProperty("user.dir")+ File.separator +"log4j.conf");
|
||||||
PropertyConfigurator.configure(System.getProperty("user.dir")+ File.separator +"log4j.conf");
|
String taskId = args[0];
|
||||||
String taskId = args[0];
|
String caseId = args[1];
|
||||||
String caseId = args[1];
|
TaskExecute task = GetServerApi.cgetTaskbyid(Integer.parseInt(taskId));
|
||||||
int version = Integer.parseInt(args[2]);
|
TaskScheduling taskScheduling = GetServerApi.cGetTaskSchedulingByTaskId(Integer.parseInt(taskId));
|
||||||
TaskExecute task = GetServerApi.cgetTaskbyid(Integer.valueOf(taskId));
|
if (taskScheduling.getTaskType() == 0) {
|
||||||
TaskScheduling taskScheduling = GetServerApi.cGetTaskSchedulingByTaskId(Integer.valueOf(taskId));
|
// 接口测试
|
||||||
if (taskScheduling.getTaskType() == 0) {
|
TestCaseExecution testCaseExecution=new TestCaseExecution();
|
||||||
// 接口测试
|
testCaseExecution.oneCaseExecuteForTask(Integer.valueOf(caseId), String.valueOf(task.getTaskId()));
|
||||||
TestCaseExecution testCaseExecution=new TestCaseExecution();
|
|
||||||
testCaseExecution.oneCaseExecuteForTask(taskScheduling.getProject().getProjectName(), Integer.valueOf(caseId), String.valueOf(task.getTaskId()));
|
} else if (taskScheduling.getTaskType() == 1) {
|
||||||
|
WebOneCaseExecute.oneCaseExecuteForTast(Integer.valueOf(caseId),
|
||||||
} else if (taskScheduling.getTaskType() == 1) {
|
String.valueOf(task.getTaskId()));
|
||||||
WebOneCaseExecute.oneCaseExecuteForTast(taskScheduling.getProject().getProjectName(), Integer.valueOf(caseId), version,
|
|
||||||
String.valueOf(task.getTaskId()));
|
} else if (taskScheduling.getTaskType() == 2) {
|
||||||
|
Properties properties = AppiumConfig.getConfiguration();
|
||||||
} else if (taskScheduling.getTaskType() == 2) {
|
|
||||||
Properties properties = AppiumConfig.getConfiguration();
|
if ("Android".equals(properties.getProperty("platformName"))) {
|
||||||
|
AndroidOneCaseExecute.oneCaseExecuteForTast(Integer.valueOf(caseId),
|
||||||
if ("Android".equals(properties.getProperty("platformName"))) {
|
String.valueOf(task.getTaskId()));
|
||||||
AndroidOneCaseExecute.oneCaseExecuteForTast(taskScheduling.getProject().getProjectName(), Integer.valueOf(caseId),
|
} else if ("IOS".equals(properties.getProperty("platformName"))) {
|
||||||
version, String.valueOf(task.getTaskId()));
|
IosOneCaseExecute.oneCaseExecuteForTast(Integer.valueOf(caseId),
|
||||||
} else if ("IOS".equals(properties.getProperty("platformName"))) {
|
String.valueOf(task.getTaskId()));
|
||||||
IosOneCaseExecute.oneCaseExecuteForTast(taskScheduling.getProject().getProjectName(), Integer.valueOf(caseId), version,
|
}
|
||||||
String.valueOf(task.getTaskId()));
|
|
||||||
}
|
}
|
||||||
|
}catch(Exception e){
|
||||||
}
|
LogUtil.APP.error("启动单个用例运行主函数出现异常,请检查!",e);
|
||||||
}catch(Exception e){
|
} finally{
|
||||||
LogUtil.APP.error("启动单个用例运行主函数出现异常,请检查!",e);
|
System.exit(0);
|
||||||
} finally{
|
}
|
||||||
System.exit(0);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,50 +1,49 @@
|
||||||
package luckyclient.execution;
|
package luckyclient.execution;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import org.apache.log4j.PropertyConfigurator;
|
import org.apache.log4j.PropertyConfigurator;
|
||||||
|
|
||||||
import luckyclient.execution.appium.AppTestControl;
|
import luckyclient.execution.appium.AppTestControl;
|
||||||
import luckyclient.execution.httpinterface.TestControl;
|
import luckyclient.execution.httpinterface.TestControl;
|
||||||
import luckyclient.execution.webdriver.WebTestControl;
|
import luckyclient.execution.webdriver.WebTestControl;
|
||||||
import luckyclient.remote.api.GetServerApi;
|
import luckyclient.remote.api.GetServerApi;
|
||||||
import luckyclient.remote.entity.TaskExecute;
|
import luckyclient.remote.entity.TaskExecute;
|
||||||
import luckyclient.remote.entity.TaskScheduling;
|
import luckyclient.remote.entity.TaskScheduling;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
*
|
*
|
||||||
* @date 2017年12月1日 上午9:29:40
|
* @date 2017年12月1日 上午9:29:40
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RunAutomationTest extends TestControl {
|
public class RunAutomationTest extends TestControl {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO Auto-generated method stub
|
try {
|
||||||
try {
|
PropertyConfigurator.configure(System.getProperty("user.dir") + File.separator + "log4j.conf");
|
||||||
PropertyConfigurator.configure(System.getProperty("user.dir") + File.separator + "log4j.conf");
|
String taskid = args[0];
|
||||||
String taskid = args[0];
|
TaskExecute task = GetServerApi.cgetTaskbyid(Integer.parseInt(taskid));
|
||||||
TaskExecute task = GetServerApi.cgetTaskbyid(Integer.valueOf(taskid));
|
TaskScheduling taskScheduling = GetServerApi.cGetTaskSchedulingByTaskId(Integer.parseInt(taskid));
|
||||||
TaskScheduling taskScheduling = GetServerApi.cGetTaskSchedulingByTaskId(Integer.valueOf(taskid));
|
if (taskScheduling.getTaskType() == 0) {
|
||||||
if (taskScheduling.getTaskType() == 0) {
|
// 接口测试
|
||||||
// 接口测试
|
TestControl.taskExecutionPlan(task);
|
||||||
TestControl.taskExecutionPlan(task);
|
} else if (taskScheduling.getTaskType() == 1) {
|
||||||
} else if (taskScheduling.getTaskType() == 1) {
|
// UI测试
|
||||||
// UI测试
|
WebTestControl.taskExecutionPlan(task);
|
||||||
WebTestControl.taskExecutionPlan(task);
|
} else if (taskScheduling.getTaskType() == 2) {
|
||||||
} else if (taskScheduling.getTaskType() == 2) {
|
AppTestControl.taskExecutionPlan(task);
|
||||||
AppTestControl.taskExecutionPlan(task);
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
// TODO Auto-generated catch block
|
||||||
// TODO Auto-generated catch block
|
LogUtil.APP.error("启动测试任务运行主函数出现异常,请检查!",e);
|
||||||
LogUtil.APP.error("启动测试任务运行主函数出现异常,请检查!",e);
|
} finally{
|
||||||
} finally{
|
System.exit(0);
|
||||||
System.exit(0);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -1,38 +1,36 @@
|
||||||
package luckyclient.execution;
|
package luckyclient.execution;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import org.apache.log4j.PropertyConfigurator;
|
import org.apache.log4j.PropertyConfigurator;
|
||||||
|
|
||||||
import luckyclient.execution.httpinterface.TestControl;
|
import luckyclient.execution.httpinterface.TestControl;
|
||||||
import luckyclient.execution.httpinterface.WebTestCaseDebug;
|
import luckyclient.execution.httpinterface.WebTestCaseDebug;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
||||||
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
* @date 2017年12月1日 上午9:29:40
|
* @date 2017年12月1日 上午9:29:40
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class WebDebugExecute extends TestControl{
|
public class WebDebugExecute extends TestControl{
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) {
|
||||||
// TODO Auto-generated method stub
|
try {
|
||||||
try {
|
PropertyConfigurator.configure(System.getProperty("user.dir") + File.separator + "log4j.conf");
|
||||||
PropertyConfigurator.configure(System.getProperty("user.dir") + File.separator + "log4j.conf");
|
String caseIdStr = args[0];
|
||||||
String caseIdStr = args[0];
|
String userIdStr = args[1];
|
||||||
String userIdStr = args[1];
|
WebTestCaseDebug.oneCaseDebug(caseIdStr, userIdStr);
|
||||||
WebTestCaseDebug.oneCaseDebug(caseIdStr, userIdStr);
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
LogUtil.APP.error("启动用例调试主函数出现异常,请检查!",e);
|
||||||
// TODO: handle exception
|
} finally{
|
||||||
LogUtil.APP.error("启动用例调试主函数出现异常,请检查!",e);
|
System.exit(0);
|
||||||
} finally{
|
}
|
||||||
System.exit(0);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,184 +1,185 @@
|
||||||
package luckyclient.execution.appium;
|
package luckyclient.execution.appium;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import luckyclient.execution.dispose.ChangString;
|
import luckyclient.execution.dispose.ChangString;
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.ProjectCase;
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
import luckyclient.remote.entity.ProjectCaseSteps;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
||||||
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* @ClassName: AnalyticCase
|
* @ClassName: AnalyticCase
|
||||||
* @Description: 解析单个用例中描述部分的脚本
|
* @Description: 解析单个用例中描述部分的脚本
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
* @date 2016年9月18日
|
* @date 2016年9月18日
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class AppDriverAnalyticCase {
|
public class AppDriverAnalyticCase {
|
||||||
//private static String splitFlag = "\\|";
|
//private static String splitFlag = "\\|";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移动端的用例步骤解析
|
* 移动端的用例步骤解析
|
||||||
* @param projectcase
|
* @param projectcase 用例对象
|
||||||
* @param step
|
* @param step 步骤对象
|
||||||
* @param taskid
|
* @param taskid 任务ID
|
||||||
* @param caselog
|
* @param caselog 日志操作
|
||||||
* @return
|
* @return 返回步骤分析对象MAP
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年1月17日
|
* @date 2019年1月17日
|
||||||
*/
|
*/
|
||||||
public static Map<String,String> analyticCaseStep(ProjectCase projectcase,ProjectCaseSteps step,String taskid,serverOperation caselog, Map<String, String> variable){
|
public static Map<String,String> analyticCaseStep(ProjectCase projectcase,ProjectCaseSteps step,String taskid,serverOperation caselog, Map<String, String> variable){
|
||||||
Map<String,String> params = new HashMap<String,String>(0);
|
Map<String,String> params = new HashMap<>(0);
|
||||||
|
|
||||||
String resultstr = null;
|
String resultstr;
|
||||||
try {
|
try {
|
||||||
// 处理值传递
|
// 处理值传递
|
||||||
String path = ChangString.changparams(step.getStepPath(), variable, "包路径|定位路径");
|
String path = ChangString.changparams(step.getStepPath(), variable, "包路径|定位路径");
|
||||||
if(null != path && path.contains("=")){
|
if(null != path && path.contains("=")){
|
||||||
String property = path.substring(0, path.indexOf("=")).trim();
|
String property = path.substring(0, path.indexOf("=")).trim();
|
||||||
String propertyValue = path.substring(path.indexOf("=")+1, path.length()).trim();
|
String propertyValue = path.substring(path.indexOf("=")+1).trim();
|
||||||
//set属性
|
//set属性
|
||||||
params.put("property", property.toLowerCase());
|
params.put("property", property.toLowerCase());
|
||||||
//set属性值
|
//set属性值
|
||||||
params.put("property_value", propertyValue);
|
params.put("property_value", propertyValue);
|
||||||
LogUtil.APP.info("对象属性解析结果:property:{}; property_value:{}",property,propertyValue);
|
LogUtil.APP.info("对象属性解析结果:property:{}; property_value:{}",property,propertyValue);
|
||||||
}
|
}
|
||||||
// set操作方法,处理值传递
|
// set操作方法,处理值传递
|
||||||
String operation = ChangString.changparams(step.getStepOperation().toLowerCase(), variable, "操作");
|
String operation = ChangString.changparams(step.getStepOperation().toLowerCase(), variable, "操作");
|
||||||
params.put("operation", operation);
|
params.put("operation", operation);
|
||||||
// set属性值,处理值传递
|
// set属性值,处理值传递
|
||||||
String operationValue = ChangString.changparams(step.getStepParameters(), variable, "操作参数");
|
String operationValue = ChangString.changparams(step.getStepParameters(), variable, "操作参数");
|
||||||
if(StringUtils.isNotEmpty(operationValue)){
|
if(StringUtils.isNotEmpty(operationValue)){
|
||||||
//set属性值
|
//set属性值
|
||||||
params.put("operation_value", operationValue);
|
params.put("operation_value", operationValue);
|
||||||
}
|
}
|
||||||
LogUtil.APP.info("对象操作解析结果:operation:{}; operation_value:{}",operation,operationValue);
|
LogUtil.APP.info("对象操作解析结果:operation:{}; operation_value:{}",operation,operationValue);
|
||||||
//获取预期结果字符串
|
//获取预期结果字符串
|
||||||
resultstr = step.getExpectedResult();
|
resultstr = step.getExpectedResult();
|
||||||
|
|
||||||
//set预期结果
|
//set预期结果
|
||||||
if(null==resultstr||"".equals(resultstr)){
|
if(null==resultstr||"".equals(resultstr)){
|
||||||
params.put("ExpectedResults", "");
|
params.put("ExpectedResults", "");
|
||||||
}else if(null!=resultstr){
|
}else {
|
||||||
String expectedResults = subComment(resultstr);
|
String expectedResults = subComment(resultstr);
|
||||||
|
|
||||||
//处理check字段
|
//处理check字段
|
||||||
if(expectedResults.startsWith("check(")){
|
if(expectedResults.startsWith("check(")){
|
||||||
params.put("checkproperty", expectedResults.substring(expectedResults.indexOf("check(")+6, expectedResults.indexOf("=")));
|
params.put("checkproperty", expectedResults.substring(expectedResults.indexOf("check(")+6, expectedResults.indexOf("=")));
|
||||||
params.put("checkproperty_value", expectedResults.substring(expectedResults.indexOf("=")+1, expectedResults.lastIndexOf(")")));
|
params.put("checkproperty_value", expectedResults.substring(expectedResults.indexOf("=")+1, expectedResults.lastIndexOf(")")));
|
||||||
}
|
}
|
||||||
|
|
||||||
//处理值传递
|
//处理值传递
|
||||||
expectedResults = ChangString.changparams(expectedResults, variable, "预期结果");
|
expectedResults = ChangString.changparams(expectedResults, variable, "预期结果");
|
||||||
params.put("ExpectedResults", expectedResults);
|
params.put("ExpectedResults", expectedResults);
|
||||||
LogUtil.APP.info("预期结果解析:ExpectedResults:{}",expectedResults);
|
LogUtil.APP.info("预期结果解析:ExpectedResults:{}",expectedResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
LogUtil.APP.info("用例编号:{} 步骤编号:{} 解析自动化用例步骤脚本完成!",projectcase.getCaseSign(),step.getStepSerialNumber());
|
LogUtil.APP.info("用例编号:{} 步骤编号:{} 解析自动化用例步骤脚本完成!",projectcase.getCaseSign(),step.getStepSerialNumber());
|
||||||
if(null!=caselog){
|
if(null!=caselog){
|
||||||
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),"步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本完成!","info",String.valueOf(step.getStepSerialNumber()),"");
|
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),"步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本完成!","info",String.valueOf(step.getStepSerialNumber()),"");
|
||||||
}
|
}
|
||||||
}catch(Exception e) {
|
}catch(Exception e) {
|
||||||
if(null!=caselog){
|
if(null!=caselog){
|
||||||
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),"步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本出错!","error",String.valueOf(step.getStepSerialNumber()),"");
|
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),"步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本出错!","error",String.valueOf(step.getStepSerialNumber()),"");
|
||||||
}
|
}
|
||||||
LogUtil.APP.error("用例编号:{} 步骤编号:{} 解析自动化用例步骤脚本出错!",projectcase.getCaseSign(),step.getStepSerialNumber(),e);
|
LogUtil.APP.error("用例编号:{} 步骤编号:{} 解析自动化用例步骤脚本出错!",projectcase.getCaseSign(),step.getStepSerialNumber(),e);
|
||||||
params.put("exception","用例编号:"+projectcase.getCaseSign()+"|解析异常,用例步骤为空或是用例脚本错误!");
|
params.put("exception","用例编号:"+projectcase.getCaseSign()+"|解析异常,用例步骤为空或是用例脚本错误!");
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String subComment(String htmlStr) throws InterruptedException{
|
private static String subComment(String htmlStr) {
|
||||||
// 定义script的正则表达式
|
// 定义script的正则表达式
|
||||||
String regExScript = "<script[^>]*?>[\\s\\S]*?<\\/script>";
|
String regExScript = "<script[^>]*?>[\\s\\S]*?</script>";
|
||||||
// 定义style的正则表达式
|
// 定义style的正则表达式
|
||||||
String regExStyle = "<style[^>]*?>[\\s\\S]*?<\\/style>";
|
String regExStyle = "<style[^>]*?>[\\s\\S]*?</style>";
|
||||||
// 定义HTML标签的正则表达式
|
// 定义HTML标签的正则表达式
|
||||||
String regExHtml = "<[^>]+>";
|
String regExHtml = "<[^>]+>";
|
||||||
//定义空格回车换行符
|
//定义空格回车换行符
|
||||||
String regExSpace = "\t|\r|\n";
|
String regExSpace = "[\t\r\n]";
|
||||||
|
|
||||||
String scriptstr = null;
|
String scriptstr;
|
||||||
if (htmlStr!=null) {
|
if (htmlStr!=null) {
|
||||||
Pattern pScript = Pattern.compile(regExScript, Pattern.CASE_INSENSITIVE);
|
Pattern pScript = Pattern.compile(regExScript, Pattern.CASE_INSENSITIVE);
|
||||||
Matcher mScript = pScript.matcher(htmlStr);
|
Matcher mScript = pScript.matcher(htmlStr);
|
||||||
// 过滤script标签
|
// 过滤script标签
|
||||||
htmlStr = mScript.replaceAll("");
|
htmlStr = mScript.replaceAll("");
|
||||||
|
|
||||||
Pattern pStyle = Pattern.compile(regExStyle, Pattern.CASE_INSENSITIVE);
|
Pattern pStyle = Pattern.compile(regExStyle, Pattern.CASE_INSENSITIVE);
|
||||||
Matcher mStyle = pStyle.matcher(htmlStr);
|
Matcher mStyle = pStyle.matcher(htmlStr);
|
||||||
// 过滤style标签
|
// 过滤style标签
|
||||||
htmlStr = mStyle.replaceAll("");
|
htmlStr = mStyle.replaceAll("");
|
||||||
|
|
||||||
Pattern pHtml = Pattern.compile(regExHtml, Pattern.CASE_INSENSITIVE);
|
Pattern pHtml = Pattern.compile(regExHtml, Pattern.CASE_INSENSITIVE);
|
||||||
Matcher mHtml = pHtml.matcher(htmlStr);
|
Matcher mHtml = pHtml.matcher(htmlStr);
|
||||||
// 过滤html标签
|
// 过滤html标签
|
||||||
htmlStr = mHtml.replaceAll("");
|
htmlStr = mHtml.replaceAll("");
|
||||||
|
|
||||||
Pattern pSpace = Pattern.compile(regExSpace, Pattern.CASE_INSENSITIVE);
|
Pattern pSpace = Pattern.compile(regExSpace, Pattern.CASE_INSENSITIVE);
|
||||||
Matcher mSpace = pSpace.matcher(htmlStr);
|
Matcher mSpace = pSpace.matcher(htmlStr);
|
||||||
// 过滤空格回车标签
|
// 过滤空格回车标签
|
||||||
htmlStr = mSpace.replaceAll("");
|
htmlStr = mSpace.replaceAll("");
|
||||||
|
|
||||||
}
|
}
|
||||||
if(htmlStr.indexOf("/*")>-1&&htmlStr.indexOf("*/")>-1){
|
assert htmlStr != null;
|
||||||
String commentstr = htmlStr.substring(htmlStr.trim().indexOf("/*"),htmlStr.indexOf("*/")+2);
|
if(htmlStr.contains("/*") && htmlStr.contains("*/")){
|
||||||
//去注释
|
String commentstr = htmlStr.substring(htmlStr.trim().indexOf("/*"),htmlStr.indexOf("*/")+2);
|
||||||
scriptstr = htmlStr.replace(commentstr, "");
|
//去注释
|
||||||
}else{
|
scriptstr = htmlStr.replace(commentstr, "");
|
||||||
scriptstr = htmlStr;
|
}else{
|
||||||
}
|
scriptstr = htmlStr;
|
||||||
//去掉字符串前后的空格
|
}
|
||||||
scriptstr = trimInnerSpaceStr(scriptstr);
|
//去掉字符串前后的空格
|
||||||
//替换空格转义
|
scriptstr = trimInnerSpaceStr(scriptstr);
|
||||||
scriptstr = scriptstr.replaceAll(" ", " ");
|
//替换空格转义
|
||||||
//转义双引号
|
scriptstr = scriptstr.replaceAll(" ", " ");
|
||||||
scriptstr = scriptstr.replaceAll(""", "\"");
|
//转义双引号
|
||||||
//转义单引号
|
scriptstr = scriptstr.replaceAll(""", "\"");
|
||||||
scriptstr = scriptstr.replaceAll("'", "\'");
|
//转义单引号
|
||||||
//转义链接符
|
scriptstr = scriptstr.replaceAll("'", "'");
|
||||||
scriptstr = scriptstr.replaceAll("&", "&");
|
//转义链接符
|
||||||
scriptstr = scriptstr.replaceAll("<", "<");
|
scriptstr = scriptstr.replaceAll("&", "&");
|
||||||
scriptstr = scriptstr.replaceAll(">", ">");
|
scriptstr = scriptstr.replaceAll("<", "<");
|
||||||
|
scriptstr = scriptstr.replaceAll(">", ">");
|
||||||
return scriptstr;
|
|
||||||
}
|
return scriptstr;
|
||||||
|
}
|
||||||
/***
|
|
||||||
* 去掉字符串前后的空格,中间的空格保留
|
/**
|
||||||
* @param str
|
* 去掉字符串前后的空格,中间的空格保留
|
||||||
* @return
|
* @param str 原始字符串
|
||||||
*/
|
* @return 返回去掉空格后的字符串
|
||||||
public static String trimInnerSpaceStr(String str) {
|
*/
|
||||||
str = str.trim();
|
public static String trimInnerSpaceStr(String str) {
|
||||||
while (str.startsWith(" ")) {
|
str = str.trim();
|
||||||
str = str.substring(1, str.length()).trim();
|
while (str.startsWith(" ")) {
|
||||||
}
|
str = str.substring(1).trim();
|
||||||
while (str.startsWith(" ")) {
|
}
|
||||||
str = str.substring(6, str.length()).trim();
|
while (str.startsWith(" ")) {
|
||||||
}
|
str = str.substring(6).trim();
|
||||||
while (str.endsWith(" ")) {
|
}
|
||||||
str = str.substring(0, str.length() - 1).trim();
|
while (str.endsWith(" ")) {
|
||||||
}
|
str = str.substring(0, str.length() - 1).trim();
|
||||||
while (str.endsWith(" ")) {
|
}
|
||||||
str = str.substring(0, str.length() - 6).trim();
|
while (str.endsWith(" ")) {
|
||||||
}
|
str = str.substring(0, str.length() - 6).trim();
|
||||||
return str;
|
}
|
||||||
}
|
return str;
|
||||||
|
}
|
||||||
public static void main(String[] args){
|
|
||||||
// TODO Auto-generated method stub
|
public static void main(String[] args){
|
||||||
}
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class AppTestControl {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 控制台模式调度计划执行用例
|
* 控制台模式调度计划执行用例
|
||||||
* @param planname
|
* @param planname 测试计划名称
|
||||||
*/
|
*/
|
||||||
public static void manualExecutionPlan(String planname) {
|
public static void manualExecutionPlan(String planname) {
|
||||||
// 不记日志到数据库
|
// 不记日志到数据库
|
||||||
|
@ -65,7 +65,7 @@ public class AppTestControl {
|
||||||
}
|
}
|
||||||
serverOperation caselog = new serverOperation();
|
serverOperation caselog = new serverOperation();
|
||||||
List<ProjectCase> testCases = GetServerApi.getCasesbyplanname(planname);
|
List<ProjectCase> testCases = GetServerApi.getCasesbyplanname(planname);
|
||||||
List<ProjectCaseParams> pcplist = new ArrayList<ProjectCaseParams>();
|
List<ProjectCaseParams> pcplist = new ArrayList<>();
|
||||||
if (testCases.size() != 0) {
|
if (testCases.size() != 0) {
|
||||||
pcplist = GetServerApi.cgetParamsByProjectid(String.valueOf(testCases.get(0).getProjectId()));
|
pcplist = GetServerApi.cgetParamsByProjectid(String.valueOf(testCases.get(0).getProjectId()));
|
||||||
}
|
}
|
||||||
|
@ -84,21 +84,18 @@ public class AppTestControl {
|
||||||
} else if ("IOS".equals(properties.getProperty("platformName"))) {
|
} else if ("IOS".equals(properties.getProperty("platformName"))) {
|
||||||
IosCaseExecution.caseExcution(testcase, steps, taskid, iosdriver, caselog, pcplist);
|
IosCaseExecution.caseExcution(testcase, steps, taskid, iosdriver, caselog, pcplist);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
LogUtil.APP.error("用户执行过程中抛出Exception异常!", e);
|
||||||
LogUtil.APP.error("用户执行过程中抛出InterruptedException异常!", e);
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
LogUtil.APP.error("用户执行过程中抛出IOException异常!", e);
|
|
||||||
}
|
}
|
||||||
LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
|
LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
|
||||||
}
|
}
|
||||||
LogUtil.APP.info("当前项目测试计划中的用例已经全部执行完成...");
|
LogUtil.APP.info("当前项目测试计划中的用例已经全部执行完成...");
|
||||||
// 关闭APP以及appium会话
|
// 关闭APP以及appium会话
|
||||||
if ("Android".equals(properties.getProperty("platformName"))) {
|
if ("Android".equals(properties.getProperty("platformName"))) {
|
||||||
|
assert androiddriver != null;
|
||||||
androiddriver.closeApp();
|
androiddriver.closeApp();
|
||||||
} else if ("IOS".equals(properties.getProperty("platformName"))) {
|
} else if ("IOS".equals(properties.getProperty("platformName"))) {
|
||||||
|
assert iosdriver != null;
|
||||||
iosdriver.closeApp();
|
iosdriver.closeApp();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,7 +110,7 @@ public class AppTestControl {
|
||||||
Properties properties = AppiumConfig.getConfiguration();
|
Properties properties = AppiumConfig.getConfiguration();
|
||||||
AppiumService as=null;
|
AppiumService as=null;
|
||||||
//根据配置自动启动Appiume服务
|
//根据配置自动启动Appiume服务
|
||||||
if(Boolean.valueOf(properties.getProperty("autoRunAppiumService"))){
|
if(Boolean.parseBoolean(properties.getProperty("autoRunAppiumService"))){
|
||||||
as =new AppiumService();
|
as =new AppiumService();
|
||||||
as.start();
|
as.start();
|
||||||
Thread.sleep(10000);
|
Thread.sleep(10000);
|
||||||
|
@ -127,7 +124,7 @@ public class AppTestControl {
|
||||||
String jobname = GetServerApi.cGetTaskSchedulingByTaskId(task.getTaskId()).getSchedulingName();
|
String jobname = GetServerApi.cGetTaskSchedulingByTaskId(task.getTaskId()).getSchedulingName();
|
||||||
int[] tastcount = null;
|
int[] tastcount = null;
|
||||||
// 判断是否要自动重启TOMCAT
|
// 判断是否要自动重启TOMCAT
|
||||||
if (restartstatus.indexOf("Status:true") > -1) {
|
if (restartstatus.contains("Status:true")) {
|
||||||
// 判断是否构建是否成功
|
// 判断是否构建是否成功
|
||||||
if (BuildResult.SUCCESS.equals(buildResult)) {
|
if (BuildResult.SUCCESS.equals(buildResult)) {
|
||||||
try {
|
try {
|
||||||
|
@ -161,22 +158,23 @@ public class AppTestControl {
|
||||||
} else if ("IOS".equals(properties.getProperty("platformName"))) {
|
} else if ("IOS".equals(properties.getProperty("platformName"))) {
|
||||||
IosCaseExecution.caseExcution(testcase, steps, taskId, iosdriver, caselog, pcplist);
|
IosCaseExecution.caseExcution(testcase, steps, taskId, iosdriver, caselog, pcplist);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException | IOException e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
|
||||||
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
||||||
}
|
}
|
||||||
LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
|
LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
|
||||||
}
|
}
|
||||||
tastcount = serverOperation.updateTaskExecuteData(taskId, cases.size(),2);
|
tastcount = serverOperation.updateTaskExecuteData(taskId, cases.size(),2);
|
||||||
String testtime = serverOperation.getTestTime(taskId);
|
String testtime = serverOperation.getTestTime(taskId);
|
||||||
LogUtil.APP.info("当前项目【{]】测试计划中的用例已经全部执行完成...",projectname);
|
LogUtil.APP.info("当前项目【{}】测试计划中的用例已经全部执行完成...",projectname);
|
||||||
MailSendInitialization.sendMailInitialization(HtmlMail.htmlSubjectFormat(jobname),
|
MailSendInitialization.sendMailInitialization(HtmlMail.htmlSubjectFormat(jobname),
|
||||||
HtmlMail.htmlContentFormat(tastcount, taskId, buildResult.toString(), restartstatus, testtime, jobname),
|
HtmlMail.htmlContentFormat(tastcount, taskId, buildResult.toString(), restartstatus, testtime, jobname),
|
||||||
taskId, taskScheduling, tastcount);
|
taskId, taskScheduling, tastcount);
|
||||||
// 关闭APP以及appium会话
|
// 关闭APP以及appium会话
|
||||||
if ("Android".equals(properties.getProperty("platformName"))) {
|
if ("Android".equals(properties.getProperty("platformName"))) {
|
||||||
|
assert androiddriver != null;
|
||||||
androiddriver.closeApp();
|
androiddriver.closeApp();
|
||||||
} else if ("IOS".equals(properties.getProperty("platformName"))) {
|
} else if ("IOS".equals(properties.getProperty("platformName"))) {
|
||||||
|
assert iosdriver != null;
|
||||||
iosdriver.closeApp();
|
iosdriver.closeApp();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,108 +1,110 @@
|
||||||
package luckyclient.execution.appium;
|
package luckyclient.execution.appium;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||||
|
|
||||||
import io.appium.java_client.android.AndroidDriver;
|
import io.appium.java_client.android.AndroidDriver;
|
||||||
import io.appium.java_client.android.AndroidElement;
|
import io.appium.java_client.android.AndroidElement;
|
||||||
import io.appium.java_client.ios.IOSDriver;
|
import io.appium.java_client.ios.IOSDriver;
|
||||||
import io.appium.java_client.ios.IOSElement;
|
import io.appium.java_client.ios.IOSElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
*
|
*
|
||||||
* @date 2017年12月1日 上午9:29:40
|
* @date 2017年12月1日 上午9:29:40
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class AppiumInitialization {
|
public class AppiumInitialization {
|
||||||
/**
|
/**
|
||||||
* 初始化AndroidAppium
|
* 初始化AndroidAppium
|
||||||
*
|
* @param properties 配置文件对象
|
||||||
* @throws IOException
|
* @return 返回安卓appium对象
|
||||||
*/
|
* @throws IOException 抛异常
|
||||||
public static AndroidDriver<AndroidElement> setAndroidAppium(Properties properties) throws IOException {
|
*/
|
||||||
AndroidDriver<AndroidElement> appium = null;
|
public static AndroidDriver<AndroidElement> setAndroidAppium(Properties properties) throws IOException {
|
||||||
DesiredCapabilities capabilities = new DesiredCapabilities();
|
AndroidDriver<AndroidElement> appium;
|
||||||
File directory = new File("");
|
DesiredCapabilities capabilities = new DesiredCapabilities();
|
||||||
File app = new File(directory.getCanonicalPath() + File.separator + properties.getProperty("appname"));
|
File directory = new File("");
|
||||||
capabilities.setCapability("app", app.getAbsolutePath());
|
File app = new File(directory.getCanonicalPath() + File.separator + properties.getProperty("appname"));
|
||||||
// 自动化测试服务
|
capabilities.setCapability("app", app.getAbsolutePath());
|
||||||
capabilities.setCapability("automationName", properties.getProperty("automationName"));
|
// 自动化测试服务
|
||||||
// 设备名称
|
capabilities.setCapability("automationName", properties.getProperty("automationName"));
|
||||||
capabilities.setCapability("deviceName", properties.getProperty("deviceName"));
|
// 设备名称
|
||||||
// 平台类型
|
capabilities.setCapability("deviceName", properties.getProperty("deviceName"));
|
||||||
capabilities.setCapability("platformName", properties.getProperty("platformName"));
|
// 平台类型
|
||||||
// 系统版本
|
capabilities.setCapability("platformName", properties.getProperty("platformName"));
|
||||||
capabilities.setCapability("platformVersion", properties.getProperty("platformVersion"));
|
// 系统版本
|
||||||
// 模拟器上的ip地址
|
capabilities.setCapability("platformVersion", properties.getProperty("platformVersion"));
|
||||||
capabilities.setCapability("udid", properties.getProperty("udid"));
|
// 模拟器上的ip地址
|
||||||
// Android应用的包名
|
capabilities.setCapability("udid", properties.getProperty("udid"));
|
||||||
capabilities.setCapability("appPackage", properties.getProperty("appPackage"));
|
// Android应用的包名
|
||||||
// 启动的Android Activity
|
capabilities.setCapability("appPackage", properties.getProperty("appPackage"));
|
||||||
capabilities.setCapability("appActivity", properties.getProperty("appActivity"));
|
// 启动的Android Activity
|
||||||
// 支持中文输入,会自动安装Unicode输入
|
capabilities.setCapability("appActivity", properties.getProperty("appActivity"));
|
||||||
capabilities.setCapability("unicodeKeyboard", Boolean.valueOf(properties.getProperty("unicodeKeyboard")));
|
// 支持中文输入,会自动安装Unicode输入
|
||||||
// 重置输入法到原有状态
|
capabilities.setCapability("unicodeKeyboard", Boolean.valueOf(properties.getProperty("unicodeKeyboard")));
|
||||||
capabilities.setCapability("resetKeyboard", Boolean.valueOf(properties.getProperty("resetKeyboard")));
|
// 重置输入法到原有状态
|
||||||
// 不重新签名apk
|
capabilities.setCapability("resetKeyboard", Boolean.valueOf(properties.getProperty("resetKeyboard")));
|
||||||
capabilities.setCapability("noSign", Boolean.valueOf(properties.getProperty("noSign")));
|
// 不重新签名apk
|
||||||
// 是否避免重新安装APP
|
capabilities.setCapability("noSign", Boolean.valueOf(properties.getProperty("noSign")));
|
||||||
capabilities.setCapability("noReset", Boolean.valueOf(properties.getProperty("noReset")));
|
// 是否避免重新安装APP
|
||||||
// 等待超时没接收到命令关闭appium
|
capabilities.setCapability("noReset", Boolean.valueOf(properties.getProperty("noReset")));
|
||||||
capabilities.setCapability("newCommandTimeout", properties.getProperty("newCommandTimeout"));
|
// 等待超时没接收到命令关闭appium
|
||||||
String url="http://" + properties.getProperty("appiumsever") + "/wd/hub";
|
capabilities.setCapability("newCommandTimeout", properties.getProperty("newCommandTimeout"));
|
||||||
appium = new AndroidDriver<AndroidElement>(new URL(url), capabilities);
|
String url="http://" + properties.getProperty("appiumsever") + "/wd/hub";
|
||||||
int waittime = Integer.valueOf(properties.getProperty("implicitlyWait"));
|
appium = new AndroidDriver<>(new URL(url), capabilities);
|
||||||
appium.manage().timeouts().implicitlyWait(waittime, TimeUnit.SECONDS);
|
int waittime = Integer.parseInt(properties.getProperty("implicitlyWait"));
|
||||||
return appium;
|
appium.manage().timeouts().implicitlyWait(waittime, TimeUnit.SECONDS);
|
||||||
}
|
return appium;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* 初始化IOSAppium
|
/**
|
||||||
*
|
* 初始化IOSAppium
|
||||||
* @throws IOException
|
* @param properties 配置文件对象
|
||||||
*/
|
* @return 返回IOS appium对象
|
||||||
public static IOSDriver<IOSElement> setIosAppium(Properties properties) throws IOException {
|
* @throws IOException 抛出IO异常
|
||||||
IOSDriver<IOSElement> appium = null;
|
*/
|
||||||
DesiredCapabilities capabilities = new DesiredCapabilities();
|
public static IOSDriver<IOSElement> setIosAppium(Properties properties) throws IOException {
|
||||||
File directory = new File("");
|
IOSDriver<IOSElement> appium;
|
||||||
File app = new File(directory.getCanonicalPath() + File.separator + properties.getProperty("appname"));
|
DesiredCapabilities capabilities = new DesiredCapabilities();
|
||||||
capabilities.setCapability("app", app.getAbsolutePath());
|
File directory = new File("");
|
||||||
// 自动化测试服务
|
File app = new File(directory.getCanonicalPath() + File.separator + properties.getProperty("appname"));
|
||||||
capabilities.setCapability("automationName", properties.getProperty("automationName"));
|
capabilities.setCapability("app", app.getAbsolutePath());
|
||||||
// 设备名称
|
// 自动化测试服务
|
||||||
capabilities.setCapability("deviceName", properties.getProperty("deviceName"));
|
capabilities.setCapability("automationName", properties.getProperty("automationName"));
|
||||||
// 平台类型
|
// 设备名称
|
||||||
capabilities.setCapability("platformName", properties.getProperty("platformName"));
|
capabilities.setCapability("deviceName", properties.getProperty("deviceName"));
|
||||||
// 系统版本
|
// 平台类型
|
||||||
capabilities.setCapability("platformVersion", properties.getProperty("platformVersion"));
|
capabilities.setCapability("platformName", properties.getProperty("platformName"));
|
||||||
// 模拟器上的ip地址
|
// 系统版本
|
||||||
capabilities.setCapability("udid", properties.getProperty("udid"));
|
capabilities.setCapability("platformVersion", properties.getProperty("platformVersion"));
|
||||||
// 支持中文输入,会自动安装Unicode输入
|
// 模拟器上的ip地址
|
||||||
capabilities.setCapability("unicodeKeyboard", Boolean.valueOf(properties.getProperty("unicodeKeyboard")));
|
capabilities.setCapability("udid", properties.getProperty("udid"));
|
||||||
// 重置输入法到原有状态
|
// 支持中文输入,会自动安装Unicode输入
|
||||||
capabilities.setCapability("resetKeyboard", Boolean.valueOf(properties.getProperty("resetKeyboard")));
|
capabilities.setCapability("unicodeKeyboard", Boolean.valueOf(properties.getProperty("unicodeKeyboard")));
|
||||||
// 不重新签名apk
|
// 重置输入法到原有状态
|
||||||
capabilities.setCapability("noSign", Boolean.valueOf(properties.getProperty("noSign")));
|
capabilities.setCapability("resetKeyboard", Boolean.valueOf(properties.getProperty("resetKeyboard")));
|
||||||
// 是否避免重新安装APP
|
// 不重新签名apk
|
||||||
capabilities.setCapability("noReset", Boolean.valueOf(properties.getProperty("noReset")));
|
capabilities.setCapability("noSign", Boolean.valueOf(properties.getProperty("noSign")));
|
||||||
// 等待超时没接收到命令关闭appium
|
// 是否避免重新安装APP
|
||||||
capabilities.setCapability("newCommandTimeout", properties.getProperty("newCommandTimeout"));
|
capabilities.setCapability("noReset", Boolean.valueOf(properties.getProperty("noReset")));
|
||||||
String url="http://" + properties.getProperty("appiumsever") + "/wd/hub";
|
// 等待超时没接收到命令关闭appium
|
||||||
appium = new IOSDriver<IOSElement>(new URL(url),capabilities);
|
capabilities.setCapability("newCommandTimeout", properties.getProperty("newCommandTimeout"));
|
||||||
int waittime = Integer.valueOf(properties.getProperty("implicitlyWait"));
|
String url="http://" + properties.getProperty("appiumsever") + "/wd/hub";
|
||||||
appium.manage().timeouts().implicitlyWait(waittime, TimeUnit.SECONDS);
|
appium = new IOSDriver<>(new URL(url), capabilities);
|
||||||
return appium;
|
int waittime = Integer.parseInt(properties.getProperty("implicitlyWait"));
|
||||||
}
|
appium.manage().timeouts().implicitlyWait(waittime, TimeUnit.SECONDS);
|
||||||
|
return appium;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,48 +1,48 @@
|
||||||
package luckyclient.execution.appium;
|
package luckyclient.execution.appium;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import io.appium.java_client.service.local.AppiumDriverLocalService;
|
import io.appium.java_client.service.local.AppiumDriverLocalService;
|
||||||
import io.appium.java_client.service.local.AppiumServiceBuilder;
|
import io.appium.java_client.service.local.AppiumServiceBuilder;
|
||||||
import io.appium.java_client.service.local.flags.GeneralServerFlag;
|
import io.appium.java_client.service.local.flags.GeneralServerFlag;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
import luckyclient.utils.config.AppiumConfig;
|
import luckyclient.utils.config.AppiumConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年8月8日
|
* @date 2019年8月8日
|
||||||
*/
|
*/
|
||||||
public class AppiumService extends Thread{
|
public class AppiumService extends Thread{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run(){
|
||||||
try{
|
try{
|
||||||
Properties properties = AppiumConfig.getConfiguration();
|
Properties properties = AppiumConfig.getConfiguration();
|
||||||
File mainjsFile = new File(properties.getProperty("mainjsPath"));
|
File mainjsFile = new File(properties.getProperty("mainjsPath"));
|
||||||
String ip=properties.getProperty("appiumsever");
|
String ip=properties.getProperty("appiumsever");
|
||||||
AppiumServiceBuilder builder =
|
AppiumServiceBuilder builder =
|
||||||
new AppiumServiceBuilder().withArgument(GeneralServerFlag.SESSION_OVERRIDE)
|
new AppiumServiceBuilder().withArgument(GeneralServerFlag.SESSION_OVERRIDE)
|
||||||
.withIPAddress(ip.split(":")[0].trim())
|
.withIPAddress(ip.split(":")[0].trim())
|
||||||
.withAppiumJS(mainjsFile)
|
.withAppiumJS(mainjsFile)
|
||||||
.usingPort(Integer.valueOf(ip.split(":")[1].trim()));
|
.usingPort(Integer.parseInt(ip.split(":")[1].trim()));
|
||||||
|
|
||||||
AppiumDriverLocalService service = AppiumDriverLocalService.buildService(builder);
|
AppiumDriverLocalService service = AppiumDriverLocalService.buildService(builder);
|
||||||
service.start();
|
service.start();
|
||||||
|
|
||||||
if (service == null || !service.isRunning()){
|
if (!service.isRunning()){
|
||||||
LogUtil.APP.warn("自动启动Appium服务失败,请检查!");
|
LogUtil.APP.warn("自动启动Appium服务失败,请检查!");
|
||||||
}else{
|
}else{
|
||||||
LogUtil.APP.info("自动启动Appium服务成功,监听IP:{} 监听端口:{}",ip.split(":")[0].trim(),ip.split(":")[1].trim());
|
LogUtil.APP.info("自动启动Appium服务成功,监听IP:{} 监听端口:{}",ip.split(":")[0].trim(),ip.split(":")[1].trim());
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
LogUtil.APP.error("自动启动Appium服务抛出异常,请检查!",e);
|
LogUtil.APP.error("自动启动Appium服务抛出异常,请检查!",e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,73 +1,73 @@
|
||||||
package luckyclient.execution.appium;
|
package luckyclient.execution.appium;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.appium.java_client.android.AndroidDriver;
|
import io.appium.java_client.android.AndroidDriver;
|
||||||
import io.appium.java_client.android.AndroidElement;
|
import io.appium.java_client.android.AndroidElement;
|
||||||
import luckyclient.execution.appium.androidex.AndroidCaseExecution;
|
import luckyclient.execution.appium.androidex.AndroidCaseExecution;
|
||||||
import luckyclient.remote.api.GetServerApi;
|
import luckyclient.remote.api.GetServerApi;
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.ProjectCase;
|
||||||
import luckyclient.remote.entity.ProjectCaseParams;
|
import luckyclient.remote.entity.ProjectCaseParams;
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
import luckyclient.remote.entity.ProjectCaseSteps;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
||||||
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
* @date 2017年12月1日 上午9:29:40
|
* @date 2017年12月1日 上午9:29:40
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class CaseLocalDebug{
|
public class CaseLocalDebug{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单个移动端用例调试
|
* 单个移动端用例调试
|
||||||
* @param appium
|
* @param appium appium初始化对象
|
||||||
* @param testCaseExternalId
|
* @param testCaseExternalId 用例编号
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2020年1月20日
|
* @date 2020年1月20日
|
||||||
*/
|
*/
|
||||||
public static void oneCasedebug(AndroidDriver<AndroidElement> appium,String testCaseExternalId){
|
public static void oneCasedebug(AndroidDriver<AndroidElement> appium,String testCaseExternalId){
|
||||||
//不记录日志到数据库
|
//不记录日志到数据库
|
||||||
serverOperation.exetype = 1;
|
serverOperation.exetype = 1;
|
||||||
serverOperation caselog = new serverOperation();
|
serverOperation caselog = new serverOperation();
|
||||||
try {
|
try {
|
||||||
ProjectCase testcase = GetServerApi.cgetCaseBysign(testCaseExternalId);
|
ProjectCase testcase = GetServerApi.cgetCaseBysign(testCaseExternalId);
|
||||||
List<ProjectCaseParams> pcplist=GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
|
List<ProjectCaseParams> pcplist=GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
|
||||||
LogUtil.APP.info("开始执行用例:【{}】......",testCaseExternalId);
|
LogUtil.APP.info("开始执行用例:【{}】......",testCaseExternalId);
|
||||||
List<ProjectCaseSteps> steps=GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
List<ProjectCaseSteps> steps=GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
||||||
AndroidCaseExecution.caseExcution(testcase, steps, "888888", appium, caselog, pcplist);
|
AndroidCaseExecution.caseExcution(testcase, steps, "888888", appium, caselog, pcplist);
|
||||||
LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
|
LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
||||||
}
|
}
|
||||||
//退出
|
//退出
|
||||||
appium.quit();
|
appium.quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 多个移动端用例调试
|
* 多个移动端用例调试
|
||||||
* @param appium
|
* @param appium appium对象
|
||||||
* @param projectname
|
* @param projectname 项目名
|
||||||
* @param addtestcase
|
* @param addtestcase 用例对象集
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2020年1月20日
|
* @date 2020年1月20日
|
||||||
*/
|
*/
|
||||||
public static void moreCaseDebug(AndroidDriver<AndroidElement> appium,String projectname,List<String> addtestcase){
|
public static void moreCaseDebug(AndroidDriver<AndroidElement> appium,String projectname,List<String> addtestcase){
|
||||||
System.out.println("当前调试用例总共:"+addtestcase.size());
|
System.out.println("当前调试用例总共:"+addtestcase.size());
|
||||||
for(String testCaseExternalId:addtestcase) {
|
for(String testCaseExternalId:addtestcase) {
|
||||||
try{
|
try{
|
||||||
LogUtil.APP.info("开始调用方法,项目名:{},用例编号:{}",projectname,testCaseExternalId);
|
LogUtil.APP.info("开始调用方法,项目名:{},用例编号:{}",projectname,testCaseExternalId);
|
||||||
oneCasedebug(appium,testCaseExternalId);
|
oneCasedebug(appium,testCaseExternalId);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
continue;
|
LogUtil.APP.info("运行用例 出现异常,用例编号:{}",testCaseExternalId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,20 +23,15 @@ import luckyclient.utils.LogUtil;
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
*
|
|
||||||
* @date 2017年12月1日 上午9:29:40
|
* @date 2017年12月1日 上午9:29:40
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class AndroidBaseAppium {
|
public class AndroidBaseAppium {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 安卓手机报错截图
|
* 安卓手机报错截图
|
||||||
*
|
* @param appium appium初始化对象
|
||||||
* @param appium
|
* @param imagname 截图名称
|
||||||
* @param imagname
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
public static void screenShot(AndroidDriver<AndroidElement> appium, String imagname) {
|
public static void screenShot(AndroidDriver<AndroidElement> appium, String imagname) {
|
||||||
imagname = imagname + ".png";
|
imagname = imagname + ".png";
|
||||||
|
@ -64,33 +59,31 @@ public class AndroidBaseAppium {
|
||||||
/**
|
/**
|
||||||
* appium不支持中文输入 参考了robotium的以js方式为元素直接设置value的做法
|
* appium不支持中文输入 参考了robotium的以js方式为元素直接设置value的做法
|
||||||
* 利用Selenium中Webdriver执行js方法实现中文输入
|
* 利用Selenium中Webdriver执行js方法实现中文输入
|
||||||
* @param appium
|
* @param appium appium初始化对象
|
||||||
* @param preferences
|
* @param preferences 对象名称
|
||||||
* @param value
|
* @param value 传入值
|
||||||
*/
|
*/
|
||||||
public static void sendChinese(AndroidDriver<AndroidElement> appium, String preferences, String value) {
|
public static void sendChinese(AndroidDriver<AndroidElement> appium, String preferences, String value) {
|
||||||
org.openqa.selenium.JavascriptExecutor jse = (org.openqa.selenium.JavascriptExecutor) appium;
|
((JavascriptExecutor) appium).executeScript("document.getElementByName('" + preferences + "').value='" + value + "'");
|
||||||
jse.executeScript("document.getElementByName('" + preferences + "').value='" + value + "'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* js webview 支持4.1~4.4
|
* js webview 支持4.1~4.4 页面滑动
|
||||||
* @param appium
|
* @param appium appium初始化对象
|
||||||
* @param sX
|
* @param sX 开始X坐标
|
||||||
* @param sY
|
* @param sY 开始Y坐标
|
||||||
* @param eX
|
* @param eX 结束X坐标
|
||||||
* @param eY
|
* @param eY 结束Y坐标
|
||||||
* @param duration
|
* @param duration 持续时间
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public static void webViewSwipe(AndroidDriver<AndroidElement> appium, Double sX, Double sY, Double eX, Double eY,
|
public static void webViewSwipe(AndroidDriver<AndroidElement> appium, Double sX, Double sY, Double eX, Double eY,
|
||||||
Double duration) throws Exception {
|
Double duration) {
|
||||||
JavascriptExecutor js;
|
JavascriptExecutor js;
|
||||||
HashMap<String, Double> swipeObject;
|
HashMap<String, Double> swipeObject;
|
||||||
try {
|
try {
|
||||||
// 滑动
|
// 滑动
|
||||||
js = (JavascriptExecutor) appium;
|
js = appium;
|
||||||
swipeObject = new HashMap<String, Double>(5);
|
swipeObject = new HashMap<>(5);
|
||||||
swipeObject.put("startX", sX);
|
swipeObject.put("startX", sX);
|
||||||
swipeObject.put("startY", sY);
|
swipeObject.put("startY", sY);
|
||||||
swipeObject.put("endX", eX);
|
swipeObject.put("endX", eX);
|
||||||
|
@ -100,23 +93,18 @@ public class AndroidBaseAppium {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
LogUtil.APP.error("安卓手机滑动出现异常",e);
|
LogUtil.APP.error("安卓手机滑动出现异常",e);
|
||||||
} finally {
|
|
||||||
// 释放变量
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 调用 ADB直接滑动 支持4.1~4.4
|
* 调用 ADB直接滑动 支持4.1~4.4
|
||||||
* @param appium
|
* @param appium appium初始化对象
|
||||||
* @param sX
|
* @param sX 开始X坐标
|
||||||
* @param sY
|
* @param sY 开始Y坐标
|
||||||
* @param eX
|
* @param eX 结束X坐标
|
||||||
* @param eY
|
* @param eY 结束Y坐标
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public static void adbSwipe(AndroidDriver<AndroidElement> appium, Double sX, Double sY, Double eX, Double eY)
|
public static void adbSwipe(AndroidDriver<AndroidElement> appium, Double sX, Double sY, Double eX, Double eY) {
|
||||||
throws Exception {
|
|
||||||
int xLine;
|
int xLine;
|
||||||
int yLine;
|
int yLine;
|
||||||
int sX2;
|
int sX2;
|
||||||
|
@ -138,36 +126,30 @@ public class AndroidBaseAppium {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
LogUtil.APP.error("安卓手机调用 ADB直接滑动出现异常",e);
|
LogUtil.APP.error("安卓手机调用 ADB直接滑动出现异常",e);
|
||||||
} finally {
|
|
||||||
// 释放变量
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 屏幕点击事件
|
* 屏幕点击事件
|
||||||
* @param drivers
|
* @param drivers appium初始化对象
|
||||||
* @param x
|
* @param x 点击X坐标
|
||||||
* @param y
|
* @param y 点击Y坐标
|
||||||
* @param duration
|
* @param duration 持续时间
|
||||||
*/
|
*/
|
||||||
public static void clickScreenForJs(AndroidDriver<AndroidElement> drivers, int x, int y, int duration) {
|
public static void clickScreenForJs(AndroidDriver<AndroidElement> drivers, int x, int y, int duration) {
|
||||||
JavascriptExecutor js = (JavascriptExecutor) drivers;
|
HashMap<String, Integer> tapObject = new HashMap<>(3);
|
||||||
HashMap<String, Integer> tapObject = new HashMap<String, Integer>(3);
|
|
||||||
tapObject.put("x", x);
|
tapObject.put("x", x);
|
||||||
tapObject.put("y", y);
|
tapObject.put("y", y);
|
||||||
tapObject.put("duration", duration);
|
tapObject.put("duration", duration);
|
||||||
js.executeScript("mobile: tap", tapObject);
|
((JavascriptExecutor) drivers).executeScript("mobile: tap", tapObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 拖住页面按屏幕比例向上滑动(手指向下,页面向上)
|
* 拖住页面按屏幕比例向上滑动(手指向下,页面向上)
|
||||||
*
|
* @param driver appium初始化对象
|
||||||
* @param driver
|
* @param second 持续时间
|
||||||
* @param second
|
* @param num 滚动次数
|
||||||
* 持续时间
|
|
||||||
* @param num
|
|
||||||
* 滚动次数
|
|
||||||
*/
|
*/
|
||||||
public static void swipePageUp(AndroidDriver<AndroidElement> driver, Double second, int num) {
|
public static void swipePageUp(AndroidDriver<AndroidElement> driver, Double second, int num) {
|
||||||
int nanos = (int) (second * 1000);
|
int nanos = (int) (second * 1000);
|
||||||
|
@ -184,10 +166,9 @@ public class AndroidBaseAppium {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 拖住页面按屏幕比例向下滑动(手指向上,页面向下)
|
* 拖住页面按屏幕比例向下滑动(手指向上,页面向下)
|
||||||
*
|
* @param driver appium初始化对象
|
||||||
* @param driver
|
* @param second 持续时间
|
||||||
* @param second
|
* @param num 滑动次数
|
||||||
* @param num
|
|
||||||
*/
|
*/
|
||||||
public static void swipePageDown(AndroidDriver<AndroidElement> driver, Double second, int num) {
|
public static void swipePageDown(AndroidDriver<AndroidElement> driver, Double second, int num) {
|
||||||
int nanos = (int) (second * 1000);
|
int nanos = (int) (second * 1000);
|
||||||
|
@ -203,10 +184,9 @@ public class AndroidBaseAppium {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 拖住页面按屏幕比例向左滑动(手指向左,页面向左滚动)
|
* 拖住页面按屏幕比例向左滑动(手指向左,页面向左滚动)
|
||||||
*
|
* @param driver appium初始化对象
|
||||||
* @param driver
|
* @param second 持续时间
|
||||||
* @param second
|
* @param num 滑动次数
|
||||||
* @param num
|
|
||||||
*/
|
*/
|
||||||
public static void swipePageLeft(AndroidDriver<AndroidElement> driver, Double second, int num) {
|
public static void swipePageLeft(AndroidDriver<AndroidElement> driver, Double second, int num) {
|
||||||
int nanos = (int) (second * 1000);
|
int nanos = (int) (second * 1000);
|
||||||
|
@ -222,10 +202,9 @@ public class AndroidBaseAppium {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 拖住页面按屏幕比例向右滑动(手指向右,页面向右)
|
* 拖住页面按屏幕比例向右滑动(手指向右,页面向右)
|
||||||
*
|
* @param driver appium初始化对象
|
||||||
* @param driver
|
* @param second 持续时间
|
||||||
* @param second
|
* @param num 滑动次数
|
||||||
* @param num
|
|
||||||
*/
|
*/
|
||||||
public static void swipePageRight(AndroidDriver<AndroidElement> driver, Double second, int num) {
|
public static void swipePageRight(AndroidDriver<AndroidElement> driver, Double second, int num) {
|
||||||
int nanos = (int) (second * 1000);
|
int nanos = (int) (second * 1000);
|
||||||
|
|
|
@ -1,97 +1,95 @@
|
||||||
package luckyclient.execution.appium.androidex;
|
package luckyclient.execution.appium.androidex;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import io.appium.java_client.android.AndroidDriver;
|
import io.appium.java_client.android.AndroidDriver;
|
||||||
import io.appium.java_client.android.AndroidElement;
|
import io.appium.java_client.android.AndroidElement;
|
||||||
import luckyclient.execution.appium.AppiumInitialization;
|
import luckyclient.execution.appium.AppiumInitialization;
|
||||||
import luckyclient.execution.appium.AppiumService;
|
import luckyclient.execution.appium.AppiumService;
|
||||||
import luckyclient.execution.httpinterface.TestControl;
|
import luckyclient.execution.httpinterface.TestControl;
|
||||||
import luckyclient.remote.api.GetServerApi;
|
import luckyclient.remote.api.GetServerApi;
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.ProjectCase;
|
||||||
import luckyclient.remote.entity.ProjectCaseParams;
|
import luckyclient.remote.entity.ProjectCaseParams;
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
import luckyclient.remote.entity.ProjectCaseSteps;
|
||||||
import luckyclient.remote.entity.TaskExecute;
|
import luckyclient.remote.entity.TaskExecute;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
import luckyclient.utils.config.AppiumConfig;
|
import luckyclient.utils.config.AppiumConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
*
|
*
|
||||||
* @date 2018年1月26日 上午15:29:40
|
* @date 2018年1月26日 上午15:29:40
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class AndroidBatchExecute {
|
public class AndroidBatchExecute {
|
||||||
|
|
||||||
public static void batchCaseExecuteForTast(String projectname, String taskid, String batchcase) throws IOException, InterruptedException {
|
public static void batchCaseExecuteForTast(String taskid, String batchcase) throws IOException, InterruptedException {
|
||||||
// 记录日志到数据库
|
// 记录日志到数据库
|
||||||
serverOperation.exetype = 0;
|
serverOperation.exetype = 0;
|
||||||
TestControl.TASKID = taskid;
|
TestControl.TASKID = taskid;
|
||||||
AndroidDriver<AndroidElement> ad = null;
|
AndroidDriver<AndroidElement> ad = null;
|
||||||
AppiumService as=null;
|
AppiumService as=null;
|
||||||
try {
|
try {
|
||||||
Properties properties = AppiumConfig.getConfiguration();
|
Properties properties = AppiumConfig.getConfiguration();
|
||||||
//根据配置自动启动Appiume服务
|
//根据配置自动启动Appiume服务
|
||||||
if(Boolean.valueOf(properties.getProperty("autoRunAppiumService"))){
|
if(Boolean.parseBoolean(properties.getProperty("autoRunAppiumService"))){
|
||||||
as =new AppiumService();
|
as =new AppiumService();
|
||||||
as.start();
|
as.start();
|
||||||
Thread.sleep(10000);
|
Thread.sleep(10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
ad = AppiumInitialization.setAndroidAppium(properties);
|
ad = AppiumInitialization.setAndroidAppium(properties);
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
// TODO Auto-generated catch block
|
LogUtil.APP.error("安卓手机根据配置自动启动Appiume服务出现异常",e);
|
||||||
LogUtil.APP.error("安卓手机根据配置自动启动Appiume服务出现异常",e);
|
}
|
||||||
}
|
serverOperation caselog = new serverOperation();
|
||||||
serverOperation caselog = new serverOperation();
|
TaskExecute task = GetServerApi.cgetTaskbyid(Integer.parseInt(taskid));
|
||||||
TaskExecute task = GetServerApi.cgetTaskbyid(Integer.valueOf(taskid));
|
List<ProjectCaseParams> pcplist = GetServerApi
|
||||||
List<ProjectCaseParams> pcplist = GetServerApi
|
.cgetParamsByProjectid(task.getProjectId().toString());
|
||||||
.cgetParamsByProjectid(task.getProjectId().toString());
|
// 执行全部非成功状态用例
|
||||||
// 执行全部非成功状态用例
|
if (batchcase.contains("ALLFAIL")) {
|
||||||
if (batchcase.indexOf("ALLFAIL") > -1) {
|
List<Integer> caseIdList = caselog.getCaseListForUnSucByTaskId(taskid);
|
||||||
List<Integer> caseIdList = caselog.getCaseListForUnSucByTaskId(taskid);
|
for (Integer integer : caseIdList) {
|
||||||
for (int i = 0; i < caseIdList.size(); i++) {
|
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(integer);
|
||||||
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(caseIdList.get(i));
|
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
||||||
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
// 删除旧的日志
|
||||||
// 删除旧的日志
|
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
||||||
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
try {
|
||||||
try {
|
AndroidCaseExecution.caseExcution(testcase, steps, taskid, ad, caselog, pcplist);
|
||||||
AndroidCaseExecution.caseExcution(testcase, steps, taskid, ad, caselog, pcplist);
|
} catch (Exception e) {
|
||||||
} catch (InterruptedException e) {
|
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
||||||
// TODO Auto-generated catch block
|
}
|
||||||
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
}
|
||||||
}
|
} else { // 批量执行用例
|
||||||
}
|
String[] temp = batchcase.split("#");
|
||||||
} else { // 批量执行用例
|
for (String s : temp) {
|
||||||
String[] temp = batchcase.split("\\#");
|
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(Integer.valueOf(s));
|
||||||
for (int i = 0; i < temp.length; i++) {
|
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
||||||
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(Integer.valueOf(temp[i]));
|
// 删除旧的日志
|
||||||
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
||||||
// 删除旧的日志
|
try {
|
||||||
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
AndroidCaseExecution.caseExcution(testcase, steps, taskid, ad, caselog, pcplist);
|
||||||
try {
|
} catch (Exception e) {
|
||||||
AndroidCaseExecution.caseExcution(testcase, steps, taskid, ad, caselog, pcplist);
|
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
||||||
} catch (InterruptedException e) {
|
}
|
||||||
// TODO Auto-generated catch block
|
}
|
||||||
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
}
|
||||||
}
|
serverOperation.updateTaskExecuteData(taskid, 0,2);
|
||||||
}
|
assert ad != null;
|
||||||
}
|
ad.closeApp();
|
||||||
serverOperation.updateTaskExecuteData(taskid, 0,2);
|
//关闭Appium服务的线程
|
||||||
ad.closeApp();
|
if(as!=null){
|
||||||
//关闭Appium服务的线程
|
as.interrupt();
|
||||||
if(as!=null){
|
}
|
||||||
as.interrupt();
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,323 +1,319 @@
|
||||||
package luckyclient.execution.appium.androidex;
|
package luckyclient.execution.appium.androidex;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.util.Date;
|
||||||
import java.util.Date;
|
import java.util.HashMap;
|
||||||
import java.util.HashMap;
|
import java.util.List;
|
||||||
import java.util.List;
|
import java.util.Map;
|
||||||
import java.util.Map;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Pattern;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
import io.appium.java_client.android.AndroidDriver;
|
||||||
import io.appium.java_client.android.AndroidDriver;
|
import io.appium.java_client.android.AndroidElement;
|
||||||
import io.appium.java_client.android.AndroidElement;
|
import luckyclient.execution.appium.AppDriverAnalyticCase;
|
||||||
import luckyclient.execution.appium.AppDriverAnalyticCase;
|
import luckyclient.execution.dispose.ActionManageForSteps;
|
||||||
import luckyclient.execution.dispose.ActionManageForSteps;
|
import luckyclient.execution.dispose.ChangString;
|
||||||
import luckyclient.execution.dispose.ChangString;
|
import luckyclient.execution.dispose.ParamsManageForSteps;
|
||||||
import luckyclient.execution.dispose.ParamsManageForSteps;
|
import luckyclient.execution.httpinterface.TestCaseExecution;
|
||||||
import luckyclient.execution.httpinterface.TestCaseExecution;
|
import luckyclient.execution.httpinterface.analyticsteps.InterfaceAnalyticCase;
|
||||||
import luckyclient.execution.httpinterface.analyticsteps.InterfaceAnalyticCase;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.entity.ProjectCase;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.ProjectCaseParams;
|
||||||
import luckyclient.remote.entity.ProjectCaseParams;
|
import luckyclient.remote.entity.ProjectCaseSteps;
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
import luckyclient.utils.Constants;
|
||||||
import luckyclient.utils.Constants;
|
import luckyclient.utils.LogUtil;
|
||||||
import luckyclient.utils.LogUtil;
|
|
||||||
|
/**
|
||||||
/**
|
* =================================================================
|
||||||
* =================================================================
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* =================================================================
|
||||||
* =================================================================
|
* @author seagull
|
||||||
*
|
* @date 2018年1月21日 上午15:12:48
|
||||||
* @author seagull
|
*/
|
||||||
* @date 2018年1月21日 上午15:12:48
|
public class AndroidCaseExecution{
|
||||||
*/
|
static Map<String, String> variable = new HashMap<>();
|
||||||
public class AndroidCaseExecution{
|
private static String casenote = "备注初始化";
|
||||||
static Map<String, String> variable = new HashMap<String, String>();
|
|
||||||
private static String casenote = "备注初始化";
|
public static void caseExcution(ProjectCase testcase, List<ProjectCaseSteps> steps,String taskid, AndroidDriver<AndroidElement> appium,serverOperation caselog,List<ProjectCaseParams> pcplist) {
|
||||||
private static String imagname = "";
|
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), 3);
|
||||||
|
// 把公共参数加入到MAP中
|
||||||
public static void caseExcution(ProjectCase testcase, List<ProjectCaseSteps> steps,String taskid, AndroidDriver<AndroidElement> appium,serverOperation caselog,List<ProjectCaseParams> pcplist)
|
for (ProjectCaseParams pcp : pcplist) {
|
||||||
throws InterruptedException, IOException {
|
variable.put(pcp.getParamsName(), pcp.getParamsValue());
|
||||||
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), 3);
|
}
|
||||||
// 把公共参数加入到MAP中
|
// 加入全局变量
|
||||||
for (ProjectCaseParams pcp : pcplist) {
|
variable.putAll(ParamsManageForSteps.GLOBAL_VARIABLE);
|
||||||
variable.put(pcp.getParamsName(), pcp.getParamsValue());
|
// 0通过 1失败 2锁定 3执行中 4未执行
|
||||||
}
|
int setcaseresult = 0;
|
||||||
// 加入全局变量
|
for (ProjectCaseSteps step : steps) {
|
||||||
variable.putAll(ParamsManageForSteps.GLOBAL_VARIABLE);
|
Map<String, String> params;
|
||||||
// 0通过 1失败 2锁定 3执行中 4未执行
|
String result;
|
||||||
int setcaseresult = 0;
|
|
||||||
for (ProjectCaseSteps step : steps) {
|
// 根据步骤类型来分析步骤参数
|
||||||
Map<String, String> params;
|
if (3 == step.getStepType()){
|
||||||
String result;
|
params = AppDriverAnalyticCase.analyticCaseStep(testcase, step, taskid,caselog,variable);
|
||||||
|
}else{
|
||||||
// 根据步骤类型来分析步骤参数
|
params = InterfaceAnalyticCase.analyticCaseStep(testcase, step, taskid, caselog,variable);
|
||||||
if (3 == step.getStepType()){
|
}
|
||||||
params = AppDriverAnalyticCase.analyticCaseStep(testcase, step, taskid,caselog,variable);
|
|
||||||
}else{
|
if(null != params.get("exception") && params.get("exception").contains("解析异常")){
|
||||||
params = InterfaceAnalyticCase.analyticCaseStep(testcase, step, taskid, caselog,variable);
|
setcaseresult = 2;
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
if(null != params.get("exception") && params.get("exception").contains("解析异常")){
|
|
||||||
setcaseresult = 2;
|
// 根据步骤类型来执行步骤
|
||||||
break;
|
if (3 == step.getStepType()){
|
||||||
}
|
result = androidRunStep(params, appium, taskid, testcase.getCaseId(), step.getStepSerialNumber(), caselog);
|
||||||
|
}else{
|
||||||
// 根据步骤类型来执行步骤
|
TestCaseExecution testCaseExecution=new TestCaseExecution();
|
||||||
if (3 == step.getStepType()){
|
result = testCaseExecution.runStep(params, taskid, testcase.getCaseSign(), step, caselog);
|
||||||
result = androidRunStep(params, appium, taskid, testcase.getCaseId(), step.getStepSerialNumber(), caselog);
|
}
|
||||||
}else{
|
|
||||||
TestCaseExecution testCaseExecution=new TestCaseExecution();
|
String expectedResults = params.get("ExpectedResults");
|
||||||
result = testCaseExecution.runStep(params, taskid, testcase.getCaseSign(), step, caselog);
|
expectedResults=ChangString.changparams(expectedResults, variable,"预期结果");
|
||||||
}
|
|
||||||
|
// 判断结果
|
||||||
String expectedResults = params.get("ExpectedResults").toString();
|
int stepresult = judgeResult(testcase, step, params, appium, taskid, expectedResults, result, caselog);
|
||||||
expectedResults=ChangString.changparams(expectedResults, variable,"预期结果");
|
// 失败,并且不在继续,直接终止
|
||||||
|
if (0 != stepresult) {
|
||||||
// 判断结果
|
setcaseresult = stepresult;
|
||||||
int stepresult = judgeResult(testcase, step, params, appium, taskid, expectedResults, result, caselog);
|
if (testcase.getFailcontinue() == 0) {
|
||||||
// 失败,并且不在继续,直接终止
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),step.getStepSerialNumber());
|
||||||
if (0 != stepresult) {
|
break;
|
||||||
setcaseresult = stepresult;
|
} else {
|
||||||
if (testcase.getFailcontinue() == 0) {
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),step.getStepSerialNumber());
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),step.getStepSerialNumber());
|
}
|
||||||
break;
|
}
|
||||||
} else {
|
}
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),step.getStepSerialNumber());
|
|
||||||
}
|
variable.clear();
|
||||||
}
|
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), setcaseresult);
|
||||||
}
|
if(setcaseresult==0){
|
||||||
|
LogUtil.APP.info("用例【{}】全部步骤执行结果成功...",testcase.getCaseSign());
|
||||||
variable.clear();
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例全部步骤执行结果成功","info", "ending","");
|
||||||
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), setcaseresult);
|
}else{
|
||||||
if(setcaseresult==0){
|
LogUtil.APP.warn("用例【{}】步骤执行过程中失败或是锁定...请查看具体原因!【{}】",testcase.getCaseSign(),casenote);
|
||||||
LogUtil.APP.info("用例【{}】全部步骤执行结果成功...",testcase.getCaseSign());
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例执行过程中失败或是锁定"+casenote,"error", "ending","");
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例全部步骤执行结果成功","info", "ending","");
|
}
|
||||||
}else{
|
//LogOperation.UpdateTastdetail(taskid, 0);
|
||||||
LogUtil.APP.warn("用例【{}】步骤执行过程中失败或是锁定...请查看具体原因!【{}】",testcase.getCaseSign(),casenote);
|
}
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例执行过程中失败或是锁定"+casenote,"error", "ending","");
|
|
||||||
}
|
public static String androidRunStep(Map<String, String> params, AndroidDriver<AndroidElement> appium,String taskid,Integer caseId,int stepno,serverOperation caselog) {
|
||||||
//LogOperation.UpdateTastdetail(taskid, 0);
|
String result;
|
||||||
}
|
String property;
|
||||||
|
String propertyValue;
|
||||||
public static String androidRunStep(Map<String, String> params, AndroidDriver<AndroidElement> appium,String taskid,Integer caseId,int stepno,serverOperation caselog) {
|
String operation;
|
||||||
String result = "";
|
String operationValue;
|
||||||
String property;
|
|
||||||
String propertyValue;
|
try {
|
||||||
String operation;
|
property = params.get("property");
|
||||||
String operationValue;
|
propertyValue = params.get("property_value");
|
||||||
|
operation = params.get("operation");
|
||||||
try {
|
operationValue = params.get("operation_value");
|
||||||
property = params.get("property");
|
|
||||||
propertyValue = params.get("property_value");
|
LogUtil.APP.info("二次解析用例过程完成,等待进行对象操作......");
|
||||||
operation = params.get("operation");
|
caselog.insertTaskCaseLog(taskid, caseId, "对象操作:"+operation+"; 操作值:"+operationValue,"info", String.valueOf(stepno),"");
|
||||||
operationValue = params.get("operation_value");
|
} catch (Exception e) {
|
||||||
|
LogUtil.APP.error("二次解析用例过程抛出异常!",e);
|
||||||
LogUtil.APP.info("二次解析用例过程完成,等待进行对象操作......");
|
return "步骤执行失败:解析用例失败!";
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "对象操作:"+operation+"; 操作值:"+operationValue,"info", String.valueOf(stepno),"");
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
LogUtil.APP.error("二次解析用例过程抛出异常!",e);
|
try {
|
||||||
return "步骤执行失败:解析用例失败!";
|
//调用接口用例
|
||||||
}
|
if(null != operationValue && "runcase".equals(operation)){
|
||||||
|
String[] temp=operationValue.split(",",-1);
|
||||||
try {
|
TestCaseExecution testCaseExecution=new TestCaseExecution();
|
||||||
//调用接口用例
|
String ex = testCaseExecution.oneCaseExecuteForUICase(temp[0], taskid, caselog, appium);
|
||||||
if(null != operation&&null != operationValue&&"runcase".equals(operation)){
|
if(!ex.contains("CallCase调用出错!") && !ex.contains("解析出错啦!") && !ex.contains("失败")){
|
||||||
String[] temp=operationValue.split(",",-1);
|
return ex;
|
||||||
TestCaseExecution testCaseExecution=new TestCaseExecution();
|
}else{
|
||||||
String ex = testCaseExecution.oneCaseExecuteForUICase(temp[0], taskid, caselog, appium);
|
return "步骤执行失败:调用接口用例过程失败";
|
||||||
if(!ex.contains("CallCase调用出错!") && !ex.contains("解析出错啦!") && !ex.contains("失败")){
|
}
|
||||||
return ex;
|
}
|
||||||
}else{
|
|
||||||
return "步骤执行失败:调用接口用例过程失败";
|
AndroidElement ae;
|
||||||
}
|
// 页面元素层
|
||||||
}
|
if (null != property && null != propertyValue) {
|
||||||
|
ae = isElementExist(appium, property, propertyValue);
|
||||||
AndroidElement ae = null;
|
// 判断此元素是否存在
|
||||||
// 页面元素层
|
if (null==ae) {
|
||||||
if (null != property && null != propertyValue) {
|
LogUtil.APP.warn("定位对象失败,isElementExist为null!");
|
||||||
ae = isElementExist(appium, property, propertyValue);
|
return "步骤执行失败:isElementExist定位元素过程失败!";
|
||||||
// 判断此元素是否存在
|
}
|
||||||
if (null==ae) {
|
|
||||||
LogUtil.APP.warn("定位对象失败,isElementExist为null!");
|
if (operation.contains("select")) {
|
||||||
return "步骤执行失败:isElementExist定位元素过程失败!";
|
result = AndroidEncapsulateOperation.selectOperation(ae, operation, operationValue);
|
||||||
}
|
} else if (operation.contains("get")){
|
||||||
|
result = AndroidEncapsulateOperation.getOperation(ae, operation,operationValue);
|
||||||
if (operation.indexOf("select") > -1) {
|
} else {
|
||||||
result = AndroidEncapsulateOperation.selectOperation(ae, operation, operationValue);
|
result = AndroidEncapsulateOperation.objectOperation(appium, ae, operation, operationValue, property, propertyValue);
|
||||||
} else if (operation.indexOf("get") > -1){
|
}
|
||||||
result = AndroidEncapsulateOperation.getOperation(ae, operation,operationValue);
|
// Driver层操作
|
||||||
} else {
|
} else if (null==property && null != operation) {
|
||||||
result = AndroidEncapsulateOperation.objectOperation(appium, ae, operation, operationValue, property, propertyValue);
|
// 处理弹出框事件
|
||||||
}
|
if (operation.contains("alert")){
|
||||||
// Driver层操作
|
result = AndroidEncapsulateOperation.alertOperation(appium, operation);
|
||||||
} else if (null==property && null != operation) {
|
}else{
|
||||||
// 处理弹出框事件
|
result = AndroidEncapsulateOperation.driverOperation(appium, operation, operationValue);
|
||||||
if (operation.indexOf("alert") > -1){
|
}
|
||||||
result = AndroidEncapsulateOperation.alertOperation(appium, operation);
|
}else{
|
||||||
}else{
|
LogUtil.APP.warn("元素操作过程失败!");
|
||||||
result = AndroidEncapsulateOperation.driverOperation(appium, operation, operationValue);
|
result = "步骤执行失败:元素操作过程失败!";
|
||||||
}
|
}
|
||||||
}else{
|
} catch (Exception e) {
|
||||||
LogUtil.APP.warn("元素操作过程失败!");
|
LogUtil.APP.error("元素定位过程或是操作过程失败或异常!",e);
|
||||||
result = "步骤执行失败:元素操作过程失败!";
|
return "步骤执行失败:元素定位过程或是操作过程失败或异常!" + e.getMessage();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
caselog.insertTaskCaseLog(taskid, caseId, result,"info", String.valueOf(stepno),"");
|
||||||
LogUtil.APP.error("元素定位过程或是操作过程失败或异常!",e);
|
|
||||||
return "步骤执行失败:元素定位过程或是操作过程失败或异常!" + e.getMessage();
|
if(result.contains("获取到的值是【") && result.contains("】")){
|
||||||
}
|
result = result.substring(result.indexOf("获取到的值是【")+7, result.length()-1);
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, result,"info", String.valueOf(stepno),"");
|
}
|
||||||
|
return result;
|
||||||
if(result.indexOf("获取到的值是【")>-1&&result.indexOf("】")>-1){
|
|
||||||
result = result.substring(result.indexOf("获取到的值是【")+7, result.length()-1);
|
}
|
||||||
}
|
|
||||||
return result;
|
public static AndroidElement isElementExist(AndroidDriver<AndroidElement> appium, String property, String propertyValue) {
|
||||||
|
try {
|
||||||
}
|
AndroidElement ae = null;
|
||||||
|
property=property.toLowerCase();
|
||||||
public static AndroidElement isElementExist(AndroidDriver<AndroidElement> appium, String property, String propertyValue) {
|
// 处理WebElement对象定位
|
||||||
try {
|
switch (property) {
|
||||||
AndroidElement ae = null;
|
case "id":
|
||||||
property=property.toLowerCase();
|
ae = appium.findElementById(propertyValue);
|
||||||
// 处理WebElement对象定位
|
break;
|
||||||
switch (property) {
|
case "name":
|
||||||
case "id":
|
ae = appium.findElementByAndroidUIAutomator("text(\""+propertyValue+"\")");
|
||||||
ae = appium.findElementById(propertyValue);
|
break;
|
||||||
break;
|
case "androiduiautomator":
|
||||||
case "name":
|
ae = appium.findElementByAndroidUIAutomator(propertyValue);
|
||||||
ae = appium.findElementByAndroidUIAutomator("text(\""+propertyValue+"\")");
|
break;
|
||||||
break;
|
case "xpath":
|
||||||
case "androiduiautomator":
|
ae = appium.findElementByXPath(propertyValue);
|
||||||
ae = appium.findElementByAndroidUIAutomator(propertyValue);
|
break;
|
||||||
break;
|
case "linktext":
|
||||||
case "xpath":
|
ae = appium.findElementByLinkText(propertyValue);
|
||||||
ae = appium.findElementByXPath(propertyValue);
|
break;
|
||||||
break;
|
case "tagname":
|
||||||
case "linktext":
|
ae = appium.findElementByTagName(propertyValue);
|
||||||
ae = appium.findElementByLinkText(propertyValue);
|
break;
|
||||||
break;
|
case "cssselector":
|
||||||
case "tagname":
|
ae = appium.findElementByCssSelector(propertyValue);
|
||||||
ae = appium.findElementByTagName(propertyValue);
|
break;
|
||||||
break;
|
case "classname":
|
||||||
case "cssselector":
|
ae = appium.findElementByClassName(propertyValue);
|
||||||
ae = appium.findElementByCssSelector(propertyValue);
|
break;
|
||||||
break;
|
case "partiallinktext":
|
||||||
case "classname":
|
ae = appium.findElementByPartialLinkText(propertyValue);
|
||||||
ae = appium.findElementByClassName(propertyValue);
|
break;
|
||||||
break;
|
default:
|
||||||
case "partiallinktext":
|
break;
|
||||||
ae = appium.findElementByPartialLinkText(propertyValue);
|
}
|
||||||
break;
|
|
||||||
default:
|
return ae;
|
||||||
break;
|
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
LogUtil.APP.error("当前对象定位失败,出现异常!",e);
|
||||||
return ae;
|
return null;
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
LogUtil.APP.error("当前对象定位失败,出现异常!",e);
|
}
|
||||||
return null;
|
|
||||||
}
|
public static int judgeResult(ProjectCase testcase, ProjectCaseSteps step, Map<String, String> params, AndroidDriver<AndroidElement> appium, String taskid, String expect, String result, serverOperation caselog) {
|
||||||
|
int setresult = 0;
|
||||||
}
|
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
|
||||||
|
String imagname = timeformat.format(new Date());
|
||||||
public static int judgeResult(ProjectCase testcase, ProjectCaseSteps step, Map<String, String> params, AndroidDriver<AndroidElement> appium, String taskid, String expect, String result, serverOperation caselog) throws InterruptedException {
|
|
||||||
int setresult = 0;
|
result = ActionManageForSteps.actionManage(step.getAction(), result);
|
||||||
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
|
if (null != result && !result.contains("步骤执行失败:")) {
|
||||||
imagname = timeformat.format(new Date());
|
// 有预期结果
|
||||||
|
if (null != expect && !expect.isEmpty()) {
|
||||||
result = ActionManageForSteps.actionManage(step.getAction(), result);
|
LogUtil.APP.info("期望结果为【{}】",expect);
|
||||||
if (null != result && !result.contains("步骤执行失败:")) {
|
|
||||||
// 有预期结果
|
// 赋值传参模式
|
||||||
if (null != expect && !expect.isEmpty()) {
|
if (expect.length() > Constants.ASSIGNMENT_SIGN.length() && expect.startsWith(Constants.ASSIGNMENT_SIGN)) {
|
||||||
LogUtil.APP.info("期望结果为【{}】",expect);
|
variable.put(expect.substring(Constants.ASSIGNMENT_SIGN.length()), result);
|
||||||
|
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给变量【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),result,expect.substring(Constants.ASSIGNMENT_SIGN.length()));
|
||||||
// 赋值传参模式
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给变量【" + expect.substring(Constants.ASSIGNMENT_SIGN.length()) + "】", "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
if (expect.length() > Constants.ASSIGNMENT_SIGN.length() && expect.startsWith(Constants.ASSIGNMENT_SIGN)) {
|
}
|
||||||
variable.put(expect.substring(Constants.ASSIGNMENT_SIGN.length()), result);
|
// 赋值全局变量
|
||||||
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给变量【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),result,expect.substring(Constants.ASSIGNMENT_SIGN.length()));
|
else if (expect.length() > Constants.ASSIGNMENT_GLOBALSIGN.length() && expect.startsWith(Constants.ASSIGNMENT_GLOBALSIGN)) {
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给变量【" + expect.substring(Constants.ASSIGNMENT_SIGN.length()) + "】", "info", String.valueOf(step.getStepSerialNumber()), "");
|
variable.put(expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), result);
|
||||||
}
|
ParamsManageForSteps.GLOBAL_VARIABLE.put(expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), result);
|
||||||
// 赋值全局变量
|
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给全局变量【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),result,expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()));
|
||||||
else if (expect.length() > Constants.ASSIGNMENT_GLOBALSIGN.length() && expect.startsWith(Constants.ASSIGNMENT_GLOBALSIGN)) {
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给全局变量【" + expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()) + "】", "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
variable.put(expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), result);
|
}
|
||||||
ParamsManageForSteps.GLOBAL_VARIABLE.put(expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), result);
|
// 移动端 UI检查模式
|
||||||
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给全局变量【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),result,expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()));
|
else if (3 == step.getStepType() && params.get("checkproperty") != null && params.get("checkproperty_value") != null) {
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给全局变量【" + expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()) + "】", "info", String.valueOf(step.getStepSerialNumber()), "");
|
String checkproperty = params.get("checkproperty");
|
||||||
}
|
String checkPropertyValue = params.get("checkproperty_value");
|
||||||
// 移动端 UI检查模式
|
|
||||||
else if (3 == step.getStepType() && params.get("checkproperty") != null && params.get("checkproperty_value") != null) {
|
AndroidElement ae = isElementExist(appium, checkproperty, checkPropertyValue);
|
||||||
String checkproperty = params.get("checkproperty");
|
if (null != ae) {
|
||||||
String checkPropertyValue = params.get("checkproperty_value");
|
LogUtil.APP.info("用例:{} 第{}步,在当前页面中找到预期结果中对象。当前步骤执行成功!",testcase.getCaseSign(),step.getStepSerialNumber());
|
||||||
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中找到预期结果中对象。当前步骤执行成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
AndroidElement ae = isElementExist(appium, checkproperty, checkPropertyValue);
|
} else {
|
||||||
if (null != ae) {
|
casenote = "第" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。执行失败!";
|
||||||
LogUtil.APP.info("用例:{} 第{}步,在当前页面中找到预期结果中对象。当前步骤执行成功!",testcase.getCaseSign(),step.getStepSerialNumber());
|
setresult = 1;
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中找到预期结果中对象。当前步骤执行成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
|
AndroidBaseAppium.screenShot(appium, imagname);
|
||||||
} else {
|
LogUtil.APP.warn("用例:{} 第{}步,没有在当前页面中找到预期结果中对象。当前步骤执行失败!",testcase.getCaseSign(),step.getStepSerialNumber());
|
||||||
casenote = "第" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。执行失败!";
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中没有找到预期结果中对象。当前步骤执行失败!" + "checkproperty【" + checkproperty + "】 checkproperty_value【" + checkPropertyValue + "】", "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
||||||
setresult = 1;
|
}
|
||||||
AndroidBaseAppium.screenShot(appium, imagname);
|
}
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,没有在当前页面中找到预期结果中对象。当前步骤执行失败!",testcase.getCaseSign(),step.getStepSerialNumber());
|
// 其它匹配模式
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中没有找到预期结果中对象。当前步骤执行失败!" + "checkproperty【" + checkproperty + "】 checkproperty_value【" + checkPropertyValue + "】", "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
else {
|
||||||
}
|
// 模糊匹配预期结果模式
|
||||||
}
|
if (expect.length() > Constants.FUZZY_MATCHING_SIGN.length() && expect.startsWith(Constants.FUZZY_MATCHING_SIGN)) {
|
||||||
// 其它匹配模式
|
if (result.contains(expect.substring(Constants.FUZZY_MATCHING_SIGN.length()))) {
|
||||||
else {
|
LogUtil.APP.info("用例:{} 第{}步,模糊匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
|
||||||
// 模糊匹配预期结果模式
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果成功!执行结果:" + result, "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
if (expect.length() > Constants.FUZZY_MATCHING_SIGN.length() && expect.startsWith(Constants.FUZZY_MATCHING_SIGN)) {
|
} else {
|
||||||
if (result.contains(expect.substring(Constants.FUZZY_MATCHING_SIGN.length()))) {
|
casenote = "第" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!";
|
||||||
LogUtil.APP.info("用例:{} 第{}步,模糊匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
|
setresult = 1;
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果成功!执行结果:" + result, "info", String.valueOf(step.getStepSerialNumber()), "");
|
AndroidBaseAppium.screenShot(appium, imagname);
|
||||||
} else {
|
LogUtil.APP.warn("用例:{} 第{}步,模糊匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expect.substring(Constants.FUZZY_MATCHING_SIGN.length()),result);
|
||||||
casenote = "第" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!";
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果失败!预期结果:" + expect.substring(Constants.FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
||||||
setresult = 1;
|
}
|
||||||
AndroidBaseAppium.screenShot(appium, imagname);
|
}
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,模糊匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expect.substring(Constants.FUZZY_MATCHING_SIGN.length()),result);
|
// 正则匹配预期结果模式
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果失败!预期结果:" + expect.substring(Constants.FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
else if (expect.length() > Constants.REGULAR_MATCHING_SIGN.length() && expect.startsWith(Constants.REGULAR_MATCHING_SIGN)) {
|
||||||
}
|
Pattern pattern = Pattern.compile(expect.substring(Constants.REGULAR_MATCHING_SIGN.length()));
|
||||||
}
|
Matcher matcher = pattern.matcher(result);
|
||||||
// 正则匹配预期结果模式
|
if (matcher.find()) {
|
||||||
else if (expect.length() > Constants.REGULAR_MATCHING_SIGN.length() && expect.startsWith(Constants.REGULAR_MATCHING_SIGN)) {
|
LogUtil.APP.info("用例:{} 第{}步,正则匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
|
||||||
Pattern pattern = Pattern.compile(expect.substring(Constants.REGULAR_MATCHING_SIGN.length()));
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
Matcher matcher = pattern.matcher(result);
|
} else {
|
||||||
if (matcher.find()) {
|
casenote = "第" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!";
|
||||||
LogUtil.APP.info("用例:{} 第{}步,正则匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
|
setresult = 1;
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
|
AndroidBaseAppium.screenShot(appium, imagname);
|
||||||
} else {
|
LogUtil.APP.warn("用例:{} 第{}步,正则匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expect.substring(Constants.REGULAR_MATCHING_SIGN.length()),result);
|
||||||
casenote = "第" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!";
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果失败!预期结果:" + expect.substring(Constants.REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
||||||
setresult = 1;
|
}
|
||||||
AndroidBaseAppium.screenShot(appium, imagname);
|
}
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,正则匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expect.substring(Constants.REGULAR_MATCHING_SIGN.length()),result);
|
// 精确匹配预期结果模式
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果失败!预期结果:" + expect.substring(Constants.REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
else {
|
||||||
}
|
if (expect.equals(result)) {
|
||||||
}
|
LogUtil.APP.info("用例:{} 第{}步,精确匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
|
||||||
// 精确匹配预期结果模式
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
else {
|
} else {
|
||||||
if (expect.equals(result)) {
|
casenote = "第" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!";
|
||||||
LogUtil.APP.info("用例:{} 第{}步,精确匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
|
setresult = 1;
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
|
AndroidBaseAppium.screenShot(appium, imagname);
|
||||||
} else {
|
LogUtil.APP.warn("用例:{} 第{}步,精确匹配预期结果失败!预期结果是:【{}】 执行结果:【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),expect,result);
|
||||||
casenote = "第" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!";
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果失败!预期结果是:【"+expect+"】 执行结果:【"+ result+"】", "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
||||||
setresult = 1;
|
}
|
||||||
AndroidBaseAppium.screenShot(appium, imagname);
|
}
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,精确匹配预期结果失败!预期结果是:【{}】 执行结果:【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),expect,result);
|
}
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果失败!预期结果是:【"+expect+"】 执行结果:【"+ result+"】", "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
}
|
||||||
}
|
} else {
|
||||||
}
|
casenote = (null != result) ? result : "";
|
||||||
}
|
setresult = 2;
|
||||||
}
|
AndroidBaseAppium.screenShot(appium, imagname);
|
||||||
} else {
|
LogUtil.APP.warn("用例:{} 第{}步,执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),casenote);
|
||||||
casenote = (null != result) ? result : "";
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "当前步骤在执行过程中解析|定位元素|操作对象失败!" + casenote, "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
||||||
setresult = 2;
|
}
|
||||||
AndroidBaseAppium.screenShot(appium, imagname);
|
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),casenote);
|
return setresult;
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "当前步骤在执行过程中解析|定位元素|操作对象失败!" + casenote, "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
return setresult;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package luckyclient.execution.appium.androidex;
|
package luckyclient.execution.appium.androidex;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.appium.java_client.android.AndroidDriver;
|
import io.appium.java_client.android.AndroidDriver;
|
||||||
import io.appium.java_client.android.AndroidElement;
|
import io.appium.java_client.android.AndroidElement;
|
||||||
import luckyclient.remote.api.GetServerApi;
|
import luckyclient.remote.api.GetServerApi;
|
||||||
|
@ -24,6 +22,11 @@ import luckyclient.utils.LogUtil;
|
||||||
*/
|
*/
|
||||||
public class AndroidCaseLocalDebug {
|
public class AndroidCaseLocalDebug {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IDEA工具方式调试测试用例
|
||||||
|
* @param androiddriver 初始化appium对象
|
||||||
|
* @param testCaseExternalId 用例编号
|
||||||
|
*/
|
||||||
public static void oneCasedebug(AndroidDriver<AndroidElement> androiddriver, String testCaseExternalId) {
|
public static void oneCasedebug(AndroidDriver<AndroidElement> androiddriver, String testCaseExternalId) {
|
||||||
// 不记录日志到数据库
|
// 不记录日志到数据库
|
||||||
serverOperation.exetype = 1;
|
serverOperation.exetype = 1;
|
||||||
|
@ -45,9 +48,9 @@ public class AndroidCaseLocalDebug {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用于做多条用例串行调试
|
* 用于做多条用例串行调试
|
||||||
* @param androiddriver
|
* @param androiddriver 初始化appium对象
|
||||||
* @param projectname
|
* @param projectname 项目名称
|
||||||
* @param addtestcase
|
* @param addtestcase 用例集
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年4月18日
|
* @date 2019年4月18日
|
||||||
*/
|
*/
|
||||||
|
@ -61,7 +64,6 @@ public class AndroidCaseLocalDebug {
|
||||||
oneCasedebug(androiddriver, testCaseExternalId);
|
oneCasedebug(androiddriver, testCaseExternalId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.APP.error("多用例调试过程中抛出异常!", e);
|
LogUtil.APP.error("多用例调试过程中抛出异常!", e);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 关闭APP以及appium会话
|
// 关闭APP以及appium会话
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,74 +1,75 @@
|
||||||
package luckyclient.execution.appium.androidex;
|
package luckyclient.execution.appium.androidex;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import io.appium.java_client.android.AndroidDriver;
|
import io.appium.java_client.android.AndroidDriver;
|
||||||
import io.appium.java_client.android.AndroidElement;
|
import io.appium.java_client.android.AndroidElement;
|
||||||
import luckyclient.execution.appium.AppiumInitialization;
|
import luckyclient.execution.appium.AppiumInitialization;
|
||||||
import luckyclient.execution.appium.AppiumService;
|
import luckyclient.execution.appium.AppiumService;
|
||||||
import luckyclient.execution.httpinterface.TestControl;
|
import luckyclient.execution.httpinterface.TestControl;
|
||||||
import luckyclient.remote.api.GetServerApi;
|
import luckyclient.remote.api.GetServerApi;
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.ProjectCase;
|
||||||
import luckyclient.remote.entity.ProjectCaseParams;
|
import luckyclient.remote.entity.ProjectCaseParams;
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
import luckyclient.remote.entity.ProjectCaseSteps;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
import luckyclient.utils.config.AppiumConfig;
|
import luckyclient.utils.config.AppiumConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
*
|
*
|
||||||
* @date 2018年1月26日 上午9:29:40
|
* @date 2018年1月26日 上午9:29:40
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class AndroidOneCaseExecute {
|
public class AndroidOneCaseExecute {
|
||||||
|
|
||||||
public static void oneCaseExecuteForTast(String projectname, Integer caseId, int version, String taskid)
|
public static void oneCaseExecuteForTast(Integer caseId, String taskid)
|
||||||
throws IOException, InterruptedException {
|
throws InterruptedException {
|
||||||
// 记录日志到数据库
|
// 记录日志到数据库
|
||||||
serverOperation.exetype = 0;
|
serverOperation.exetype = 0;
|
||||||
TestControl.TASKID = taskid;
|
TestControl.TASKID = taskid;
|
||||||
AndroidDriver<AndroidElement> ad = null;
|
AndroidDriver<AndroidElement> ad = null;
|
||||||
AppiumService as=null;
|
AppiumService as=null;
|
||||||
try {
|
try {
|
||||||
Properties properties = AppiumConfig.getConfiguration();
|
Properties properties = AppiumConfig.getConfiguration();
|
||||||
//根据配置自动启动Appiume服务
|
//根据配置自动启动Appiume服务
|
||||||
if(Boolean.valueOf(properties.getProperty("autoRunAppiumService"))){
|
if(Boolean.parseBoolean(properties.getProperty("autoRunAppiumService"))){
|
||||||
as =new AppiumService();
|
as =new AppiumService();
|
||||||
as.start();
|
as.start();
|
||||||
Thread.sleep(10000);
|
Thread.sleep(10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
ad = AppiumInitialization.setAndroidAppium(properties);
|
ad = AppiumInitialization.setAndroidAppium(properties);
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
LogUtil.APP.error("初始化AndroidDriver出错!", e1);
|
LogUtil.APP.error("初始化AndroidDriver出错!", e1);
|
||||||
}
|
}
|
||||||
serverOperation caselog = new serverOperation();
|
serverOperation caselog = new serverOperation();
|
||||||
// 删除旧的日志
|
// 删除旧的日志
|
||||||
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(caseId);
|
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(caseId);
|
||||||
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
||||||
List<ProjectCaseParams> pcplist = GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
|
List<ProjectCaseParams> pcplist = GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
|
||||||
LogUtil.APP.info("开始执行用例:【{}】......",testcase.getCaseSign());
|
LogUtil.APP.info("开始执行用例:【{}】......",testcase.getCaseSign());
|
||||||
try {
|
try {
|
||||||
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
||||||
AndroidCaseExecution.caseExcution(testcase, steps, taskid, ad, caselog, pcplist);
|
AndroidCaseExecution.caseExcution(testcase, steps, taskid, ad, caselog, pcplist);
|
||||||
LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
|
LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
|
||||||
} catch (InterruptedException e) {
|
} catch (Exception e) {
|
||||||
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
||||||
}
|
}
|
||||||
serverOperation.updateTaskExecuteData(taskid, 0,2);
|
serverOperation.updateTaskExecuteData(taskid, 0,2);
|
||||||
ad.closeApp();
|
assert ad != null;
|
||||||
//关闭Appium服务的线程
|
ad.closeApp();
|
||||||
if(as!=null){
|
//关闭Appium服务的线程
|
||||||
as.interrupt();
|
if(as!=null){
|
||||||
}
|
as.interrupt();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,216 +1,220 @@
|
||||||
package luckyclient.execution.appium.iosex;
|
package luckyclient.execution.appium.iosex;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.openqa.selenium.JavascriptExecutor;
|
import org.openqa.selenium.JavascriptExecutor;
|
||||||
import org.openqa.selenium.OutputType;
|
import org.openqa.selenium.OutputType;
|
||||||
import org.openqa.selenium.TakesScreenshot;
|
import org.openqa.selenium.TakesScreenshot;
|
||||||
import org.openqa.selenium.remote.Augmenter;
|
import org.openqa.selenium.remote.Augmenter;
|
||||||
|
|
||||||
import io.appium.java_client.ios.IOSDriver;
|
import io.appium.java_client.ios.IOSDriver;
|
||||||
import io.appium.java_client.ios.IOSElement;
|
import io.appium.java_client.ios.IOSElement;
|
||||||
import io.appium.java_client.ios.IOSTouchAction;
|
import io.appium.java_client.ios.IOSTouchAction;
|
||||||
import io.appium.java_client.touch.WaitOptions;
|
import io.appium.java_client.touch.WaitOptions;
|
||||||
import io.appium.java_client.touch.offset.PointOption;
|
import io.appium.java_client.touch.offset.PointOption;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
* @date 2018年2月2日
|
* @date 2018年2月2日
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class IosBaseAppium {
|
public class IosBaseAppium {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param args
|
* IOS手机报错截图
|
||||||
* @throws IOException
|
* @param appium appium对象
|
||||||
* IOS手机报错截图
|
* @param imagname 截图名称
|
||||||
*/
|
*/
|
||||||
public static void screenShot(IOSDriver<IOSElement> appium, String imagname){
|
public static void screenShot(IOSDriver<IOSElement> appium, String imagname){
|
||||||
imagname = imagname + ".png";
|
imagname = imagname + ".png";
|
||||||
String relativelyPath = System.getProperty("user.dir");
|
String relativelyPath = System.getProperty("user.dir");
|
||||||
String pngpath=relativelyPath +File.separator+ "log"+File.separator+"ScreenShot" +File.separator+ imagname;
|
String pngpath=relativelyPath +File.separator+ "log"+File.separator+"ScreenShot" +File.separator+ imagname;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(3000);
|
Thread.sleep(3000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
LogUtil.APP.error("IOS手机报错截图休眠出现异常", e);
|
LogUtil.APP.error("IOS手机报错截图休眠出现异常", e);
|
||||||
}
|
}
|
||||||
File imageFile = ((TakesScreenshot) (new Augmenter().augment(appium))).getScreenshotAs(OutputType.FILE);
|
File imageFile = ((TakesScreenshot) (new Augmenter().augment(appium))).getScreenshotAs(OutputType.FILE);
|
||||||
File screenFile = new File(pngpath);
|
File screenFile = new File(pngpath);
|
||||||
FileUtils.copyFile(imageFile, screenFile);
|
FileUtils.copyFile(imageFile, screenFile);
|
||||||
imageFile.deleteOnExit();
|
imageFile.deleteOnExit();
|
||||||
LogUtil.APP
|
LogUtil.APP
|
||||||
.info("已对当前界面进行截图操作,可通过用例执行界面的日志明细查看,也可以前往客户端上查看...【{}】",pngpath);
|
.info("已对当前界面进行截图操作,可通过用例执行界面的日志明细查看,也可以前往客户端上查看...【{}】",pngpath);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogUtil.APP.error("IOS手机报错截图出现异常", e);
|
LogUtil.APP.error("IOS手机报错截图出现异常", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param args
|
* appium不支持中文输入 参考了robotium的以js方式为元素直接设置value的做法
|
||||||
* @throws IOException
|
* 利用Selenium中Webdriver执行js方法实现中文输入
|
||||||
* appium不支持中文输入 参考了robotium的以js方式为元素直接设置value的做法
|
* @param appium appium对象
|
||||||
* 利用Selenium中Webdriver执行js方法实现中文输入
|
* @param preferences 操作对象名称
|
||||||
*/
|
* @param value 操作值
|
||||||
public static void sendChinese(IOSDriver<IOSElement> appium, String preferences, String value) {
|
*/
|
||||||
org.openqa.selenium.JavascriptExecutor jse = (org.openqa.selenium.JavascriptExecutor) appium;
|
public static void sendChinese(IOSDriver<IOSElement> appium, String preferences, String value) {
|
||||||
jse.executeScript("document.getElementByName('" + preferences + "').value='" + value + "'");
|
((JavascriptExecutor) appium).executeScript("document.getElementByName('" + preferences + "').value='" + value + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param args
|
* js webview 支持4.1~4.4 页面滑动
|
||||||
* js webview 支持4.1~4.4
|
* @param appium appium初始化对象
|
||||||
*/
|
* @param sX 开始X坐标
|
||||||
public static void webViewSwipe(IOSDriver<IOSElement> appium, Double sX, Double sY, Double eX, Double eY, Double duration)
|
* @param sY 开始Y坐标
|
||||||
throws Exception {
|
* @param eX 结束X坐标
|
||||||
JavascriptExecutor js;
|
* @param eY 结束Y坐标
|
||||||
HashMap<String, Double> swipeObject;
|
* @param duration 持续时间
|
||||||
try {
|
*/
|
||||||
// 滑动
|
public static void webViewSwipe(IOSDriver<IOSElement> appium, Double sX, Double sY, Double eX, Double eY, Double duration) {
|
||||||
js = (JavascriptExecutor) appium;
|
JavascriptExecutor js;
|
||||||
swipeObject = new HashMap<String, Double>(5);
|
HashMap<String, Double> swipeObject;
|
||||||
swipeObject.put("startX", sX);
|
try {
|
||||||
swipeObject.put("startY", sY);
|
// 滑动
|
||||||
swipeObject.put("endX", eX);
|
js = appium;
|
||||||
swipeObject.put("endY", eY);
|
swipeObject = new HashMap<>(5);
|
||||||
swipeObject.put("duration", duration);
|
swipeObject.put("startX", sX);
|
||||||
js.executeScript("mobile: swipe", swipeObject);
|
swipeObject.put("startY", sY);
|
||||||
} catch (Exception e) {
|
swipeObject.put("endX", eX);
|
||||||
// TODO Auto-generated catch block
|
swipeObject.put("endY", eY);
|
||||||
LogUtil.APP.error("IOS手机滑动出现异常", e);
|
swipeObject.put("duration", duration);
|
||||||
} finally {
|
js.executeScript("mobile: swipe", swipeObject);
|
||||||
// 释放变量
|
} catch (Exception e) {
|
||||||
}
|
// TODO Auto-generated catch block
|
||||||
|
LogUtil.APP.error("IOS手机滑动出现异常", e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
* @param args
|
/**
|
||||||
* 调用 ADB直接滑动 支持4.1~4.4
|
* 调用 ADB直接滑动 支持4.1~4.4
|
||||||
*/
|
* @param appium appium初始化对象
|
||||||
public static void adbSwipe(IOSDriver<IOSElement> appium, Double sX, Double sY, Double eX, Double eY) throws Exception {
|
* @param sX 开始X坐标
|
||||||
int xLine;
|
* @param sY 开始Y坐标
|
||||||
int yLine;
|
* @param eX 结束X坐标
|
||||||
int sX2;
|
* @param eY 结束Y坐标
|
||||||
int sY2;
|
*/
|
||||||
int eX2;
|
public static void adbSwipe(IOSDriver<IOSElement> appium, Double sX, Double sY, Double eX, Double eY) {
|
||||||
int eY2;
|
int xLine;
|
||||||
try {
|
int yLine;
|
||||||
// 滑动
|
int sX2;
|
||||||
xLine = appium.manage().window().getSize().getWidth();
|
int sY2;
|
||||||
yLine = appium.manage().window().getSize().getHeight();
|
int eX2;
|
||||||
|
int eY2;
|
||||||
sX2 = (int) (xLine * sX);
|
try {
|
||||||
sY2 = (int) (yLine * sY);
|
// 滑动
|
||||||
eX2 = (int) (xLine * eX);
|
xLine = appium.manage().window().getSize().getWidth();
|
||||||
eY2 = (int) (yLine * eY);
|
yLine = appium.manage().window().getSize().getHeight();
|
||||||
// logger.info("滑动11111111");
|
|
||||||
Runtime.getRuntime()
|
sX2 = (int) (xLine * sX);
|
||||||
.exec("adb -s " + "IOS" + " shell input swipe " + sX2 + " " + sY2 + " " + eX2 + " " + eY2);
|
sY2 = (int) (yLine * sY);
|
||||||
} catch (Exception e) {
|
eX2 = (int) (xLine * eX);
|
||||||
// TODO Auto-generated catch block
|
eY2 = (int) (yLine * eY);
|
||||||
LogUtil.APP.error("IOS手机调用 ADB直接滑动出现异常", e);
|
// logger.info("滑动11111111");
|
||||||
} finally {
|
Runtime.getRuntime()
|
||||||
// 释放变量
|
.exec("adb -s " + "IOS" + " shell input swipe " + sX2 + " " + sY2 + " " + eX2 + " " + eY2);
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
}
|
LogUtil.APP.error("IOS手机调用 ADB直接滑动出现异常", e);
|
||||||
|
}
|
||||||
/**
|
}
|
||||||
* @param args
|
|
||||||
* 屏幕点击事件
|
/**
|
||||||
*/
|
* 屏幕点击事件
|
||||||
public static void clickScreenForJs(IOSDriver<IOSElement> drivers, int x, int y, int duration) {
|
* @param drivers appium初始化对象
|
||||||
JavascriptExecutor js = (JavascriptExecutor) drivers;
|
* @param x 点击X坐标
|
||||||
HashMap<String, Integer> tapObject = new HashMap<String, Integer>(3);
|
* @param y 点击Y坐标
|
||||||
tapObject.put("x", x);
|
* @param duration 持续时间
|
||||||
tapObject.put("y", y);
|
*/
|
||||||
tapObject.put("duration", duration);
|
public static void clickScreenForJs(IOSDriver<IOSElement> drivers, int x, int y, int duration) {
|
||||||
js.executeScript("mobile: tap", tapObject);
|
HashMap<String, Integer> tapObject = new HashMap<>(3);
|
||||||
}
|
tapObject.put("x", x);
|
||||||
|
tapObject.put("y", y);
|
||||||
/**
|
tapObject.put("duration", duration);
|
||||||
* 拖住页面按屏幕比例向上滑动(手指向下,页面向上)
|
((JavascriptExecutor) drivers).executeScript("mobile: tap", tapObject);
|
||||||
* @param driver
|
}
|
||||||
* @param second 持续时间
|
|
||||||
* @param num 滚动次数
|
/**
|
||||||
*/
|
* 拖住页面按屏幕比例向上滑动(手指向下,页面向上)
|
||||||
public static void swipePageUp(IOSDriver<IOSElement> driver, Double second, int num) {
|
* @param driver appium初始化对象
|
||||||
int nanos = (int) (second * 1000);
|
* @param second 持续时间
|
||||||
Duration duration = Duration.ofNanos(nanos);
|
* @param num 滚动次数
|
||||||
int width = driver.manage().window().getSize().width;
|
*/
|
||||||
int height = driver.manage().window().getSize().height;
|
public static void swipePageUp(IOSDriver<IOSElement> driver, Double second, int num) {
|
||||||
IOSTouchAction action = new IOSTouchAction(driver);
|
int nanos = (int) (second * 1000);
|
||||||
|
Duration duration = Duration.ofNanos(nanos);
|
||||||
for (int i = 0; i <= num; i++) {
|
int width = driver.manage().window().getSize().width;
|
||||||
action.press(PointOption.point(width / 2, 20)).waitAction(WaitOptions.waitOptions(duration))
|
int height = driver.manage().window().getSize().height;
|
||||||
.moveTo(PointOption.point(width / 2, height-20)).release().perform();
|
IOSTouchAction action = new IOSTouchAction(driver);
|
||||||
}
|
|
||||||
}
|
for (int i = 0; i <= num; i++) {
|
||||||
|
action.press(PointOption.point(width / 2, 20)).waitAction(WaitOptions.waitOptions(duration))
|
||||||
/**
|
.moveTo(PointOption.point(width / 2, height-20)).release().perform();
|
||||||
* 拖住页面按屏幕比例向下滑动(手指向上,页面向下)
|
}
|
||||||
* @param driver
|
}
|
||||||
* @param second
|
|
||||||
* @param num
|
/**
|
||||||
*/
|
* 拖住页面按屏幕比例向下滑动(手指向上,页面向下)
|
||||||
public static void swipePageDown(IOSDriver<IOSElement> driver,Double second,int num){
|
* @param driver appium初始化对象
|
||||||
int nanos = (int) (second * 1000);
|
* @param second 持续时间
|
||||||
Duration duration = Duration.ofNanos(nanos);
|
* @param num 滑动次数
|
||||||
int width = driver.manage().window().getSize().width;
|
*/
|
||||||
int height = driver.manage().window().getSize().height;
|
public static void swipePageDown(IOSDriver<IOSElement> driver,Double second,int num){
|
||||||
IOSTouchAction action = new IOSTouchAction(driver);
|
int nanos = (int) (second * 1000);
|
||||||
for (int i = 0; i <= num; i++) {
|
Duration duration = Duration.ofNanos(nanos);
|
||||||
action.press(PointOption.point(width / 2, height-20)).waitAction(WaitOptions.waitOptions(duration))
|
int width = driver.manage().window().getSize().width;
|
||||||
.moveTo(PointOption.point(width / 2, 20)).release().perform();
|
int height = driver.manage().window().getSize().height;
|
||||||
}
|
IOSTouchAction action = new IOSTouchAction(driver);
|
||||||
}
|
for (int i = 0; i <= num; i++) {
|
||||||
|
action.press(PointOption.point(width / 2, height-20)).waitAction(WaitOptions.waitOptions(duration))
|
||||||
/**
|
.moveTo(PointOption.point(width / 2, 20)).release().perform();
|
||||||
* 拖住页面按屏幕比例向左滑动(手指向左,页面向左滚动)
|
}
|
||||||
* @param driver
|
}
|
||||||
* @param second
|
|
||||||
* @param num
|
/**
|
||||||
*/
|
* 拖住页面按屏幕比例向左滑动(手指向左,页面向左滚动)
|
||||||
public static void swipePageLeft(IOSDriver<IOSElement> driver, Double second, int num) {
|
* @param driver appium初始化对象
|
||||||
int nanos = (int) (second * 1000);
|
* @param second 持续时间
|
||||||
Duration duration = Duration.ofNanos(nanos);
|
* @param num 滑动次数
|
||||||
int width = driver.manage().window().getSize().width;
|
*/
|
||||||
int height = driver.manage().window().getSize().height;
|
public static void swipePageLeft(IOSDriver<IOSElement> driver, Double second, int num) {
|
||||||
IOSTouchAction action = new IOSTouchAction(driver);
|
int nanos = (int) (second * 1000);
|
||||||
for (int i = 0; i <= num; i++) {
|
Duration duration = Duration.ofNanos(nanos);
|
||||||
action.press(PointOption.point(width - 10, height / 2)).waitAction(WaitOptions.waitOptions(duration))
|
int width = driver.manage().window().getSize().width;
|
||||||
.moveTo(PointOption.point(10, height / 2)).release().perform();
|
int height = driver.manage().window().getSize().height;
|
||||||
}
|
IOSTouchAction action = new IOSTouchAction(driver);
|
||||||
}
|
for (int i = 0; i <= num; i++) {
|
||||||
|
action.press(PointOption.point(width - 10, height / 2)).waitAction(WaitOptions.waitOptions(duration))
|
||||||
/**
|
.moveTo(PointOption.point(10, height / 2)).release().perform();
|
||||||
* 拖住页面按屏幕比例向右滑动(手指向右,页面向右)
|
}
|
||||||
* @param driver
|
}
|
||||||
* @param second
|
|
||||||
* @param num
|
/**
|
||||||
*/
|
* 拖住页面按屏幕比例向右滑动(手指向右,页面向右)
|
||||||
public static void swipePageRight(IOSDriver<IOSElement> driver, Double second, int num) {
|
* @param driver appium初始化对象
|
||||||
int nanos = (int) (second * 1000);
|
* @param second 持续时间
|
||||||
Duration duration = Duration.ofNanos(nanos);
|
* @param num 滑动次数
|
||||||
int width = driver.manage().window().getSize().width;
|
*/
|
||||||
int height = driver.manage().window().getSize().height;
|
public static void swipePageRight(IOSDriver<IOSElement> driver, Double second, int num) {
|
||||||
IOSTouchAction action = new IOSTouchAction(driver);
|
int nanos = (int) (second * 1000);
|
||||||
for (int i = 0; i <= num; i++) {
|
Duration duration = Duration.ofNanos(nanos);
|
||||||
action.press(PointOption.point(10, height / 2)).waitAction(WaitOptions.waitOptions(duration))
|
int width = driver.manage().window().getSize().width;
|
||||||
.moveTo(PointOption.point(width - 10, height / 2)).release().perform();
|
int height = driver.manage().window().getSize().height;
|
||||||
}
|
IOSTouchAction action = new IOSTouchAction(driver);
|
||||||
}
|
for (int i = 0; i <= num; i++) {
|
||||||
|
action.press(PointOption.point(10, height / 2)).waitAction(WaitOptions.waitOptions(duration))
|
||||||
}
|
.moveTo(PointOption.point(width - 10, height / 2)).release().perform();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,95 +1,95 @@
|
||||||
package luckyclient.execution.appium.iosex;
|
package luckyclient.execution.appium.iosex;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import io.appium.java_client.ios.IOSDriver;
|
import io.appium.java_client.ios.IOSDriver;
|
||||||
import io.appium.java_client.ios.IOSElement;
|
import io.appium.java_client.ios.IOSElement;
|
||||||
import luckyclient.execution.appium.AppiumInitialization;
|
import luckyclient.execution.appium.AppiumInitialization;
|
||||||
import luckyclient.execution.appium.AppiumService;
|
import luckyclient.execution.appium.AppiumService;
|
||||||
import luckyclient.execution.httpinterface.TestControl;
|
import luckyclient.execution.httpinterface.TestControl;
|
||||||
import luckyclient.remote.api.GetServerApi;
|
import luckyclient.remote.api.GetServerApi;
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.ProjectCase;
|
||||||
import luckyclient.remote.entity.ProjectCaseParams;
|
import luckyclient.remote.entity.ProjectCaseParams;
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
import luckyclient.remote.entity.ProjectCaseSteps;
|
||||||
import luckyclient.remote.entity.TaskExecute;
|
import luckyclient.remote.entity.TaskExecute;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
import luckyclient.utils.config.AppiumConfig;
|
import luckyclient.utils.config.AppiumConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
* @date 2018年2月2日
|
* @date 2018年2月2日
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class IosBatchExecute {
|
public class IosBatchExecute {
|
||||||
|
|
||||||
public static void batchCaseExecuteForTast(String projectname, String taskid, String batchcase) throws IOException, InterruptedException {
|
public static void batchCaseExecuteForTast(String taskid, String batchcase) throws IOException, InterruptedException {
|
||||||
// 记录日志到数据库
|
// 记录日志到数据库
|
||||||
serverOperation.exetype = 0;
|
serverOperation.exetype = 0;
|
||||||
TestControl.TASKID = taskid;
|
TestControl.TASKID = taskid;
|
||||||
IOSDriver<IOSElement> iosd = null;
|
IOSDriver<IOSElement> iosd = null;
|
||||||
AppiumService as=null;
|
AppiumService as=null;
|
||||||
try {
|
try {
|
||||||
Properties properties = AppiumConfig.getConfiguration();
|
Properties properties = AppiumConfig.getConfiguration();
|
||||||
//根据配置自动启动Appiume服务
|
//根据配置自动启动Appiume服务
|
||||||
if(Boolean.valueOf(properties.getProperty("autoRunAppiumService"))){
|
if(Boolean.parseBoolean(properties.getProperty("autoRunAppiumService"))){
|
||||||
as =new AppiumService();
|
as =new AppiumService();
|
||||||
as.start();
|
as.start();
|
||||||
Thread.sleep(10000);
|
Thread.sleep(10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
iosd = AppiumInitialization.setIosAppium(properties);
|
iosd = AppiumInitialization.setIosAppium(properties);
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
LogUtil.APP.error("根据配置自动启动Appiume服务中抛出异常!", e);
|
LogUtil.APP.error("根据配置自动启动Appiume服务中抛出异常!", e);
|
||||||
}
|
}
|
||||||
serverOperation caselog = new serverOperation();
|
serverOperation caselog = new serverOperation();
|
||||||
TaskExecute task = GetServerApi.cgetTaskbyid(Integer.valueOf(taskid));
|
TaskExecute task = GetServerApi.cgetTaskbyid(Integer.parseInt(taskid));
|
||||||
List<ProjectCaseParams> pcplist = GetServerApi
|
List<ProjectCaseParams> pcplist = GetServerApi
|
||||||
.cgetParamsByProjectid(task.getProjectId().toString());
|
.cgetParamsByProjectid(task.getProjectId().toString());
|
||||||
// 执行全部非成功状态用例
|
// 执行全部非成功状态用例
|
||||||
if (batchcase.indexOf("ALLFAIL") > -1) {
|
if (batchcase.contains("ALLFAIL")) {
|
||||||
List<Integer> caseIdList = caselog.getCaseListForUnSucByTaskId(taskid);
|
List<Integer> caseIdList = caselog.getCaseListForUnSucByTaskId(taskid);
|
||||||
for (int i = 0; i < caseIdList.size(); i++) {
|
for (Integer integer : caseIdList) {
|
||||||
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(caseIdList.get(i));
|
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(integer);
|
||||||
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
||||||
// 删除旧的日志
|
// 删除旧的日志
|
||||||
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
||||||
try {
|
try {
|
||||||
IosCaseExecution.caseExcution(testcase, steps, taskid, iosd, caselog, pcplist);
|
IosCaseExecution.caseExcution(testcase, steps, taskid, iosd, caselog, pcplist);
|
||||||
} catch (InterruptedException e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
||||||
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
}
|
||||||
}
|
}
|
||||||
}
|
} else { // 批量执行用例
|
||||||
} else { // 批量执行用例
|
String[] temp = batchcase.split("#");
|
||||||
String[] temp = batchcase.split("\\#");
|
for (String s : temp) {
|
||||||
for (int i = 0; i < temp.length; i++) {
|
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(Integer.valueOf(s));
|
||||||
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(Integer.valueOf(temp[i]));
|
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
||||||
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
// 删除旧的日志
|
||||||
// 删除旧的日志
|
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
||||||
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
try {
|
||||||
try {
|
IosCaseExecution.caseExcution(testcase, steps, taskid, iosd, caselog, pcplist);
|
||||||
IosCaseExecution.caseExcution(testcase, steps, taskid, iosd, caselog, pcplist);
|
} catch (Exception e) {
|
||||||
} catch (InterruptedException e) {
|
// TODO Auto-generated catch block
|
||||||
// TODO Auto-generated catch block
|
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
||||||
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
serverOperation.updateTaskExecuteData(taskid, 0,2);
|
||||||
serverOperation.updateTaskExecuteData(taskid, 0,2);
|
assert iosd != null;
|
||||||
iosd.closeApp();
|
iosd.closeApp();
|
||||||
//关闭Appium服务的线程
|
//关闭Appium服务的线程
|
||||||
if(as!=null){
|
if(as!=null){
|
||||||
as.interrupt();
|
as.interrupt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,334 +1,332 @@
|
||||||
package luckyclient.execution.appium.iosex;
|
package luckyclient.execution.appium.iosex;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.util.Date;
|
||||||
import java.util.Date;
|
import java.util.HashMap;
|
||||||
import java.util.HashMap;
|
import java.util.List;
|
||||||
import java.util.List;
|
import java.util.Map;
|
||||||
import java.util.Map;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Pattern;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
import io.appium.java_client.ios.IOSDriver;
|
||||||
import io.appium.java_client.ios.IOSDriver;
|
import io.appium.java_client.ios.IOSElement;
|
||||||
import io.appium.java_client.ios.IOSElement;
|
import luckyclient.execution.appium.AppDriverAnalyticCase;
|
||||||
import luckyclient.execution.appium.AppDriverAnalyticCase;
|
import luckyclient.execution.dispose.ActionManageForSteps;
|
||||||
import luckyclient.execution.dispose.ActionManageForSteps;
|
import luckyclient.execution.dispose.ChangString;
|
||||||
import luckyclient.execution.dispose.ChangString;
|
import luckyclient.execution.dispose.ParamsManageForSteps;
|
||||||
import luckyclient.execution.dispose.ParamsManageForSteps;
|
import luckyclient.execution.httpinterface.TestCaseExecution;
|
||||||
import luckyclient.execution.httpinterface.TestCaseExecution;
|
import luckyclient.execution.httpinterface.analyticsteps.InterfaceAnalyticCase;
|
||||||
import luckyclient.execution.httpinterface.analyticsteps.InterfaceAnalyticCase;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.entity.ProjectCase;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.ProjectCaseParams;
|
||||||
import luckyclient.remote.entity.ProjectCaseParams;
|
import luckyclient.remote.entity.ProjectCaseSteps;
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
import luckyclient.utils.Constants;
|
||||||
import luckyclient.utils.Constants;
|
import luckyclient.utils.LogUtil;
|
||||||
import luckyclient.utils.LogUtil;
|
|
||||||
|
/**
|
||||||
/**
|
* =================================================================
|
||||||
* =================================================================
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* =================================================================
|
||||||
* =================================================================
|
*
|
||||||
*
|
* @author seagull
|
||||||
* @author seagull
|
* @date 2018年1月21日 上午15:12:48
|
||||||
* @date 2018年1月21日 上午15:12:48
|
*/
|
||||||
*/
|
public class IosCaseExecution{
|
||||||
public class IosCaseExecution{
|
static Map<String, String> variable = new HashMap<>();
|
||||||
static Map<String, String> variable = new HashMap<String, String>();
|
private static String casenote = "备注初始化";
|
||||||
private static String casenote = "备注初始化";
|
|
||||||
private static String imagname = "";
|
public static void caseExcution(ProjectCase testcase, List<ProjectCaseSteps> steps,String taskid, IOSDriver<IOSElement> appium,serverOperation caselog,List<ProjectCaseParams> pcplist) {
|
||||||
|
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), 3);
|
||||||
public static void caseExcution(ProjectCase testcase, List<ProjectCaseSteps> steps,String taskid, IOSDriver<IOSElement> appium,serverOperation caselog,List<ProjectCaseParams> pcplist)
|
// 把公共参数加入到MAP中
|
||||||
throws InterruptedException, IOException {
|
for (ProjectCaseParams pcp : pcplist) {
|
||||||
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), 3);
|
variable.put(pcp.getParamsName(), pcp.getParamsValue());
|
||||||
// 把公共参数加入到MAP中
|
}
|
||||||
for (ProjectCaseParams pcp : pcplist) {
|
// 加入全局变量
|
||||||
variable.put(pcp.getParamsName(), pcp.getParamsValue());
|
variable.putAll(ParamsManageForSteps.GLOBAL_VARIABLE);
|
||||||
}
|
|
||||||
// 加入全局变量
|
// 0:成功 1:失败 2:锁定 其他:锁定
|
||||||
variable.putAll(ParamsManageForSteps.GLOBAL_VARIABLE);
|
int setcaseresult = 0;
|
||||||
|
for (ProjectCaseSteps step : steps) {
|
||||||
// 0:成功 1:失败 2:锁定 其他:锁定
|
Map<String, String> params;
|
||||||
int setcaseresult = 0;
|
String result;
|
||||||
for (ProjectCaseSteps step : steps) {
|
|
||||||
Map<String, String> params;
|
// 根据步骤类型来分析步骤参数
|
||||||
String result;
|
if (3 == step.getStepType()){
|
||||||
|
params = AppDriverAnalyticCase.analyticCaseStep(testcase, step, taskid,caselog,variable);
|
||||||
// 根据步骤类型来分析步骤参数
|
}else{
|
||||||
if (3 == step.getStepType()){
|
params = InterfaceAnalyticCase.analyticCaseStep(testcase, step, taskid, caselog,variable);
|
||||||
params = AppDriverAnalyticCase.analyticCaseStep(testcase, step, taskid,caselog,variable);
|
}
|
||||||
}else{
|
|
||||||
params = InterfaceAnalyticCase.analyticCaseStep(testcase, step, taskid, caselog,variable);
|
if(null != params.get("exception") && params.get("exception").contains("解析异常")){
|
||||||
}
|
setcaseresult = 2;
|
||||||
|
break;
|
||||||
if(null != params.get("exception") && params.get("exception").contains("解析异常")){
|
}
|
||||||
setcaseresult = 2;
|
|
||||||
break;
|
// 根据步骤类型来执行步骤
|
||||||
}
|
if (3 == step.getStepType()){
|
||||||
|
result = iosRunStep(params, variable, appium, taskid, testcase.getCaseId(), step.getStepSerialNumber(), caselog);
|
||||||
// 根据步骤类型来执行步骤
|
}else{
|
||||||
if (3 == step.getStepType()){
|
TestCaseExecution testCaseExecution=new TestCaseExecution();
|
||||||
result = iosRunStep(params, variable, appium, taskid, testcase.getCaseId(), step.getStepSerialNumber(), caselog);
|
result = testCaseExecution.runStep(params, taskid, testcase.getCaseSign(), step, caselog);
|
||||||
}else{
|
}
|
||||||
TestCaseExecution testCaseExecution=new TestCaseExecution();
|
|
||||||
result = testCaseExecution.runStep(params, taskid, testcase.getCaseSign(), step, caselog);
|
String expectedResults = params.get("ExpectedResults");
|
||||||
}
|
expectedResults=ChangString.changparams(expectedResults, variable,"预期结果");
|
||||||
|
|
||||||
String expectedResults = params.get("ExpectedResults").toString();
|
// 判断结果
|
||||||
expectedResults=ChangString.changparams(expectedResults, variable,"预期结果");
|
int stepresult = judgeResult(testcase, step, params, appium, taskid, expectedResults, result, caselog);
|
||||||
|
// 失败,并且不在继续,直接终止
|
||||||
// 判断结果
|
if (0 != stepresult) {
|
||||||
int stepresult = judgeResult(testcase, step, params, appium, taskid, expectedResults, result, caselog);
|
setcaseresult = stepresult;
|
||||||
// 失败,并且不在继续,直接终止
|
if (testcase.getFailcontinue() == 0) {
|
||||||
if (0 != stepresult) {
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),step.getStepSerialNumber());
|
||||||
setcaseresult = stepresult;
|
break;
|
||||||
if (testcase.getFailcontinue() == 0) {
|
} else {
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),step.getStepSerialNumber());
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),step.getStepSerialNumber());
|
||||||
break;
|
}
|
||||||
} else {
|
}
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),step.getStepSerialNumber());
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
variable.clear();
|
||||||
}
|
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), setcaseresult);
|
||||||
|
if(setcaseresult==0){
|
||||||
variable.clear();
|
LogUtil.APP.info("用例【{}】全部步骤执行结果成功...",testcase.getCaseSign());
|
||||||
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), setcaseresult);
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例全部步骤执行结果成功","info", "ending","");
|
||||||
if(setcaseresult==0){
|
}else{
|
||||||
LogUtil.APP.info("用例【{}】全部步骤执行结果成功...",testcase.getCaseSign());
|
LogUtil.APP.warn("用例【{}】步骤执行过程中失败或是锁定...请查看具体原因!{}",testcase.getCaseSign(),casenote);
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例全部步骤执行结果成功","info", "ending","");
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例执行过程中失败或是锁定"+casenote,"error", "ending","");
|
||||||
}else{
|
}
|
||||||
LogUtil.APP.warn("用例【{}】步骤执行过程中失败或是锁定...请查看具体原因!{}",testcase.getCaseSign(),casenote);
|
//LogOperation.UpdateTastdetail(taskid, 0);
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例执行过程中失败或是锁定"+casenote,"error", "ending","");
|
}
|
||||||
}
|
|
||||||
//LogOperation.UpdateTastdetail(taskid, 0);
|
public static String iosRunStep(Map<String, String> params, Map<String, String> variable, IOSDriver<IOSElement> appium,String taskid,Integer caseId,int stepno,serverOperation caselog) {
|
||||||
}
|
String result;
|
||||||
|
String property;
|
||||||
public static String iosRunStep(Map<String, String> params, Map<String, String> variable, IOSDriver<IOSElement> appium,String taskid,Integer caseId,int stepno,serverOperation caselog) {
|
String propertyValue;
|
||||||
String result = "";
|
String operation;
|
||||||
String property;
|
String operationValue;
|
||||||
String propertyValue;
|
|
||||||
String operation;
|
try {
|
||||||
String operationValue;
|
property = params.get("property");
|
||||||
|
propertyValue = params.get("property_value");
|
||||||
try {
|
operation = params.get("operation");
|
||||||
property = params.get("property");
|
operationValue = params.get("operation_value");
|
||||||
propertyValue = params.get("property_value");
|
|
||||||
operation = params.get("operation");
|
// 处理值传递
|
||||||
operationValue = params.get("operation_value");
|
property = ChangString.changparams(property, variable,"定位方式");
|
||||||
|
propertyValue=ChangString.changparams(propertyValue, variable,"定位路径");
|
||||||
// 处理值传递
|
operation=ChangString.changparams(operation, variable,"操作");
|
||||||
property = ChangString.changparams(property, variable,"定位方式");
|
operationValue=ChangString.changparams(operationValue, variable,"操作参数");
|
||||||
propertyValue=ChangString.changparams(propertyValue, variable,"定位路径");
|
|
||||||
operation=ChangString.changparams(operation, variable,"操作");
|
LogUtil.APP.info("二次解析用例过程完成,等待进行对象操作......");
|
||||||
operationValue=ChangString.changparams(operationValue, variable,"操作参数");
|
caselog.insertTaskCaseLog(taskid, caseId, "对象操作:"+operation+"; 操作值:"+operationValue,"info", String.valueOf(stepno),"");
|
||||||
|
} catch (Exception e) {
|
||||||
LogUtil.APP.info("二次解析用例过程完成,等待进行对象操作......");
|
LogUtil.APP.error("二次解析用例过程抛出异常!",e);
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "对象操作:"+operation+"; 操作值:"+operationValue,"info", String.valueOf(stepno),"");
|
return "步骤执行失败:解析用例失败!";
|
||||||
} catch (Exception e) {
|
}
|
||||||
LogUtil.APP.error("二次解析用例过程抛出异常!",e);
|
|
||||||
return "步骤执行失败:解析用例失败!";
|
try {
|
||||||
}
|
//调用接口用例
|
||||||
|
if(null != operationValue && "runcase".equals(operation)){
|
||||||
try {
|
String[] temp=operationValue.split(",",-1);
|
||||||
//调用接口用例
|
TestCaseExecution testCaseExecution=new TestCaseExecution();
|
||||||
if(null != operation&&null != operationValue&&"runcase".equals(operation)){
|
String ex = testCaseExecution.oneCaseExecuteForUICase(temp[0], taskid, caselog, appium);
|
||||||
String[] temp=operationValue.split(",",-1);
|
if(!ex.contains("CallCase调用出错!") && !ex.contains("解析出错啦!") && !ex.contains("匹配失败")){
|
||||||
TestCaseExecution testCaseExecution=new TestCaseExecution();
|
return ex;
|
||||||
String ex = testCaseExecution.oneCaseExecuteForUICase(temp[0], taskid, caselog, appium);
|
}else{
|
||||||
if(ex.indexOf("CallCase调用出错!")<=-1&&ex.indexOf("解析出错啦!")<=-1&&ex.indexOf("匹配失败")<=-1){
|
return "步骤执行失败:调用接口用例过程失败";
|
||||||
return ex;
|
}
|
||||||
}else{
|
}
|
||||||
return "步骤执行失败:调用接口用例过程失败";
|
|
||||||
}
|
IOSElement ae;
|
||||||
}
|
// 页面元素层
|
||||||
|
if (null != property && null != propertyValue) {
|
||||||
IOSElement ae = null;
|
ae = isElementExist(appium, property, propertyValue);
|
||||||
// 页面元素层
|
// 判断此元素是否存在
|
||||||
if (null != property && null != propertyValue) {
|
if (null==ae) {
|
||||||
ae = isElementExist(appium, property, propertyValue);
|
LogUtil.APP.warn("定位对象失败,isElementExist为null!");
|
||||||
// 判断此元素是否存在
|
return "步骤执行失败:isElementExist定位元素过程失败!";
|
||||||
if (null==ae) {
|
}
|
||||||
LogUtil.APP.warn("定位对象失败,isElementExist为null!");
|
|
||||||
return "步骤执行失败:isElementExist定位元素过程失败!";
|
assert operation != null;
|
||||||
}
|
if (operation.contains("select")) {
|
||||||
|
result = IosEncapsulateOperation.selectOperation(ae, operation, operationValue);
|
||||||
if (operation.indexOf("select") > -1) {
|
} else if (operation.contains("get")){
|
||||||
result = IosEncapsulateOperation.selectOperation(ae, operation, operationValue);
|
result = IosEncapsulateOperation.getOperation(ae, operation,operationValue);
|
||||||
} else if (operation.indexOf("get") > -1){
|
} else {
|
||||||
result = IosEncapsulateOperation.getOperation(ae, operation,operationValue);
|
result = IosEncapsulateOperation.objectOperation(appium, ae, operation, operationValue, property, propertyValue);
|
||||||
} else {
|
}
|
||||||
result = IosEncapsulateOperation.objectOperation(appium, ae, operation, operationValue, property, propertyValue);
|
// Driver层操作
|
||||||
}
|
} else if (null==property && null != operation) {
|
||||||
// Driver层操作
|
// 处理弹出框事件
|
||||||
} else if (null==property && null != operation) {
|
if (operation.contains("alert")){
|
||||||
// 处理弹出框事件
|
result = IosEncapsulateOperation.alertOperation(appium, operation);
|
||||||
if (operation.indexOf("alert") > -1){
|
}else{
|
||||||
result = IosEncapsulateOperation.alertOperation(appium, operation);
|
result = IosEncapsulateOperation.driverOperation(appium, operation, operationValue);
|
||||||
}else{
|
}
|
||||||
result = IosEncapsulateOperation.driverOperation(appium, operation, operationValue);
|
}else{
|
||||||
}
|
LogUtil.APP.warn("元素操作过程失败!");
|
||||||
}else{
|
result = "步骤执行失败:元素操作过程失败!";
|
||||||
LogUtil.APP.warn("元素操作过程失败!");
|
}
|
||||||
result = "步骤执行失败:元素操作过程失败!";
|
} catch (Exception e) {
|
||||||
}
|
LogUtil.APP.error("元素定位过程或是操作过程失败或异常!",e);
|
||||||
} catch (Exception e) {
|
return "步骤执行失败:元素定位过程或是操作过程失败或异常!" + e.getMessage();
|
||||||
LogUtil.APP.error("元素定位过程或是操作过程失败或异常!",e);
|
}
|
||||||
return "步骤执行失败:元素定位过程或是操作过程失败或异常!" + e.getMessage();
|
caselog.insertTaskCaseLog(taskid, caseId, result,"info", String.valueOf(stepno),"");
|
||||||
}
|
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, result,"info", String.valueOf(stepno),"");
|
if(result.contains("获取到的值是【") && result.contains("】")){
|
||||||
|
result = result.substring(result.indexOf("获取到的值是【")+7, result.length()-1);
|
||||||
if(result.indexOf("获取到的值是【")>-1&&result.indexOf("】")>-1){
|
}
|
||||||
result = result.substring(result.indexOf("获取到的值是【")+7, result.length()-1);
|
return result;
|
||||||
}
|
|
||||||
return result;
|
}
|
||||||
|
|
||||||
}
|
public static IOSElement isElementExist(IOSDriver<IOSElement> appium, String property, String propertyValue) {
|
||||||
|
try {
|
||||||
public static IOSElement isElementExist(IOSDriver<IOSElement> appium, String property, String propertyValue) {
|
IOSElement ae = null;
|
||||||
try {
|
property=property.toLowerCase();
|
||||||
IOSElement ae = null;
|
// 处理WebElement对象定位
|
||||||
property=property.toLowerCase();
|
switch (property) {
|
||||||
// 处理WebElement对象定位
|
case "id":
|
||||||
switch (property) {
|
ae = appium.findElementById(propertyValue);
|
||||||
case "id":
|
break;
|
||||||
ae = appium.findElementById(propertyValue);
|
case "name":
|
||||||
break;
|
ae = appium.findElementByName(propertyValue);
|
||||||
case "name":
|
break;
|
||||||
ae = appium.findElementByName(propertyValue);
|
case "xpath":
|
||||||
break;
|
ae = appium.findElementByXPath(propertyValue);
|
||||||
case "xpath":
|
break;
|
||||||
ae = appium.findElementByXPath(propertyValue);
|
case "linktext":
|
||||||
break;
|
ae = appium.findElementByLinkText(propertyValue);
|
||||||
case "linktext":
|
break;
|
||||||
ae = appium.findElementByLinkText(propertyValue);
|
case "tagname":
|
||||||
break;
|
ae = appium.findElementByTagName(propertyValue);
|
||||||
case "tagname":
|
break;
|
||||||
ae = appium.findElementByTagName(propertyValue);
|
case "cssselector":
|
||||||
break;
|
ae = appium.findElementByCssSelector(propertyValue);
|
||||||
case "cssselector":
|
break;
|
||||||
ae = appium.findElementByCssSelector(propertyValue);
|
case "classname":
|
||||||
break;
|
ae = appium.findElementByClassName(propertyValue);
|
||||||
case "classname":
|
break;
|
||||||
ae = appium.findElementByClassName(propertyValue);
|
case "accessibilityid":
|
||||||
break;
|
ae = appium.findElementByAccessibilityId(propertyValue);
|
||||||
case "accessibilityid":
|
break;
|
||||||
ae = appium.findElementByAccessibilityId(propertyValue);
|
case "iosclasschain":
|
||||||
break;
|
ae = appium.findElementByIosClassChain(propertyValue);
|
||||||
case "iosclasschain":
|
break;
|
||||||
ae = appium.findElementByIosClassChain(propertyValue);
|
case "iosnspredicate":
|
||||||
break;
|
ae = appium.findElementByIosNsPredicate(propertyValue);
|
||||||
case "iosnspredicate":
|
break;
|
||||||
ae = appium.findElementByIosNsPredicate(propertyValue);
|
default:
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
break;
|
|
||||||
}
|
return ae;
|
||||||
|
|
||||||
return ae;
|
} catch (Exception e) {
|
||||||
|
LogUtil.APP.error("当前对象定位失败!",e);
|
||||||
} catch (Exception e) {
|
return null;
|
||||||
LogUtil.APP.error("当前对象定位失败!",e);
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public static int judgeResult(ProjectCase testcase, ProjectCaseSteps step, Map<String, String> params, IOSDriver<IOSElement> appium, String taskid, String expect, String result, serverOperation caselog) {
|
||||||
|
int setresult = 0;
|
||||||
public static int judgeResult(ProjectCase testcase, ProjectCaseSteps step, Map<String, String> params, IOSDriver<IOSElement> appium, String taskid, String expect, String result, serverOperation caselog) throws InterruptedException {
|
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
|
||||||
int setresult = 0;
|
String imagname = timeformat.format(new Date());
|
||||||
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
|
|
||||||
imagname = timeformat.format(new Date());
|
result = ActionManageForSteps.actionManage(step.getAction(), result);
|
||||||
|
if (null != result && !result.contains("步骤执行失败:")) {
|
||||||
result = ActionManageForSteps.actionManage(step.getAction(), result);
|
// 有预期结果
|
||||||
if (null != result && !result.contains("步骤执行失败:")) {
|
if (null != expect && !expect.isEmpty()) {
|
||||||
// 有预期结果
|
LogUtil.APP.info("期望结果为【{}】",expect);
|
||||||
if (null != expect && !expect.isEmpty()) {
|
|
||||||
LogUtil.APP.info("期望结果为【{}】",expect);
|
// 赋值传参模式
|
||||||
|
if (expect.length() > Constants.ASSIGNMENT_SIGN.length() && expect.startsWith(Constants.ASSIGNMENT_SIGN)) {
|
||||||
// 赋值传参模式
|
variable.put(expect.substring(Constants.ASSIGNMENT_SIGN.length()), result);
|
||||||
if (expect.length() > Constants.ASSIGNMENT_SIGN.length() && expect.startsWith(Constants.ASSIGNMENT_SIGN)) {
|
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给变量【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),result,expect.substring(Constants.ASSIGNMENT_SIGN.length()));
|
||||||
variable.put(expect.substring(Constants.ASSIGNMENT_SIGN.length()), result);
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给变量【" + expect.substring(Constants.ASSIGNMENT_SIGN.length()) + "】", "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给变量【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),result,expect.substring(Constants.ASSIGNMENT_SIGN.length()));
|
}
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给变量【" + expect.substring(Constants.ASSIGNMENT_SIGN.length()) + "】", "info", String.valueOf(step.getStepSerialNumber()), "");
|
// 赋值全局变量
|
||||||
}
|
else if (expect.length() > Constants.ASSIGNMENT_GLOBALSIGN.length() && expect.startsWith(Constants.ASSIGNMENT_GLOBALSIGN)) {
|
||||||
// 赋值全局变量
|
variable.put(expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), result);
|
||||||
else if (expect.length() > Constants.ASSIGNMENT_GLOBALSIGN.length() && expect.startsWith(Constants.ASSIGNMENT_GLOBALSIGN)) {
|
ParamsManageForSteps.GLOBAL_VARIABLE.put(expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), result);
|
||||||
variable.put(expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), result);
|
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给全局变量【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),result,expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()));
|
||||||
ParamsManageForSteps.GLOBAL_VARIABLE.put(expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), result);
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给全局变量【" + expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()) + "】", "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给全局变量【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),result,expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()));
|
}
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给全局变量【" + expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()) + "】", "info", String.valueOf(step.getStepSerialNumber()), "");
|
// 移动端 UI检查模式
|
||||||
}
|
else if (3 == step.getStepType() && params.get("checkproperty") != null && params.get("checkproperty_value") != null) {
|
||||||
// 移动端 UI检查模式
|
String checkproperty = params.get("checkproperty");
|
||||||
else if (3 == step.getStepType() && params.get("checkproperty") != null && params.get("checkproperty_value") != null) {
|
String checkPropertyValue = params.get("checkproperty_value");
|
||||||
String checkproperty = params.get("checkproperty");
|
|
||||||
String checkPropertyValue = params.get("checkproperty_value");
|
IOSElement ae = isElementExist(appium, checkproperty, checkPropertyValue);
|
||||||
|
if (null != ae) {
|
||||||
IOSElement ae = isElementExist(appium, checkproperty, checkPropertyValue);
|
LogUtil.APP.info("用例:{} 第{}步,在当前页面中找到预期结果中对象。当前步骤执行成功!",testcase.getCaseSign(),step.getStepSerialNumber());
|
||||||
if (null != ae) {
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中找到预期结果中对象。当前步骤执行成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
LogUtil.APP.info("用例:{} 第{}步,在当前页面中找到预期结果中对象。当前步骤执行成功!",testcase.getCaseSign(),step.getStepSerialNumber());
|
} else {
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中找到预期结果中对象。当前步骤执行成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
|
casenote = "第" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。执行失败!";
|
||||||
} else {
|
setresult = 1;
|
||||||
casenote = "第" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。执行失败!";
|
IosBaseAppium.screenShot(appium, imagname);
|
||||||
setresult = 1;
|
LogUtil.APP.warn("用例:{} 第{}步,没有在当前页面中找到预期结果中对象。当前步骤执行失败!",testcase.getCaseSign(),step.getStepSerialNumber());
|
||||||
IosBaseAppium.screenShot(appium, imagname);
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中没有找到预期结果中对象。当前步骤执行失败!" + "checkproperty【" + checkproperty + "】 checkproperty_value【" + checkPropertyValue + "】", "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,没有在当前页面中找到预期结果中对象。当前步骤执行失败!",testcase.getCaseSign(),step.getStepSerialNumber());
|
}
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中没有找到预期结果中对象。当前步骤执行失败!" + "checkproperty【" + checkproperty + "】 checkproperty_value【" + checkPropertyValue + "】", "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
}
|
||||||
}
|
// 其它匹配模式
|
||||||
}
|
else {
|
||||||
// 其它匹配模式
|
// 模糊匹配预期结果模式
|
||||||
else {
|
if (expect.length() > Constants.FUZZY_MATCHING_SIGN.length() && expect.startsWith(Constants.FUZZY_MATCHING_SIGN)) {
|
||||||
// 模糊匹配预期结果模式
|
if (result.contains(expect.substring(Constants.FUZZY_MATCHING_SIGN.length()))) {
|
||||||
if (expect.length() > Constants.FUZZY_MATCHING_SIGN.length() && expect.startsWith(Constants.FUZZY_MATCHING_SIGN)) {
|
LogUtil.APP.info("用例:{} 第{}步,模糊匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
|
||||||
if (result.contains(expect.substring(Constants.FUZZY_MATCHING_SIGN.length()))) {
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果成功!执行结果:" + result, "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
LogUtil.APP.info("用例:{} 第{}步,模糊匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
|
} else {
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果成功!执行结果:" + result, "info", String.valueOf(step.getStepSerialNumber()), "");
|
casenote = "第" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!";
|
||||||
} else {
|
setresult = 1;
|
||||||
casenote = "第" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!";
|
IosBaseAppium.screenShot(appium, imagname);
|
||||||
setresult = 1;
|
LogUtil.APP.warn("用例:{} 第{}步,模糊匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expect.substring(Constants.FUZZY_MATCHING_SIGN.length()),result);
|
||||||
IosBaseAppium.screenShot(appium, imagname);
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果失败!预期结果:" + expect.substring(Constants.FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,模糊匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expect.substring(Constants.FUZZY_MATCHING_SIGN.length()),result);
|
}
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果失败!预期结果:" + expect.substring(Constants.FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
}
|
||||||
}
|
// 正则匹配预期结果模式
|
||||||
}
|
else if (expect.length() > Constants.REGULAR_MATCHING_SIGN.length() && expect.startsWith(Constants.REGULAR_MATCHING_SIGN)) {
|
||||||
// 正则匹配预期结果模式
|
Pattern pattern = Pattern.compile(expect.substring(Constants.REGULAR_MATCHING_SIGN.length()));
|
||||||
else if (expect.length() > Constants.REGULAR_MATCHING_SIGN.length() && expect.startsWith(Constants.REGULAR_MATCHING_SIGN)) {
|
Matcher matcher = pattern.matcher(result);
|
||||||
Pattern pattern = Pattern.compile(expect.substring(Constants.REGULAR_MATCHING_SIGN.length()));
|
if (matcher.find()) {
|
||||||
Matcher matcher = pattern.matcher(result);
|
LogUtil.APP.info("用例:{} 第{}步,正则匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
|
||||||
if (matcher.find()) {
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
LogUtil.APP.info("用例:{} 第{}步,正则匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
|
} else {
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
|
casenote = "第" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!";
|
||||||
} else {
|
setresult = 1;
|
||||||
casenote = "第" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!";
|
IosBaseAppium.screenShot(appium, imagname);
|
||||||
setresult = 1;
|
LogUtil.APP.warn("用例:{} 第{}步,正则匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expect.substring(Constants.REGULAR_MATCHING_SIGN.length()),result);
|
||||||
IosBaseAppium.screenShot(appium, imagname);
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果失败!预期结果:" + expect.substring(Constants.REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,正则匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expect.substring(Constants.REGULAR_MATCHING_SIGN.length()),result);
|
}
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果失败!预期结果:" + expect.substring(Constants.REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
}
|
||||||
}
|
// 精确匹配预期结果模式
|
||||||
}
|
else {
|
||||||
// 精确匹配预期结果模式
|
if (expect.equals(result)) {
|
||||||
else {
|
LogUtil.APP.info("用例:{} 第{}步,精确匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
|
||||||
if (expect.equals(result)) {
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
LogUtil.APP.info("用例:{} 第{}步,精确匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
|
} else {
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
|
casenote = "第" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!";
|
||||||
} else {
|
setresult = 1;
|
||||||
casenote = "第" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!";
|
IosBaseAppium.screenShot(appium, imagname);
|
||||||
setresult = 1;
|
LogUtil.APP.warn("用例:{} 第{}步,精确匹配预期结果失败!预期结果是:【{}】 执行结果:【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),expect,result);
|
||||||
IosBaseAppium.screenShot(appium, imagname);
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果失败!预期结果是:【"+expect+"】 执行结果:【"+ result+"】", "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,精确匹配预期结果失败!预期结果是:【{}】 执行结果:【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),expect,result);
|
}
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果失败!预期结果是:【"+expect+"】 执行结果:【"+ result+"】", "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
}
|
casenote = (null != result) ? result : "";
|
||||||
} else {
|
setresult = 2;
|
||||||
casenote = (null != result) ? result : "";
|
IosBaseAppium.screenShot(appium, imagname);
|
||||||
setresult = 2;
|
LogUtil.APP.warn("用例:{} 第{}步,执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),casenote);
|
||||||
IosBaseAppium.screenShot(appium, imagname);
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "当前步骤在执行过程中解析|定位元素|操作对象失败!" + casenote, "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),casenote);
|
}
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "当前步骤在执行过程中解析|定位元素|操作对象失败!" + casenote, "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
|
||||||
}
|
return setresult;
|
||||||
|
}
|
||||||
return setresult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,73 +1,68 @@
|
||||||
package luckyclient.execution.appium.iosex;
|
package luckyclient.execution.appium.iosex;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.appium.java_client.ios.IOSDriver;
|
import io.appium.java_client.ios.IOSDriver;
|
||||||
import io.appium.java_client.ios.IOSElement;
|
import io.appium.java_client.ios.IOSElement;
|
||||||
import luckyclient.remote.api.GetServerApi;
|
import luckyclient.remote.api.GetServerApi;
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.ProjectCase;
|
||||||
import luckyclient.remote.entity.ProjectCaseParams;
|
import luckyclient.remote.entity.ProjectCaseParams;
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
import luckyclient.remote.entity.ProjectCaseSteps;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author seagull
|
* @author seagull
|
||||||
* @date 2018年1月29日
|
* @date 2018年1月29日
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class IosCaseLocalDebug {
|
public class IosCaseLocalDebug {
|
||||||
|
|
||||||
public static void oneCasedebug(IOSDriver<IOSElement> iosdriver, String testCaseExternalId) {
|
public static void oneCasedebug(IOSDriver<IOSElement> iosdriver, String testCaseExternalId) {
|
||||||
// 不记录日志到数据库
|
// 不记录日志到数据库
|
||||||
serverOperation.exetype = 1;
|
serverOperation.exetype = 1;
|
||||||
serverOperation caselog = new serverOperation();
|
serverOperation caselog = new serverOperation();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ProjectCase testcase = GetServerApi.cgetCaseBysign(testCaseExternalId);
|
ProjectCase testcase = GetServerApi.cgetCaseBysign(testCaseExternalId);
|
||||||
List<ProjectCaseParams> pcplist = GetServerApi
|
List<ProjectCaseParams> pcplist = GetServerApi
|
||||||
.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
|
.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
|
||||||
LogUtil.APP.info("开始执行用例:【{}】......",testCaseExternalId);
|
LogUtil.APP.info("开始执行用例:【{}】......",testCaseExternalId);
|
||||||
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
||||||
IosCaseExecution.caseExcution(testcase, steps, "888888", iosdriver, caselog, pcplist);
|
IosCaseExecution.caseExcution(testcase, steps, "888888", iosdriver, caselog, pcplist);
|
||||||
|
|
||||||
LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
|
LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param 项目名
|
* 用于做多条用例串行调试
|
||||||
* @param 用例编号
|
* @param iosdriver IOS驱动
|
||||||
* @param 用例版本号
|
* @param projectname 项目名称
|
||||||
* 用于在testlink上配置好用例参数后,做多条用例串行调试
|
* @param addtestcase 用例编号
|
||||||
*/
|
*/
|
||||||
public static void moreCaseDebug(IOSDriver<IOSElement> iosdriver, String projectname,
|
public static void moreCaseDebug(IOSDriver<IOSElement> iosdriver, String projectname,
|
||||||
List<String> addtestcase) {
|
List<String> addtestcase) {
|
||||||
System.out.println("当前调试用例总共:"+addtestcase.size());
|
System.out.println("当前调试用例总共:"+addtestcase.size());
|
||||||
for(String testCaseExternalId:addtestcase) {
|
for(String testCaseExternalId:addtestcase) {
|
||||||
try {
|
try {
|
||||||
LogUtil.APP
|
LogUtil.APP
|
||||||
.info("开始调用方法,项目名:{},用例编号:{}",projectname,testCaseExternalId);
|
.info("开始调用方法,项目名:{},用例编号:{}",projectname,testCaseExternalId);
|
||||||
oneCasedebug(iosdriver, testCaseExternalId);
|
oneCasedebug(iosdriver, testCaseExternalId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.APP.error("多用例调试过程中抛出异常!", e);
|
LogUtil.APP.error("多用例调试过程中抛出异常!", e);
|
||||||
continue;
|
}
|
||||||
}
|
}
|
||||||
}
|
// 关闭APP以及appium会话
|
||||||
// 关闭APP以及appium会话
|
iosdriver.closeApp();
|
||||||
iosdriver.closeApp();
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
public static void main(String[] args) throws IOException {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,73 +1,74 @@
|
||||||
package luckyclient.execution.appium.iosex;
|
package luckyclient.execution.appium.iosex;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import io.appium.java_client.ios.IOSDriver;
|
import io.appium.java_client.ios.IOSDriver;
|
||||||
import io.appium.java_client.ios.IOSElement;
|
import io.appium.java_client.ios.IOSElement;
|
||||||
import luckyclient.execution.appium.AppiumInitialization;
|
import luckyclient.execution.appium.AppiumInitialization;
|
||||||
import luckyclient.execution.appium.AppiumService;
|
import luckyclient.execution.appium.AppiumService;
|
||||||
import luckyclient.execution.httpinterface.TestControl;
|
import luckyclient.execution.httpinterface.TestControl;
|
||||||
import luckyclient.remote.api.GetServerApi;
|
import luckyclient.remote.api.GetServerApi;
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.ProjectCase;
|
||||||
import luckyclient.remote.entity.ProjectCaseParams;
|
import luckyclient.remote.entity.ProjectCaseParams;
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
import luckyclient.remote.entity.ProjectCaseSteps;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
import luckyclient.utils.config.AppiumConfig;
|
import luckyclient.utils.config.AppiumConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
* @date 2018年2月2日
|
* @date 2018年2月2日
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class IosOneCaseExecute {
|
public class IosOneCaseExecute {
|
||||||
|
|
||||||
public static void oneCaseExecuteForTast(String projectname, Integer caseId, int version, String taskid)
|
public static void oneCaseExecuteForTast(Integer caseId, String taskid)
|
||||||
throws IOException, InterruptedException {
|
throws InterruptedException {
|
||||||
// 记录日志到数据库
|
// 记录日志到数据库
|
||||||
serverOperation.exetype = 0;
|
serverOperation.exetype = 0;
|
||||||
TestControl.TASKID = taskid;
|
TestControl.TASKID = taskid;
|
||||||
IOSDriver<IOSElement> iosd = null;
|
IOSDriver<IOSElement> iosd = null;
|
||||||
AppiumService as=null;
|
AppiumService as=null;
|
||||||
try {
|
try {
|
||||||
Properties properties = AppiumConfig.getConfiguration();
|
Properties properties = AppiumConfig.getConfiguration();
|
||||||
//根据配置自动启动Appiume服务
|
//根据配置自动启动Appiume服务
|
||||||
if(Boolean.valueOf(properties.getProperty("autoRunAppiumService"))){
|
if(Boolean.parseBoolean(properties.getProperty("autoRunAppiumService"))){
|
||||||
as =new AppiumService();
|
as =new AppiumService();
|
||||||
as.start();
|
as.start();
|
||||||
Thread.sleep(10000);
|
Thread.sleep(10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
iosd = AppiumInitialization.setIosAppium(properties);
|
iosd = AppiumInitialization.setIosAppium(properties);
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
LogUtil.APP.error("初始化IOSDriver出错!", e1);
|
LogUtil.APP.error("初始化IOSDriver出错!", e1);
|
||||||
}
|
}
|
||||||
serverOperation caselog = new serverOperation();
|
serverOperation caselog = new serverOperation();
|
||||||
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(caseId);
|
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(caseId);
|
||||||
// 删除旧的日志
|
// 删除旧的日志
|
||||||
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
||||||
|
|
||||||
List<ProjectCaseParams> pcplist = GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
|
List<ProjectCaseParams> pcplist = GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
|
||||||
LogUtil.APP.info("开始执行用例:【{}】......",testcase.getCaseSign());
|
LogUtil.APP.info("开始执行用例:【{}】......",testcase.getCaseSign());
|
||||||
try {
|
try {
|
||||||
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
||||||
IosCaseExecution.caseExcution(testcase, steps, taskid, iosd, caselog, pcplist);
|
IosCaseExecution.caseExcution(testcase, steps, taskid, iosd, caselog, pcplist);
|
||||||
LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
|
LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
|
||||||
} catch (InterruptedException e) {
|
} catch (Exception e) {
|
||||||
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
||||||
}
|
}
|
||||||
serverOperation.updateTaskExecuteData(taskid, 0,2);
|
serverOperation.updateTaskExecuteData(taskid, 0,2);
|
||||||
iosd.closeApp();
|
assert iosd != null;
|
||||||
//关闭Appium服务的线程
|
iosd.closeApp();
|
||||||
if(as!=null){
|
//关闭Appium服务的线程
|
||||||
as.interrupt();
|
if(as!=null){
|
||||||
}
|
as.interrupt();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,63 +1,63 @@
|
||||||
package luckyclient.execution.dispose;
|
package luckyclient.execution.dispose;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.reflections.Reflections;
|
import org.reflections.Reflections;
|
||||||
|
|
||||||
import luckyclient.execution.dispose.actionkeyword.Action;
|
import luckyclient.execution.dispose.actionkeyword.Action;
|
||||||
import luckyclient.execution.dispose.actionkeyword.ActionKeyWordParser;
|
import luckyclient.execution.dispose.actionkeyword.ActionKeyWordParser;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 步骤动作容器,根据参数生成不同的动作关键字类型,执行相应的解析
|
* 步骤动作容器,根据参数生成不同的动作关键字类型,执行相应的解析
|
||||||
* @author: sunshaoyan@
|
* @author: sunshaoyan@
|
||||||
* @date: Created on 2019/4/13
|
* @date: Created on 2019/4/13
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public class ActionContext {
|
public class ActionContext {
|
||||||
|
|
||||||
private static Map<String, Class> allActions;
|
private static Map<String, Class> allActions;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Reflections reflections = new Reflections("luckyclient.execution.dispose.actionkeyword");
|
Reflections reflections = new Reflections("luckyclient.execution.dispose.actionkeyword");
|
||||||
Set<Class<?>> annotatedClasses =
|
Set<Class<?>> annotatedClasses =
|
||||||
reflections.getTypesAnnotatedWith(Action.class);
|
reflections.getTypesAnnotatedWith(Action.class);
|
||||||
allActions = new ConcurrentHashMap<String, Class>();
|
allActions = new ConcurrentHashMap<>();
|
||||||
for (Class<?> classObject : annotatedClasses) {
|
for (Class<?> classObject : annotatedClasses) {
|
||||||
Action action = (Action) classObject
|
Action action = classObject
|
||||||
.getAnnotation(Action.class);
|
.getAnnotation(Action.class);
|
||||||
allActions.put(action.name(), classObject);
|
allActions.put(action.name(), classObject);
|
||||||
}
|
}
|
||||||
allActions = Collections.unmodifiableMap(allActions);
|
allActions = Collections.unmodifiableMap(allActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ActionKeyWordParser action;
|
private ActionKeyWordParser action;
|
||||||
|
|
||||||
public ActionContext(String name){
|
public ActionContext(String name){
|
||||||
|
|
||||||
if (allActions.containsKey(name)) {
|
if (allActions.containsKey(name)) {
|
||||||
LogUtil.APP.info("Created Action name is {}", name);
|
LogUtil.APP.info("Created Action name is {}", name);
|
||||||
try {
|
try {
|
||||||
action = (ActionKeyWordParser) allActions.get(name).newInstance();
|
action = (ActionKeyWordParser) allActions.get(name).newInstance();
|
||||||
} catch (InstantiationException | IllegalAccessException ex) {
|
} catch (InstantiationException | IllegalAccessException ex) {
|
||||||
LogUtil.APP.error("Instantiate Action failed", ex);
|
LogUtil.APP.error("Instantiate Action failed", ex);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LogUtil.APP.warn("Specified Action name {} does not exist", name);
|
LogUtil.APP.warn("Specified Action name {} does not exist", name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String parse(String actionParams,String testResult,String actionKeyWord) {
|
public String parse(String actionParams,String testResult,String actionKeyWord) {
|
||||||
if(null != action){
|
if(null != action){
|
||||||
testResult = action.parse(actionParams, testResult);
|
testResult = action.parse(actionParams, testResult);
|
||||||
}else {
|
}else {
|
||||||
testResult="未检索到对应动作关键字,直接跳过此动作,请检查关键字:"+actionKeyWord;
|
testResult="未检索到对应动作关键字,直接跳过此动作,请检查关键字:"+actionKeyWord;
|
||||||
LogUtil.APP.warn("未检索到对应动作关键字,直接跳过此动作,请检查关键字:{}",actionKeyWord);
|
LogUtil.APP.warn("未检索到对应动作关键字,直接跳过此动作,请检查关键字:{}",actionKeyWord);
|
||||||
}
|
}
|
||||||
return testResult;
|
return testResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,90 +1,90 @@
|
||||||
package luckyclient.execution.dispose;
|
package luckyclient.execution.dispose;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import luckyclient.utils.Constants;
|
import luckyclient.utils.Constants;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 动作关键字处理
|
* 动作关键字处理
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年1月15日
|
* @date 2019年1月15日
|
||||||
*/
|
*/
|
||||||
public class ActionManageForSteps {
|
public class ActionManageForSteps {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析用例步骤
|
* 解析用例步骤
|
||||||
* @param stepsaction
|
* @param stepsaction 步骤关键字
|
||||||
* @param testresult
|
* @param testresult 待处理测试结果
|
||||||
* @return
|
* @return 返回处理后结果
|
||||||
*/
|
*/
|
||||||
public static String actionManage(String stepsaction,String testresult){
|
public static String actionManage(String stepsaction,String testresult){
|
||||||
LogUtil.APP.info("Action(动作)处理前,测试结果是:{}",testresult);
|
LogUtil.APP.info("Action(动作)处理前,测试结果是:{}",testresult);
|
||||||
LogUtil.APP.info("现在进入到Action(动作)处理......ACTION值:{}",stepsaction);
|
LogUtil.APP.info("现在进入到Action(动作)处理......ACTION值:{}",stepsaction);
|
||||||
if(null==stepsaction||"".equals(stepsaction.trim())){
|
if(null==stepsaction||"".equals(stepsaction.trim())){
|
||||||
LogUtil.APP.info("Action(动作)无需处理......");
|
LogUtil.APP.info("Action(动作)无需处理......");
|
||||||
return testresult;
|
return testresult;
|
||||||
}
|
}
|
||||||
|
|
||||||
String responseHead="";
|
String responseHead="";
|
||||||
String responseCode="";
|
String responseCode="";
|
||||||
//去除测试响应头域消息
|
//去除测试响应头域消息
|
||||||
if(testresult.startsWith(Constants.RESPONSE_HEAD)){
|
if(testresult.startsWith(Constants.RESPONSE_HEAD)){
|
||||||
responseHead = testresult.substring(0,testresult.indexOf(Constants.RESPONSE_END)+1);
|
responseHead = testresult.substring(0,testresult.indexOf(Constants.RESPONSE_END)+1);
|
||||||
testresult = testresult.substring(testresult.indexOf(responseHead)+responseHead.length()+1);
|
testresult = testresult.substring(testresult.indexOf(responseHead)+responseHead.length()+1);
|
||||||
responseHead = responseHead+" ";
|
responseHead = responseHead+" ";
|
||||||
}
|
}
|
||||||
|
|
||||||
//去除测试响应头域消息
|
//去除测试响应头域消息
|
||||||
if(testresult.startsWith(Constants.RESPONSE_CODE)){
|
if(testresult.startsWith(Constants.RESPONSE_CODE)){
|
||||||
responseCode = testresult.substring(0,testresult.indexOf(Constants.RESPONSE_END)+1);
|
responseCode = testresult.substring(0,testresult.indexOf(Constants.RESPONSE_END)+1);
|
||||||
testresult = testresult.substring(testresult.indexOf(responseCode)+responseCode.length()+1);
|
testresult = testresult.substring(testresult.indexOf(responseCode)+responseCode.length()+1);
|
||||||
responseCode = responseCode+" ";
|
responseCode = responseCode+" ";
|
||||||
}
|
}
|
||||||
|
|
||||||
stepsaction=stepsaction.trim();
|
stepsaction=stepsaction.trim();
|
||||||
String[] temp=stepsaction.split("\\|",-1);
|
String[] temp=stepsaction.split("\\|",-1);
|
||||||
for(String actionorder:temp){
|
for(String actionorder:temp){
|
||||||
if(null!=actionorder&&!"".equals(actionorder.trim())){
|
if(null!=actionorder&&!"".equals(actionorder.trim())){
|
||||||
testresult=actionExecute(actionorder,testresult);
|
testresult=actionExecute(actionorder,testresult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//返回处理结果时,再把响应头以及响应码加上
|
//返回处理结果时,再把响应头以及响应码加上
|
||||||
return responseHead+responseCode+testresult;
|
return responseHead+responseCode+testresult;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 动作关键字执行
|
* 动作关键字执行
|
||||||
* @param actionKeyWord
|
* @param actionKeyWord 步骤关键字
|
||||||
* @param testResult
|
* @param testResult 待处理测试结果
|
||||||
* @return
|
* @return 关键字处理后返回结果
|
||||||
*/
|
*/
|
||||||
private static String actionExecute(String actionKeyWord,String testResult){
|
private static String actionExecute(String actionKeyWord,String testResult){
|
||||||
try{
|
try{
|
||||||
String keyWord = "";
|
String keyWord = "";
|
||||||
String actionParams = "";
|
String actionParams = "";
|
||||||
if(actionKeyWord.contains("#")){
|
if(actionKeyWord.contains("#")){
|
||||||
keyWord = actionKeyWord.substring(actionKeyWord.lastIndexOf("#")+1, actionKeyWord.length());
|
keyWord = actionKeyWord.substring(actionKeyWord.lastIndexOf("#")+1);
|
||||||
actionParams = actionKeyWord.substring(0, actionKeyWord.lastIndexOf("#"));
|
actionParams = actionKeyWord.substring(0, actionKeyWord.lastIndexOf("#"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StrUtil.isNotEmpty(keyWord)&& keyWord.length()>0){
|
if(StrUtil.isNotEmpty(keyWord)&& keyWord.length()>0){
|
||||||
ActionContext actionContext = new ActionContext(keyWord.toLowerCase());
|
ActionContext actionContext = new ActionContext(keyWord.toLowerCase());
|
||||||
testResult = actionContext.parse(actionParams, testResult, actionKeyWord);
|
testResult = actionContext.parse(actionParams, testResult, actionKeyWord);
|
||||||
}else {
|
}else {
|
||||||
testResult="关键字语法书写有误,请检查关键字:"+actionKeyWord;
|
testResult="关键字语法书写有误,请检查关键字:"+actionKeyWord;
|
||||||
LogUtil.APP.warn("关键字语法书写有误,请检查关键字:{}",actionKeyWord);
|
LogUtil.APP.warn("关键字语法书写有误,请检查关键字:{}",actionKeyWord);
|
||||||
}
|
}
|
||||||
return testResult;
|
return testResult;
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
testResult="处理步骤动作事件过程中出现异常,直接返回测试结果:"+actionKeyWord;
|
testResult="处理步骤动作事件过程中出现异常,直接返回测试结果:"+actionKeyWord;
|
||||||
LogUtil.APP.error("处理步骤动作事件过程中出现异常,直接返回测试结果!" ,e);
|
LogUtil.APP.error("处理步骤动作事件过程中出现异常,直接返回测试结果!" ,e);
|
||||||
return testResult;
|
return testResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,7 @@ package luckyclient.execution.dispose;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
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.Map.Entry;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -34,10 +28,10 @@ public class ChangString {
|
||||||
/**
|
/**
|
||||||
* 替换变量中的字符
|
* 替换变量中的字符
|
||||||
*
|
*
|
||||||
* @param str
|
* @param str 待处理字符串
|
||||||
* @param variable
|
* @param variable 变量集(公共变量、全局变量、局部变量)
|
||||||
* @param changname
|
* @param changname 变量key
|
||||||
* @return
|
* @return 返回替换后的字符串
|
||||||
*/
|
*/
|
||||||
public static String changparams(String str, Map<String, String> variable, String changname) {
|
public static String changparams(String str, Map<String, String> variable, String changname) {
|
||||||
try {
|
try {
|
||||||
|
@ -45,7 +39,7 @@ public class ChangString {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
str = str.replace(""", "\"");
|
str = str.replace(""", "\"");
|
||||||
str = str.replace("'", "\'");
|
str = str.replace("'", "'");
|
||||||
// @@用来注释@的引用作用
|
// @@用来注释@的引用作用
|
||||||
int varcount = counter(str, "@") - counter(str, "@@") * 2;
|
int varcount = counter(str, "@") - counter(str, "@@") * 2;
|
||||||
|
|
||||||
|
@ -55,17 +49,14 @@ public class ChangString {
|
||||||
int changcount = 0;
|
int changcount = 0;
|
||||||
|
|
||||||
// 准备将HASHMAP换成LINKMAP,对KEY进行排序,解决要先替换最长KEY的问题
|
// 准备将HASHMAP换成LINKMAP,对KEY进行排序,解决要先替换最长KEY的问题
|
||||||
List<Map.Entry<String, String>> list = new ArrayList<Map.Entry<String, String>>(variable.entrySet());
|
List<Map.Entry<String, String>> list = new ArrayList<>(variable.entrySet());
|
||||||
// 然后通过比较器来实现排序
|
// 然后通过比较器来实现排序
|
||||||
Collections.sort(list, new Comparator<Map.Entry<String, String>>() {
|
// 按KEY长度降序排序
|
||||||
// °´KEY³¤¶È½µÐòÅÅÐò
|
// 然后通过比较器来实现排序
|
||||||
@Override
|
// 按KEY长度降序排序
|
||||||
public int compare(Entry<String, String> o1, Entry<String, String> o2) {
|
list.sort((o1, o2) -> o2.getKey().length() - o1.getKey().length());
|
||||||
return o2.getKey().length() - o1.getKey().length();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Map<String, String> aMap2 = new LinkedHashMap<String, String>();
|
Map<String, String> aMap2 = new LinkedHashMap<>();
|
||||||
for (Map.Entry<String, String> mapping : list) {
|
for (Map.Entry<String, String> mapping : list) {
|
||||||
aMap2.put(mapping.getKey(), mapping.getValue());
|
aMap2.put(mapping.getKey(), mapping.getValue());
|
||||||
}
|
}
|
||||||
|
@ -105,10 +96,9 @@ public class ChangString {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统计字符
|
* 统计字符
|
||||||
*
|
* @param str1 原始字符串
|
||||||
* @param str1
|
* @param str2 待统计字符串
|
||||||
* @param str2
|
* @return 返回个数
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static int counter(String str1, String str2) {
|
public static int counter(String str1, String str2) {
|
||||||
int total = 0;
|
int total = 0;
|
||||||
|
@ -125,9 +115,8 @@ public class ChangString {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断是否是数字
|
* 判断是否是数字
|
||||||
*
|
* @param str 数字字符
|
||||||
* @param str
|
* @return 返回布尔值
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static boolean isNumeric(String str) {
|
public static boolean isNumeric(String str) {
|
||||||
for (int i = 0; i < str.length(); i++) {
|
for (int i = 0; i < str.length(); i++) {
|
||||||
|
@ -140,22 +129,20 @@ public class ChangString {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断是否是整数
|
* 判断是否是整数
|
||||||
*
|
* @param str 数字字符
|
||||||
* @param str
|
* @return 返回布尔值
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static boolean isInteger(String str) {
|
public static boolean isInteger(String str) {
|
||||||
String patternStr="^[-\\+]?[\\d]*$";
|
String patternStr="^[-+]?[\\d]*$";
|
||||||
Pattern pattern = Pattern.compile(patternStr);
|
Pattern pattern = Pattern.compile(patternStr);
|
||||||
return pattern.matcher(str).matches();
|
return pattern.matcher(str).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 替换变量类型
|
* 替换变量类型
|
||||||
*
|
* @param object 替换对象
|
||||||
* @param object
|
* @param str 替换字符串
|
||||||
* @param str
|
* @return 返回对象
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static Object settype(Object object, String str) {
|
public static Object settype(Object object, String str) {
|
||||||
if (object instanceof Integer) {
|
if (object instanceof Integer) {
|
||||||
|
@ -185,11 +172,11 @@ public class ChangString {
|
||||||
private static Boolean BCHANG=false;
|
private static Boolean BCHANG=false;
|
||||||
/**
|
/**
|
||||||
* 遍历JSON对象
|
* 遍历JSON对象
|
||||||
* @param json
|
* @param json 原始json
|
||||||
* @param key
|
* @param key 替换key
|
||||||
* @param value
|
* @param value 替换值
|
||||||
* @param keyindex
|
* @param keyindex 替换key索引
|
||||||
* @return
|
* @return 返回json对象
|
||||||
*/
|
*/
|
||||||
public static JSONObject parseJsonString(String json,String key,String value,int keyindex){
|
public static JSONObject parseJsonString(String json,String key,String value,int keyindex){
|
||||||
LinkedHashMap<String, Object> jsonMap = JSON.parseObject(json, new TypeReference<LinkedHashMap<String, Object>>(){});
|
LinkedHashMap<String, Object> jsonMap = JSON.parseObject(json, new TypeReference<LinkedHashMap<String, Object>>(){});
|
||||||
|
@ -201,14 +188,13 @@ public class ChangString {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 替换遍历后JSON对象中的KEY
|
* 替换遍历后JSON对象中的KEY
|
||||||
* @param entry
|
* @param entry json对象转换成MAP
|
||||||
* @param key
|
* @param key 待替换key
|
||||||
* @param value
|
* @param value 替换值
|
||||||
* @param keyindex
|
* @param keyindex 替换key索引
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Map.Entry<String, Object> parseJsonMap(Map.Entry<String, Object> entry,String key,String value,int keyindex){
|
public static void parseJsonMap(Entry<String, Object> entry, String key, String value, int keyindex){
|
||||||
//如果是字符串型的null直接把对象设置为对象null
|
//如果是字符串型的null直接把对象设置为对象null
|
||||||
if("NULL".equals(value)){
|
if("NULL".equals(value)){
|
||||||
value = null;
|
value = null;
|
||||||
|
@ -273,6 +259,7 @@ public class ChangString {
|
||||||
if(key.equals(entry.getKey())){
|
if(key.equals(entry.getKey())){
|
||||||
if(keyindex==COUNTER){
|
if(keyindex==COUNTER){
|
||||||
LogUtil.APP.info("对象原始Integer值:【{}】",entry.getValue());
|
LogUtil.APP.info("对象原始Integer值:【{}】",entry.getValue());
|
||||||
|
assert value != null;
|
||||||
entry.setValue(Integer.valueOf(value));
|
entry.setValue(Integer.valueOf(value));
|
||||||
LogUtil.APP.info("对象替换后Integer值:【{}】",entry.getValue());
|
LogUtil.APP.info("对象替换后Integer值:【{}】",entry.getValue());
|
||||||
BCHANG=true;
|
BCHANG=true;
|
||||||
|
@ -285,6 +272,7 @@ public class ChangString {
|
||||||
if(key.equals(entry.getKey())){
|
if(key.equals(entry.getKey())){
|
||||||
if(keyindex==COUNTER){
|
if(keyindex==COUNTER){
|
||||||
LogUtil.APP.info("对象原始Long值:【{}】",entry.getValue());
|
LogUtil.APP.info("对象原始Long值:【{}】",entry.getValue());
|
||||||
|
assert value != null;
|
||||||
entry.setValue(Long.valueOf(value));
|
entry.setValue(Long.valueOf(value));
|
||||||
LogUtil.APP.info("对象替换后Long值:【{}】",entry.getValue());
|
LogUtil.APP.info("对象替换后Long值:【{}】",entry.getValue());
|
||||||
BCHANG=true;
|
BCHANG=true;
|
||||||
|
@ -297,6 +285,7 @@ public class ChangString {
|
||||||
if(key.equals(entry.getKey())){
|
if(key.equals(entry.getKey())){
|
||||||
if(keyindex==COUNTER){
|
if(keyindex==COUNTER){
|
||||||
LogUtil.APP.info("对象原始BigDecimal值:【{}】",entry.getValue());
|
LogUtil.APP.info("对象原始BigDecimal值:【{}】",entry.getValue());
|
||||||
|
assert value != null;
|
||||||
BigDecimal bd = new BigDecimal(value);
|
BigDecimal bd = new BigDecimal(value);
|
||||||
entry.setValue(bd);
|
entry.setValue(bd);
|
||||||
LogUtil.APP.info("对象替换后BigDecimal值:【{}】",entry.getValue());
|
LogUtil.APP.info("对象替换后BigDecimal值:【{}】",entry.getValue());
|
||||||
|
@ -317,28 +306,27 @@ public class ChangString {
|
||||||
COUNTER++;
|
COUNTER++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return entry;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 替换json对象中指定KEY入口方法
|
* 替换json对象中指定KEY入口方法
|
||||||
* @param json
|
* @param json 待替换原始json
|
||||||
* @param key
|
* @param key 替换key
|
||||||
* @param value
|
* @param value 替换值
|
||||||
* @param index
|
* @param index 替换key索引
|
||||||
* @return
|
* @return 返回替换后的MAP对象
|
||||||
*/
|
*/
|
||||||
public static Map<String, String> changjson(String json, String key, String value,int index) {
|
public static Map<String, String> changjson(String json, String key, String value,int index) {
|
||||||
json=json.trim();
|
json=json.trim();
|
||||||
LogUtil.APP.info("原始JSON:【{}】,待替换JSON KEY:【{}】,待替换JSON VALUE:【{}】,待替换JSON KEY序号:【{}】",json,key,value,index);
|
LogUtil.APP.info("原始JSON:【{}】,待替换JSON KEY:【{}】,待替换JSON VALUE:【{}】,待替换JSON KEY序号:【{}】",json,key,value,index);
|
||||||
Map<String, String> map = new HashMap<String, String>(0);
|
Map<String, String> map = new HashMap<>(0);
|
||||||
map.put("json", json);
|
map.put("json", json);
|
||||||
map.put("boolean", BCHANG.toString().toLowerCase());
|
map.put("boolean", BCHANG.toString().toLowerCase());
|
||||||
|
|
||||||
if (json.startsWith("{") && json.endsWith("}")) {
|
if (json.startsWith("{") && json.endsWith("}")) {
|
||||||
try {
|
try {
|
||||||
JSONObject jsonStr = JSONObject.parseObject(json);
|
JSONObject jsonStr;
|
||||||
jsonStr=parseJsonString(json,key,value,index);
|
jsonStr=parseJsonString(json,key,value,index);
|
||||||
if (BCHANG) {
|
if (BCHANG) {
|
||||||
LogUtil.APP.info("JSON字符串替换成功,新JSON:【{}】",jsonStr.toJSONString());
|
LogUtil.APP.info("JSON字符串替换成功,新JSON:【{}】",jsonStr.toJSONString());
|
||||||
|
|
|
@ -1,113 +1,113 @@
|
||||||
package luckyclient.execution.dispose;
|
package luckyclient.execution.dispose;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对内置参数进行处理
|
* 对内置参数进行处理
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年1月15日
|
* @date 2019年1月15日
|
||||||
*/
|
*/
|
||||||
public class ParamsManageForSteps {
|
public class ParamsManageForSteps {
|
||||||
public static Map<String, String> GLOBAL_VARIABLE = new HashMap<>(0);
|
public static Map<String, String> GLOBAL_VARIABLE = new HashMap<>(0);
|
||||||
/**
|
/**
|
||||||
* 进内置参数管理
|
* 进内置参数管理
|
||||||
* @param params
|
* @param params 内置参数关键字
|
||||||
* @return
|
* @return 返回参数处理结果
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年1月15日
|
* @date 2019年1月15日
|
||||||
*/
|
*/
|
||||||
public static String paramsManage(String params) {
|
public static String paramsManage(String params) {
|
||||||
ParamsManageForSteps pmfs = new ParamsManageForSteps();
|
ParamsManageForSteps pmfs = new ParamsManageForSteps();
|
||||||
params = pmfs.replaceRandomInt(params);
|
params = pmfs.replaceRandomInt(params);
|
||||||
params = pmfs.replaceTimeNow(params);
|
params = pmfs.replaceTimeNow(params);
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 内置参数生成替换(生成随机整数)
|
* 内置参数生成替换(生成随机整数)
|
||||||
* @param params
|
* @param params 参数关键字
|
||||||
* @return
|
* @return 返回随机数
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年1月15日
|
* @date 2019年1月15日
|
||||||
*/
|
*/
|
||||||
private String replaceRandomInt(String params) {
|
private String replaceRandomInt(String params) {
|
||||||
try {
|
try {
|
||||||
String str="(?i)@\\{random\\[(\\d+)\\]\\[(\\d+)\\]\\}";
|
String str="(?i)@\\{random\\[(\\d+)]\\[(\\d+)]}";
|
||||||
Pattern pattern = Pattern.compile(str);
|
Pattern pattern = Pattern.compile(str);
|
||||||
Matcher m = pattern.matcher(params);
|
Matcher m = pattern.matcher(params);
|
||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
String matcherstr = m.group(0);
|
String matcherstr = m.group(0);
|
||||||
int startnum = Integer
|
int startnum = Integer
|
||||||
.valueOf(matcherstr.substring(matcherstr.indexOf("[") + 1, matcherstr.indexOf("]")).trim());
|
.parseInt(matcherstr.substring(matcherstr.indexOf("[") + 1, matcherstr.indexOf("]")).trim());
|
||||||
int endnum = Integer
|
int endnum = Integer
|
||||||
.valueOf(matcherstr.substring(matcherstr.lastIndexOf("[") + 1, matcherstr.lastIndexOf("]")).trim());
|
.parseInt(matcherstr.substring(matcherstr.lastIndexOf("[") + 1, matcherstr.lastIndexOf("]")).trim());
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
String replacement = String.valueOf(random.nextInt(endnum - startnum + 1) + startnum);
|
String replacement = String.valueOf(random.nextInt(endnum - startnum + 1) + startnum);
|
||||||
params = m.replaceFirst(replacement);
|
params = m.replaceFirst(replacement);
|
||||||
LogUtil.APP.info("Params({}):替换成随机数后,字符串:{}",matcherstr,params);
|
LogUtil.APP.info("Params({}):替换成随机数后,字符串:{}",matcherstr,params);
|
||||||
m = pattern.matcher(params);
|
m = pattern.matcher(params);
|
||||||
}
|
}
|
||||||
return params;
|
return params;
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (IllegalArgumentException iae) {
|
||||||
LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查数字区间是否正常!",iae);
|
LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查数字区间是否正常!",iae);
|
||||||
return params;
|
return params;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查你的格式是否正确!",e);
|
LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查你的格式是否正确!",e);
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 内置参数生成替换(生成当时时间指定格式)
|
* 内置参数生成替换(生成当时时间指定格式)
|
||||||
* @param params
|
* @param params 参数关键字
|
||||||
* @return
|
* @return 返回生成的参数
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年1月15日
|
* @date 2019年1月15日
|
||||||
*/
|
*/
|
||||||
private String replaceTimeNow(String params) {
|
private String replaceTimeNow(String params) {
|
||||||
try {
|
try {
|
||||||
String str="(?i)@\\{timenow\\[(.*?)\\]\\}";
|
String str="(?i)@\\{timenow\\[(.*?)]}";
|
||||||
Pattern pattern = Pattern.compile(str);
|
Pattern pattern = Pattern.compile(str);
|
||||||
Matcher m = pattern.matcher(params);
|
Matcher m = pattern.matcher(params);
|
||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
String matcherstr = m.group(0);
|
String matcherstr = m.group(0);
|
||||||
String formart = matcherstr.substring(matcherstr.indexOf("[") + 1, matcherstr.indexOf("]")).trim();
|
String formart = matcherstr.substring(matcherstr.indexOf("[") + 1, matcherstr.indexOf("]")).trim();
|
||||||
SimpleDateFormat df = null;
|
SimpleDateFormat df;
|
||||||
try {
|
try {
|
||||||
if("".equals(formart)||"timestamp".equals(formart.toLowerCase())){
|
if("".equals(formart)||"timestamp".equals(formart.toLowerCase())){
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
matcherstr=String.valueOf(time);
|
matcherstr=String.valueOf(time);
|
||||||
}else{
|
}else{
|
||||||
df = new SimpleDateFormat(formart);
|
df = new SimpleDateFormat(formart);
|
||||||
matcherstr=df.format(new Date());
|
matcherstr=df.format(new Date());
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (IllegalArgumentException iae) {
|
||||||
LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查你的格式是否正确!",iae);
|
LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查你的格式是否正确!",iae);
|
||||||
df = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
|
df = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
|
||||||
matcherstr=df.format(new Date());
|
matcherstr=df.format(new Date());
|
||||||
} finally {
|
} finally {
|
||||||
params = m.replaceFirst(matcherstr);
|
params = m.replaceFirst(matcherstr);
|
||||||
LogUtil.APP.info("Params({}):替换成随机数后,字符串:{}",matcherstr,params);
|
LogUtil.APP.info("Params({}):替换成随机数后,字符串:{}",matcherstr,params);
|
||||||
m = pattern.matcher(params);
|
m = pattern.matcher(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return params;
|
return params;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查你的格式是否正确!",e);
|
LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查你的格式是否正确!",e);
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
package luckyclient.execution.dispose.actionkeyword;
|
package luckyclient.execution.dispose.actionkeyword;
|
||||||
|
|
||||||
/**
|
import java.lang.annotation.*;
|
||||||
* 动作关键字注解定义
|
|
||||||
* @author: sunshaoyan
|
/**
|
||||||
* @date: Created on 2019/4/13
|
* 动作关键字注解定义
|
||||||
*/
|
* @author: sunshaoyan
|
||||||
|
* @date: Created on 2019/4/13
|
||||||
import java.lang.annotation.*;
|
*/
|
||||||
|
|
||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Documented
|
@Documented
|
||||||
@Inherited
|
@Inherited
|
||||||
public @interface Action {
|
public @interface Action {
|
||||||
String name() default "";
|
String name() default "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
package luckyclient.execution.dispose.actionkeyword;
|
package luckyclient.execution.dispose.actionkeyword;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 动作关键字的处理接口
|
* 动作关键字的处理接口
|
||||||
* @author: sunshaoyan
|
* @author: sunshaoyan
|
||||||
* @date: Created on 2019/4/13
|
* @date: Created on 2019/4/13
|
||||||
*/
|
*/
|
||||||
public interface ActionKeyWordParser {
|
public interface ActionKeyWordParser {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 针对关键字的抽象方法
|
* 针对关键字的抽象方法
|
||||||
* @param actionParams
|
* @param actionParams 关键字
|
||||||
* @param testResult
|
* @param testResult 待处理的测试结果
|
||||||
* @return
|
* @return 返回处理结果
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年8月8日
|
* @date 2019年8月8日
|
||||||
*/
|
*/
|
||||||
String parse(String actionParams, String testResult);
|
String parse(String actionParams, String testResult);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class GetJsonActionParser implements ActionKeyWordParser {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String parse(String actionParams, String testResult) {
|
public String parse(String actionParams, String testResult) {
|
||||||
String key="";
|
String key;
|
||||||
String index="1";
|
String index="1";
|
||||||
if(actionParams.endsWith("]")&&actionParams.contains("[")){
|
if(actionParams.endsWith("]")&&actionParams.contains("[")){
|
||||||
key=actionParams.substring(0,actionParams.indexOf("["));
|
key=actionParams.substring(0,actionParams.indexOf("["));
|
||||||
|
|
|
@ -16,9 +16,9 @@ public class HeaderParser implements ActionKeyWordParser {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 动作关键字
|
* 动作关键字
|
||||||
* @param actionParams
|
* @param actionParams 关键字参数
|
||||||
* @param testResult
|
* @param testResult 待处理的测试结果
|
||||||
* @return
|
* @return 返回处理结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String parse(String actionParams, String testResult) {
|
public String parse(String actionParams, String testResult) {
|
||||||
|
|
|
@ -19,8 +19,8 @@ public class SubCentresStrActionParser implements ActionKeyWordParser {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String parse(String actionParams, String testResult) {
|
public String parse(String actionParams, String testResult) {
|
||||||
String startstr="";
|
String startstr;
|
||||||
String endstr="";
|
String endstr;
|
||||||
if(actionParams.startsWith("[")&&actionParams.endsWith("]")){
|
if(actionParams.startsWith("[")&&actionParams.endsWith("]")){
|
||||||
startstr=actionParams.substring(actionParams.indexOf("[")+1, actionParams.indexOf("]"));
|
startstr=actionParams.substring(actionParams.indexOf("[")+1, actionParams.indexOf("]"));
|
||||||
endstr=actionParams.substring(actionParams.lastIndexOf("[")+1, actionParams.lastIndexOf("]"));
|
endstr=actionParams.substring(actionParams.lastIndexOf("[")+1, actionParams.lastIndexOf("]"));
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class SubStrRegxActionParser implements ActionKeyWordParser {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String parse(String actionParams, String testResult) {
|
public String parse(String actionParams, String testResult) {
|
||||||
String key="";
|
String key;
|
||||||
String index="1";
|
String index="1";
|
||||||
if(actionParams.endsWith("]")&&actionParams.contains("[")){
|
if(actionParams.endsWith("]")&&actionParams.contains("[")){
|
||||||
key=actionParams.substring(0,actionParams.lastIndexOf("["));
|
key=actionParams.substring(0,actionParams.lastIndexOf("["));
|
||||||
|
|
|
@ -15,9 +15,9 @@ public class ThreadWaitAction implements ActionKeyWordParser {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 动作关键字
|
* 动作关键字
|
||||||
* @param actionParams
|
* @param actionParams 关键字参数
|
||||||
* @param testResult
|
* @param testResult 待处理测试结果
|
||||||
* @return
|
* @return 返回处理后结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String parse(String actionParams, String testResult) {
|
public String parse(String actionParams, String testResult) {
|
||||||
|
|
|
@ -1,239 +1,230 @@
|
||||||
package luckyclient.execution.httpinterface;
|
package luckyclient.execution.httpinterface;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import luckyclient.execution.dispose.ActionManageForSteps;
|
import luckyclient.execution.dispose.ActionManageForSteps;
|
||||||
import luckyclient.execution.httpinterface.analyticsteps.InterfaceAnalyticCase;
|
import luckyclient.execution.httpinterface.analyticsteps.InterfaceAnalyticCase;
|
||||||
import luckyclient.remote.api.GetServerApi;
|
import luckyclient.remote.api.GetServerApi;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.ProjectCase;
|
||||||
import luckyclient.remote.entity.ProjectCaseParams;
|
import luckyclient.remote.entity.ProjectCaseParams;
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
import luckyclient.remote.entity.ProjectCaseSteps;
|
||||||
import luckyclient.utils.InvokeMethod;
|
import luckyclient.utils.InvokeMethod;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
import luckyclient.utils.httputils.HttpRequest;
|
import luckyclient.utils.httputils.HttpRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @ClassName: TestCaseDebug
|
* @ClassName: TestCaseDebug
|
||||||
* @Description: 针对自动化用例在编写过程中,对用例脚本进行调试 @author: seagull
|
* @Description: 针对自动化用例在编写过程中,对用例脚本进行调试 @author: seagull
|
||||||
* @date 2018年3月1日
|
* @date 2018年3月1日
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ApiTestCaseDebug {
|
public class ApiTestCaseDebug {
|
||||||
private static final String ASSIGNMENT_SIGN = "$=";
|
private static final String ASSIGNMENT_SIGN = "$=";
|
||||||
private static final String FUZZY_MATCHING_SIGN = "%=";
|
private static final String FUZZY_MATCHING_SIGN = "%=";
|
||||||
private static final String REGULAR_MATCHING_SIGN = "~=";
|
private static final String REGULAR_MATCHING_SIGN = "~=";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用于在本地做单条用例调试
|
* 用于在本地做单条用例调试
|
||||||
*
|
* @param testCaseExternalId 用例编号
|
||||||
* @param projectname
|
*/
|
||||||
* @param testCaseExternalId
|
public static void oneCaseDebug(String testCaseExternalId) {
|
||||||
*/
|
Map<String, String> variable = new HashMap<>(0);
|
||||||
public static void oneCaseDebug(String projectname, String testCaseExternalId) {
|
String packagename;
|
||||||
Map<String, String> variable = new HashMap<String, String>(0);
|
String functionname;
|
||||||
String packagename = null;
|
String expectedresults;
|
||||||
String functionname = null;
|
int setcaseresult = 0;
|
||||||
String expectedresults = null;
|
Object[] getParameterValues;
|
||||||
Integer setcaseresult = 0;
|
String testnote = "初始化测试结果";
|
||||||
Object[] getParameterValues = null;
|
int k = 0;
|
||||||
String testnote = "初始化测试结果";
|
ProjectCase testcase = GetServerApi.cgetCaseBysign(testCaseExternalId);
|
||||||
int k = 0;
|
List<ProjectCaseParams> pcplist = GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
|
||||||
ProjectCase testcase = GetServerApi.cgetCaseBysign(testCaseExternalId);
|
// 把公共参数加入到MAP中
|
||||||
List<ProjectCaseParams> pcplist = GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
|
for (ProjectCaseParams pcp : pcplist) {
|
||||||
// 把公共参数加入到MAP中
|
variable.put(pcp.getParamsName(), pcp.getParamsValue());
|
||||||
for (ProjectCaseParams pcp : pcplist) {
|
}
|
||||||
variable.put(pcp.getParamsName(), pcp.getParamsValue());
|
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
||||||
}
|
if (steps.size() == 0) {
|
||||||
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
setcaseresult = 2;
|
||||||
if (steps.size() == 0) {
|
LogUtil.APP.warn("用例中未找到步骤,请检查!");
|
||||||
setcaseresult = 2;
|
testnote = "用例中未找到步骤,请检查!";
|
||||||
LogUtil.APP.warn("用例中未找到步骤,请检查!");
|
}
|
||||||
testnote = "用例中未找到步骤,请检查!";
|
// 进入循环,解析用例所有步骤
|
||||||
}
|
for (int i = 0; i < steps.size(); i++) {
|
||||||
// 进入循环,解析用例所有步骤
|
Map<String, String> casescript = InterfaceAnalyticCase.analyticCaseStep(testcase, steps.get(i), "888888",
|
||||||
for (int i = 0; i < steps.size(); i++) {
|
null,variable);
|
||||||
Map<String, String> casescript = InterfaceAnalyticCase.analyticCaseStep(testcase, steps.get(i), "888888",
|
try {
|
||||||
null,variable);
|
packagename = casescript.get("PackageName");
|
||||||
try {
|
functionname = casescript.get("FunctionName");
|
||||||
packagename = casescript.get("PackageName").toString();
|
} catch (Exception e) {
|
||||||
functionname = casescript.get("FunctionName").toString();
|
LogUtil.APP.error("用例:{} 解析包名或是方法名失败,请检查!",testcase.getCaseSign(),e);
|
||||||
} catch (Exception e) {
|
break; // 某一步骤失败后,此条用例置为失败退出
|
||||||
k = 0;
|
}
|
||||||
LogUtil.APP.error("用例:{} 解析包名或是方法名失败,请检查!",testcase.getCaseSign(),e);
|
// 用例名称解析出现异常或是单个步骤参数解析异常
|
||||||
break; // 某一步骤失败后,此条用例置为失败退出
|
if (functionname.contains("解析异常") || k == 1) {
|
||||||
}
|
testnote = "用例第" + (i + 1) + "步解析出错啦!";
|
||||||
// 用例名称解析出现异常或是单个步骤参数解析异常
|
break;
|
||||||
if (functionname.indexOf("解析异常") > -1 || k == 1) {
|
}
|
||||||
k = 0;
|
expectedresults = casescript.get("ExpectedResults");
|
||||||
testnote = "用例第" + (i + 1) + "步解析出错啦!";
|
// 判断方法是否带参数
|
||||||
break;
|
if (casescript.size() > 4) {
|
||||||
}
|
// 获取传入参数,放入对象中,初始化参数对象个数
|
||||||
expectedresults = casescript.get("ExpectedResults").toString();
|
getParameterValues = new Object[casescript.size() - 4];
|
||||||
// 判断方法是否带参数
|
for (int j = 0; j < casescript.size() - 4; j++) {
|
||||||
if (casescript.size() > 4) {
|
if (casescript.get("FunctionParams" + (j + 1)) == null) {
|
||||||
// 获取传入参数,放入对象中,初始化参数对象个数
|
k = 1;
|
||||||
getParameterValues = new Object[casescript.size() - 4];
|
break;
|
||||||
for (int j = 0; j < casescript.size() - 4; j++) {
|
}
|
||||||
if (casescript.get("FunctionParams" + (j + 1)) == null) {
|
String parameterValues = casescript.get("FunctionParams" + (j + 1));
|
||||||
k = 1;
|
LogUtil.APP.info("用例:{} 解析包名:{} 方法名:{} 第{}个参数:{}",testcase.getCaseSign(),packagename,functionname,(j+1),parameterValues);
|
||||||
break;
|
getParameterValues[j] = parameterValues;
|
||||||
}
|
}
|
||||||
String parameterValues = casescript.get("FunctionParams" + (j + 1));
|
} else {
|
||||||
LogUtil.APP.info("用例:{} 解析包名:{} 方法名:{} 第{}个参数:{}",testcase.getCaseSign(),packagename,functionname,(j+1),parameterValues);
|
getParameterValues = null;
|
||||||
getParameterValues[j] = parameterValues;
|
}
|
||||||
}
|
// 调用动态方法,执行测试用例
|
||||||
} else {
|
try {
|
||||||
getParameterValues = null;
|
LogUtil.APP.info("开始调用方法:{} .....",functionname);
|
||||||
}
|
testnote = InvokeMethod.callCase(packagename, functionname, getParameterValues,
|
||||||
// 调用动态方法,执行测试用例
|
steps.get(i).getStepType(), steps.get(i).getExtend());
|
||||||
try {
|
testnote = ActionManageForSteps.actionManage(casescript.get("Action"), testnote);
|
||||||
LogUtil.APP.info("开始调用方法:{} .....",functionname);
|
if (null != expectedresults && !expectedresults.isEmpty()) {
|
||||||
testnote = InvokeMethod.callCase(packagename, functionname, getParameterValues,
|
LogUtil.APP.info("expectedResults=【{}】",expectedresults);
|
||||||
steps.get(i).getStepType(), steps.get(i).getExtend());
|
// 赋值传参
|
||||||
testnote = ActionManageForSteps.actionManage(casescript.get("Action"), testnote);
|
if (expectedresults.length() > ASSIGNMENT_SIGN.length()
|
||||||
if (null != expectedresults && !expectedresults.isEmpty()) {
|
&& expectedresults.startsWith(ASSIGNMENT_SIGN)) {
|
||||||
LogUtil.APP.info("expectedResults=【{}】",expectedresults);
|
variable.put(expectedresults.substring(ASSIGNMENT_SIGN.length()), testnote);
|
||||||
// 赋值传参
|
LogUtil.APP
|
||||||
if (expectedresults.length() > ASSIGNMENT_SIGN.length()
|
.info("用例:{} 第{}步,将测试结果【{}】赋值给变量【{}】",testcase.getCaseSign(),(i+1),testnote,expectedresults.substring(ASSIGNMENT_SIGN.length()));
|
||||||
&& expectedresults.startsWith(ASSIGNMENT_SIGN)) {
|
}
|
||||||
variable.put(expectedresults.substring(ASSIGNMENT_SIGN.length()), testnote);
|
// 模糊匹配
|
||||||
LogUtil.APP
|
else if (expectedresults.length() > FUZZY_MATCHING_SIGN.length()
|
||||||
.info("用例:{} 第{}步,将测试结果【{}】赋值给变量【{}】",testcase.getCaseSign(),(i+1),testnote,expectedresults.substring(ASSIGNMENT_SIGN.length()));
|
&& expectedresults.startsWith(FUZZY_MATCHING_SIGN)) {
|
||||||
}
|
if (testnote.contains(expectedresults.substring(FUZZY_MATCHING_SIGN.length()))) {
|
||||||
// 模糊匹配
|
LogUtil.APP.info(
|
||||||
else if (expectedresults.length() > FUZZY_MATCHING_SIGN.length()
|
"用例:{} 第{}步,模糊匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),(i+1),testnote);
|
||||||
&& expectedresults.startsWith(FUZZY_MATCHING_SIGN)) {
|
} else {
|
||||||
if (testnote.contains(expectedresults.substring(FUZZY_MATCHING_SIGN.length()))) {
|
setcaseresult = 1;
|
||||||
LogUtil.APP.info(
|
LogUtil.APP.warn("用例:{} 第{}步,模糊匹配预期结果失败!预期结果{},测试结果:{}",testcase.getCaseSign(),(i+1),expectedresults.substring(FUZZY_MATCHING_SIGN.length()),testnote);
|
||||||
"用例:{} 第{}步,模糊匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),(i+1),testnote);
|
testnote = "用例第" + (i + 1) + "步,模糊匹配预期结果失败!";
|
||||||
} else {
|
if (testcase.getFailcontinue() == 0) {
|
||||||
setcaseresult = 1;
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,模糊匹配预期结果失败!预期结果{},测试结果:{}",testcase.getCaseSign(),(i+1),expectedresults.substring(FUZZY_MATCHING_SIGN.length()),testnote);
|
break;
|
||||||
testnote = "用例第" + (i + 1) + "步,模糊匹配预期结果失败!";
|
} else {
|
||||||
if (testcase.getFailcontinue() == 0) {
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
}
|
||||||
break;
|
}
|
||||||
} else {
|
}
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
// 正则匹配
|
||||||
}
|
else if (expectedresults.length() > REGULAR_MATCHING_SIGN.length()
|
||||||
}
|
&& expectedresults.startsWith(REGULAR_MATCHING_SIGN)) {
|
||||||
}
|
Pattern pattern = Pattern.compile(expectedresults.substring(REGULAR_MATCHING_SIGN.length()));
|
||||||
// 正则匹配
|
Matcher matcher = pattern.matcher(testnote);
|
||||||
else if (expectedresults.length() > REGULAR_MATCHING_SIGN.length()
|
if (matcher.find()) {
|
||||||
&& expectedresults.startsWith(REGULAR_MATCHING_SIGN)) {
|
LogUtil.APP.info(
|
||||||
Pattern pattern = Pattern.compile(expectedresults.substring(REGULAR_MATCHING_SIGN.length()));
|
"用例:{} 第{}步,正则匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),(i+1),testnote);
|
||||||
Matcher matcher = pattern.matcher(testnote);
|
} else {
|
||||||
if (matcher.find()) {
|
setcaseresult = 1;
|
||||||
LogUtil.APP.info(
|
LogUtil.APP.warn("用例:{} 第{}步,正则匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),(i+1),expectedresults.substring(REGULAR_MATCHING_SIGN.length()),testnote);
|
||||||
"用例:{} 第{}步,正则匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),(i+1),testnote);
|
testnote = "用例第" + (i + 1) + "步,正则匹配预期结果失败!";
|
||||||
} else {
|
if (testcase.getFailcontinue() == 0) {
|
||||||
setcaseresult = 1;
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,正则匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),(i+1),expectedresults.substring(REGULAR_MATCHING_SIGN.length()),testnote);
|
break;
|
||||||
testnote = "用例第" + (i + 1) + "步,正则匹配预期结果失败!";
|
} else {
|
||||||
if (testcase.getFailcontinue() == 0) {
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
}
|
||||||
break;
|
}
|
||||||
} else {
|
}
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
// 完全相等
|
||||||
}
|
else {
|
||||||
}
|
if (expectedresults.equals(testnote)) {
|
||||||
}
|
LogUtil.APP.info(
|
||||||
// 完全相等
|
"用例:{} 第{}步,精确匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),(i+1),testnote);
|
||||||
else {
|
} else {
|
||||||
if (expectedresults.equals(testnote)) {
|
setcaseresult = 1;
|
||||||
LogUtil.APP.info(
|
LogUtil.APP.warn("用例:{} 第{}步,精确匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),(i+1),expectedresults,testnote);
|
||||||
"用例:{} 第{}步,精确匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),(i+1),testnote);
|
testnote = "用例第" + (i + 1) + "步,精确匹配预期结果失败!";
|
||||||
} else {
|
if (testcase.getFailcontinue() == 0) {
|
||||||
setcaseresult = 1;
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,精确匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),(i+1),expectedresults,testnote);
|
break;
|
||||||
testnote = "用例第" + (i + 1) + "步,精确匹配预期结果失败!";
|
} else {
|
||||||
if (testcase.getFailcontinue() == 0) {
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
}
|
||||||
break;
|
}
|
||||||
} else {
|
}
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
}
|
setcaseresult = 1;
|
||||||
}
|
LogUtil.APP.error("调用方法过程出错,方法名:{} 请重新检查脚本方法名称以及参数!",functionname,e);
|
||||||
}
|
testnote = "CallCase调用出错!";
|
||||||
} catch (Exception e) {
|
if (testcase.getFailcontinue() == 0) {
|
||||||
setcaseresult = 1;
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
||||||
LogUtil.APP.error("调用方法过程出错,方法名:{} 请重新检查脚本方法名称以及参数!",functionname,e);
|
break;
|
||||||
testnote = "CallCase调用出错!";
|
} else {
|
||||||
if (testcase.getFailcontinue() == 0) {
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
}
|
||||||
break;
|
}
|
||||||
} else {
|
}
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
variable.clear(); // 清空传参MAP
|
||||||
}
|
// 如果调用方法过程中未出错,进入设置测试结果流程
|
||||||
}
|
if (!testnote.contains("CallCase调用出错!") && !testnote.contains("解析出错啦!")) {
|
||||||
}
|
LogUtil.APP.info("用例{}解析成功,并成功调用用例中方法,请继续查看执行结果!",testCaseExternalId);
|
||||||
variable.clear(); // 清空传参MAP
|
} else {
|
||||||
// 如果调用方法过程中未出错,进入设置测试结果流程
|
LogUtil.APP.warn("用例{}解析或是调用步骤中的方法出错!",testCaseExternalId);
|
||||||
if (testnote.indexOf("CallCase调用出错!") <= -1 && testnote.indexOf("解析出错啦!") <= -1) {
|
}
|
||||||
LogUtil.APP.info("用例{}解析成功,并成功调用用例中方法,请继续查看执行结果!",testCaseExternalId);
|
if (0 == setcaseresult) {
|
||||||
} else {
|
LogUtil.APP.info("用例{}步骤全部执行成功!",testCaseExternalId);
|
||||||
LogUtil.APP.warn("用例{}解析或是调用步骤中的方法出错!",testCaseExternalId);
|
} else {
|
||||||
}
|
LogUtil.APP.warn("用例{}在执行过程中失败,请检查日志!",testCaseExternalId);
|
||||||
if (0 == setcaseresult) {
|
}
|
||||||
LogUtil.APP.info("用例{}步骤全部执行成功!",testCaseExternalId);
|
}
|
||||||
} else {
|
|
||||||
LogUtil.APP.warn("用例{}在执行过程中失败,请检查日志!",testCaseExternalId);
|
/**
|
||||||
}
|
* 用于在本地做多条用例串行调试
|
||||||
}
|
* @param projectname 项目名称
|
||||||
|
* @param addtestcase 用例集
|
||||||
/**
|
*/
|
||||||
* 用于在本地做多条用例串行调试
|
public static void moreCaseDebug(String projectname, List<String> addtestcase) {
|
||||||
*
|
System.out.println("当前调试用例总共:"+addtestcase.size());
|
||||||
* @param projectname
|
for(String testCaseExternalId:addtestcase) {
|
||||||
* @param addtestcase
|
try {
|
||||||
*/
|
LogUtil.APP
|
||||||
public static void moreCaseDebug(String projectname, List<String> addtestcase) {
|
.info("开始调用方法,项目名:{},用例编号:{}",projectname,testCaseExternalId);
|
||||||
System.out.println("当前调试用例总共:"+addtestcase.size());
|
oneCaseDebug(testCaseExternalId);
|
||||||
for(String testCaseExternalId:addtestcase) {
|
} catch (Exception e) {
|
||||||
try {
|
LogUtil.APP.error("批量Debug用例出现异常!",e);
|
||||||
LogUtil.APP
|
}
|
||||||
.info("开始调用方法,项目名:{},用例编号:{}",projectname,testCaseExternalId);
|
}
|
||||||
oneCaseDebug(projectname, testCaseExternalId);
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
LogUtil.APP.error("批量Debug用例出现异常!",e);
|
/**
|
||||||
continue;
|
* 更新系统中用例指定步骤的预期结果
|
||||||
}
|
*/
|
||||||
}
|
public static String setExpectedResults(String testCaseSign, int steps, String expectedResults) {
|
||||||
}
|
String results;
|
||||||
|
String params;
|
||||||
/**
|
try {
|
||||||
* 更新系统中用例指定步骤的预期结果
|
expectedResults = expectedResults.replace("%", "BBFFHH");
|
||||||
*/
|
expectedResults = expectedResults.replace("=", "DHDHDH");
|
||||||
public static String setExpectedResults(String testCaseSign, int steps, String expectedResults) {
|
expectedResults = expectedResults.replace("&", "ANDAND");
|
||||||
String results = "设置结果失败";
|
params = "caseno=" + testCaseSign;
|
||||||
String params = "";
|
params += "&stepnum=" + steps;
|
||||||
try {
|
params += "&expectedresults=" + expectedResults;
|
||||||
expectedResults = expectedResults.replace("%", "BBFFHH");
|
results = HttpRequest.sendPost("/projectCasesteps/cUpdateStepExpectedResults.do", params);
|
||||||
expectedResults = expectedResults.replace("=", "DHDHDH");
|
} catch (Exception e) {
|
||||||
expectedResults = expectedResults.replace("&", "ANDAND");
|
LogUtil.APP.error("更新系统中用例指定步骤的预期结果出现异常!",e);
|
||||||
params = "caseno=" + testCaseSign;
|
return "更新系统中用例指定步骤的预期结果出现异常!";
|
||||||
params += "&stepnum=" + steps;
|
}
|
||||||
params += "&expectedresults=" + expectedResults;
|
return results;
|
||||||
results = HttpRequest.sendPost("/projectCasesteps/cUpdateStepExpectedResults.do", params);
|
|
||||||
} catch (Exception e) {
|
}
|
||||||
LogUtil.APP.error("更新系统中用例指定步骤的预期结果出现异常!",e);
|
|
||||||
return "更新系统中用例指定步骤的预期结果出现异常!";
|
}
|
||||||
}
|
|
||||||
return results;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -25,33 +25,32 @@ public class BatchTestCaseExecution {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建线程池,多线程执行用例
|
* 创建线程池,多线程执行用例
|
||||||
* @param projectname
|
* @param taskid 任务ID
|
||||||
* @param taskid
|
* @param batchcase 批量用例字符串,#隔断
|
||||||
* @param batchcase
|
* @throws Exception 抛异常
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static void batchCaseExecuteForTast(String projectname,String taskid,String batchcase) throws Exception{
|
public static void batchCaseExecuteForTast(String taskid, String batchcase) throws Exception{
|
||||||
int threadcount = GetServerApi.cGetTaskSchedulingByTaskId(Integer.valueOf(taskid)).getExThreadCount();
|
int threadcount = GetServerApi.cGetTaskSchedulingByTaskId(Integer.parseInt(taskid)).getExThreadCount();
|
||||||
ThreadPoolExecutor threadExecute = new ThreadPoolExecutor(threadcount, 30, 3, TimeUnit.SECONDS,
|
ThreadPoolExecutor threadExecute = new ThreadPoolExecutor(threadcount, 30, 3, TimeUnit.SECONDS,
|
||||||
new ArrayBlockingQueue<Runnable>(1000),
|
new ArrayBlockingQueue<>(1000),
|
||||||
new ThreadPoolExecutor.CallerRunsPolicy());
|
new ThreadPoolExecutor.CallerRunsPolicy());
|
||||||
//执行全部非成功状态用例
|
//执行全部非成功状态用例
|
||||||
if(batchcase.indexOf("ALLFAIL")>-1){
|
if(batchcase.contains("ALLFAIL")){
|
||||||
//初始化写用例结果以及日志模块
|
//初始化写用例结果以及日志模块
|
||||||
serverOperation caselog = new serverOperation();
|
serverOperation caselog = new serverOperation();
|
||||||
List<Integer> caseIdList = caselog.getCaseListForUnSucByTaskId(taskid);
|
List<Integer> caseIdList = caselog.getCaseListForUnSucByTaskId(taskid);
|
||||||
for(int i=0;i<caseIdList.size();i++){
|
for (Integer integer : caseIdList) {
|
||||||
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(caseIdList.get(i));
|
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(integer);
|
||||||
TestControl.THREAD_COUNT++; //多线程计数++,用于检测线程是否全部执行完
|
TestControl.THREAD_COUNT++; //多线程计数++,用于检测线程是否全部执行完
|
||||||
threadExecute.execute(new ThreadForBatchCase(projectname,testcase.getCaseId(),taskid));
|
threadExecute.execute(new ThreadForBatchCase(testcase.getCaseId(), taskid));
|
||||||
}
|
}
|
||||||
}else{ //批量执行用例
|
}else{ //批量执行用例
|
||||||
String[] temp=batchcase.split("\\#");
|
String[] temp=batchcase.split("#");
|
||||||
LogUtil.APP.info("当前批量执行任务中共有【{}】条待测试用例...",temp.length);
|
LogUtil.APP.info("当前批量执行任务中共有【{}】条待测试用例...",temp.length);
|
||||||
for(int i=0;i<temp.length;i++){
|
for (String s : temp) {
|
||||||
TestControl.THREAD_COUNT++; //多线程计数++,用于检测线程是否全部执行完
|
TestControl.THREAD_COUNT++; //多线程计数++,用于检测线程是否全部执行完
|
||||||
threadExecute.execute(new ThreadForBatchCase(projectname,Integer.valueOf(temp[i]),taskid));
|
threadExecute.execute(new ThreadForBatchCase(Integer.valueOf(s), taskid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//多线程计数,用于检测线程是否全部执行完
|
//多线程计数,用于检测线程是否全部执行完
|
||||||
|
|
|
@ -1,413 +1,401 @@
|
||||||
package luckyclient.execution.httpinterface;
|
package luckyclient.execution.httpinterface;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
|
|
||||||
import io.appium.java_client.android.AndroidDriver;
|
import io.appium.java_client.android.AndroidDriver;
|
||||||
import io.appium.java_client.android.AndroidElement;
|
import io.appium.java_client.android.AndroidElement;
|
||||||
import io.appium.java_client.ios.IOSDriver;
|
import io.appium.java_client.ios.IOSDriver;
|
||||||
import io.appium.java_client.ios.IOSElement;
|
import io.appium.java_client.ios.IOSElement;
|
||||||
import luckyclient.driven.SubString;
|
import luckyclient.driven.SubString;
|
||||||
import luckyclient.execution.appium.AppDriverAnalyticCase;
|
import luckyclient.execution.appium.AppDriverAnalyticCase;
|
||||||
import luckyclient.execution.appium.androidex.AndroidCaseExecution;
|
import luckyclient.execution.appium.androidex.AndroidCaseExecution;
|
||||||
import luckyclient.execution.appium.iosex.IosCaseExecution;
|
import luckyclient.execution.appium.iosex.IosCaseExecution;
|
||||||
import luckyclient.execution.dispose.ActionManageForSteps;
|
import luckyclient.execution.dispose.ActionManageForSteps;
|
||||||
import luckyclient.execution.dispose.ParamsManageForSteps;
|
import luckyclient.execution.dispose.ParamsManageForSteps;
|
||||||
import luckyclient.execution.httpinterface.analyticsteps.InterfaceAnalyticCase;
|
import luckyclient.execution.httpinterface.analyticsteps.InterfaceAnalyticCase;
|
||||||
import luckyclient.execution.webdriver.ex.WebCaseExecution;
|
import luckyclient.execution.webdriver.ex.WebCaseExecution;
|
||||||
import luckyclient.execution.webdriver.ex.WebDriverAnalyticCase;
|
import luckyclient.execution.webdriver.ex.WebDriverAnalyticCase;
|
||||||
import luckyclient.remote.api.GetServerApi;
|
import luckyclient.remote.api.GetServerApi;
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.ProjectCase;
|
||||||
import luckyclient.remote.entity.ProjectCaseParams;
|
import luckyclient.remote.entity.ProjectCaseParams;
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
import luckyclient.remote.entity.ProjectCaseSteps;
|
||||||
import luckyclient.utils.Constants;
|
import luckyclient.utils.Constants;
|
||||||
import luckyclient.utils.InvokeMethod;
|
import luckyclient.utils.InvokeMethod;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
||||||
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
* @date 2018年3月1日
|
* @date 2018年3月1日
|
||||||
*/
|
*/
|
||||||
public class TestCaseExecution {
|
public class TestCaseExecution {
|
||||||
private Map<String, String> VARIABLE = new HashMap<String, String>(0);
|
private Map<String, String> VARIABLE = new HashMap<>(0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param projectname 项目名
|
* 用于单条用例调试,并通过日志框架写日志到UTP上,用做UTP上单条用例运行
|
||||||
* @param testCaseExternalId 用例编号
|
*/
|
||||||
* @param version 用例版本号
|
public void oneCaseExecuteForTask(Integer caseId, String taskid) {
|
||||||
* 用于单条用例调试,并通过日志框架写日志到UTP上,用做UTP上单条用例运行
|
TestControl.TASKID = taskid;
|
||||||
*/
|
serverOperation.exetype = 0;
|
||||||
public void oneCaseExecuteForTask(String projectname, Integer caseId, String taskid) {
|
// 初始化写用例结果以及日志模块
|
||||||
TestControl.TASKID = taskid;
|
serverOperation caselog = new serverOperation();
|
||||||
serverOperation.exetype = 0;
|
String packagename;
|
||||||
// 初始化写用例结果以及日志模块
|
String functionname;
|
||||||
serverOperation caselog = new serverOperation();
|
String expectedresults;
|
||||||
String packagename = null;
|
int setcaseresult = 0;
|
||||||
String functionname = null;
|
Object[] getParameterValues;
|
||||||
String expectedresults = null;
|
String testnote = "初始化测试结果";
|
||||||
Integer setcaseresult = 0;
|
int k = 0;
|
||||||
Object[] getParameterValues = null;
|
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(caseId);
|
||||||
String testnote = "初始化测试结果";
|
//更新用例状态
|
||||||
int k = 0;
|
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), 3);
|
||||||
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(caseId);
|
// 删除旧的日志
|
||||||
//更新用例状态
|
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
||||||
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), 3);
|
|
||||||
// 删除旧的日志
|
List<ProjectCaseParams> pcplist = GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
|
||||||
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
// 把公共参数加入到MAP中
|
||||||
|
for (ProjectCaseParams pcp : pcplist) {
|
||||||
List<ProjectCaseParams> pcplist = GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
|
VARIABLE.put(pcp.getParamsName(), pcp.getParamsValue());
|
||||||
// 把公共参数加入到MAP中
|
}
|
||||||
for (ProjectCaseParams pcp : pcplist) {
|
// 加入全局变量
|
||||||
VARIABLE.put(pcp.getParamsName(), pcp.getParamsValue());
|
VARIABLE.putAll(ParamsManageForSteps.GLOBAL_VARIABLE);
|
||||||
}
|
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
||||||
// 加入全局变量
|
if (steps.size() == 0) {
|
||||||
VARIABLE.putAll(ParamsManageForSteps.GLOBAL_VARIABLE);
|
setcaseresult = 2;
|
||||||
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
LogUtil.APP.warn("用例中未找到步骤,请检查!");
|
||||||
if (steps.size() == 0) {
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例中未找到步骤,请检查!", "error", "1", "");
|
||||||
setcaseresult = 2;
|
testnote = "用例中未找到步骤,请检查!";
|
||||||
LogUtil.APP.warn("用例中未找到步骤,请检查!");
|
}
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例中未找到步骤,请检查!", "error", "1", "");
|
// 进入循环,解析用例所有步骤
|
||||||
testnote = "用例中未找到步骤,请检查!";
|
for (int i = 0; i < steps.size(); i++) {
|
||||||
}
|
Map<String, String> casescript = InterfaceAnalyticCase.analyticCaseStep(testcase, steps.get(i), taskid, caselog,VARIABLE);
|
||||||
// 进入循环,解析用例所有步骤
|
try {
|
||||||
for (int i = 0; i < steps.size(); i++) {
|
packagename = casescript.get("PackageName");
|
||||||
Map<String, String> casescript = InterfaceAnalyticCase.analyticCaseStep(testcase, steps.get(i), taskid, caselog,VARIABLE);
|
functionname = casescript.get("FunctionName");
|
||||||
try {
|
} catch (Exception e) {
|
||||||
packagename = casescript.get("PackageName");
|
LogUtil.APP.error("用例:{} 解析包名或是方法名失败,请检查!",testcase.getCaseSign(),e);
|
||||||
functionname = casescript.get("FunctionName");
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "解析包名或是方法名失败,请检查!", "error", String.valueOf(i + 1), "");
|
||||||
} catch (Exception e) {
|
break; // 某一步骤失败后,此条用例置为失败退出
|
||||||
k = 0;
|
}
|
||||||
LogUtil.APP.error("用例:{} 解析包名或是方法名失败,请检查!",testcase.getCaseSign(),e);
|
// 用例名称解析出现异常或是单个步骤参数解析异常
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "解析包名或是方法名失败,请检查!", "error", String.valueOf(i + 1), "");
|
if ((null != functionname && functionname.contains("解析异常")) || k == 1) {
|
||||||
break; // 某一步骤失败后,此条用例置为失败退出
|
testnote = "用例第" + (i + 1) + "步解析出错啦!";
|
||||||
}
|
break;
|
||||||
// 用例名称解析出现异常或是单个步骤参数解析异常
|
}
|
||||||
if ((null != functionname && functionname.contains("解析异常")) || k == 1) {
|
expectedresults = casescript.get("ExpectedResults");
|
||||||
k = 0;
|
// 判断方法是否带参数
|
||||||
testnote = "用例第" + (i + 1) + "步解析出错啦!";
|
if (casescript.size() > 4) {
|
||||||
break;
|
// 获取传入参数,放入对象中,初始化参数对象个数
|
||||||
}
|
getParameterValues = new Object[casescript.size() - 4];
|
||||||
expectedresults = casescript.get("ExpectedResults");
|
for (int j = 0; j < casescript.size() - 4; j++) {
|
||||||
// 判断方法是否带参数
|
if (casescript.get("FunctionParams" + (j + 1)) == null) {
|
||||||
if (casescript.size() > 4) {
|
k = 1;
|
||||||
// 获取传入参数,放入对象中,初始化参数对象个数
|
break;
|
||||||
getParameterValues = new Object[casescript.size() - 4];
|
}
|
||||||
for (int j = 0; j < casescript.size() - 4; j++) {
|
|
||||||
if (casescript.get("FunctionParams" + (j + 1)) == null) {
|
String parameterValues = casescript.get("FunctionParams" + (j + 1));
|
||||||
k = 1;
|
LogUtil.APP.info("用例:{} 解析包名:{} 方法名:{} 第{}个参数:{}",testcase.getCaseSign(),packagename,functionname,(j+1),parameterValues);
|
||||||
break;
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "解析包名:" + packagename + " 方法名:" + functionname + " 第" + (j + 1) + "个参数:" + parameterValues, "info", String.valueOf(i + 1), "");
|
||||||
}
|
getParameterValues[j] = parameterValues;
|
||||||
|
}
|
||||||
String parameterValues = casescript.get("FunctionParams" + (j + 1));
|
} else {
|
||||||
LogUtil.APP.info("用例:{} 解析包名:{} 方法名:{} 第{}个参数:{}",testcase.getCaseSign(),packagename,functionname,(j+1),parameterValues);
|
getParameterValues = null;
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "解析包名:" + packagename + " 方法名:" + functionname + " 第" + (j + 1) + "个参数:" + parameterValues, "info", String.valueOf(i + 1), "");
|
}
|
||||||
getParameterValues[j] = parameterValues;
|
// 调用动态方法,执行测试用例
|
||||||
}
|
try {
|
||||||
} else {
|
LogUtil.APP.info("开始调用方法:{} .....",functionname);
|
||||||
getParameterValues = null;
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "开始调用方法:" + functionname + " .....", "info", String.valueOf(i + 1), "");
|
||||||
}
|
testnote = InvokeMethod.callCase(packagename, functionname, getParameterValues, steps.get(i).getStepType(), steps.get(i).getExtend());
|
||||||
// 调用动态方法,执行测试用例
|
testnote = ActionManageForSteps.actionManage(casescript.get("Action"), testnote);
|
||||||
try {
|
// 判断结果
|
||||||
LogUtil.APP.info("开始调用方法:{} .....",functionname);
|
int stepresult = interfaceJudgeResult(testcase, steps.get(i), taskid, expectedresults, testnote, caselog);
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "开始调用方法:" + functionname + " .....", "info", String.valueOf(i + 1), "");
|
// 失败,并且不在继续,直接终止
|
||||||
testnote = InvokeMethod.callCase(packagename, functionname, getParameterValues, steps.get(i).getStepType(), steps.get(i).getExtend());
|
if (0 != stepresult) {
|
||||||
testnote = ActionManageForSteps.actionManage(casescript.get("Action"), testnote);
|
setcaseresult = stepresult;
|
||||||
// 判断结果
|
if (testcase.getFailcontinue() == 0) {
|
||||||
int stepresult = interfaceJudgeResult(testcase, steps.get(i), taskid, expectedresults, testnote, caselog);
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),steps.get(i).getStepSerialNumber());
|
||||||
// 失败,并且不在继续,直接终止
|
break;
|
||||||
if (0 != stepresult) {
|
} else {
|
||||||
setcaseresult = stepresult;
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),steps.get(i).getStepSerialNumber());
|
||||||
if (testcase.getFailcontinue() == 0) {
|
}
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),steps.get(i).getStepSerialNumber());
|
}
|
||||||
break;
|
|
||||||
} else {
|
} catch (Exception e) {
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),steps.get(i).getStepSerialNumber());
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!", "error", String.valueOf(i + 1), "");
|
||||||
}
|
LogUtil.APP.error("调用方法过程出错,方法名:{} 请重新检查脚本方法名称以及参数!",functionname, e);
|
||||||
}
|
testnote = "CallCase调用出错!";
|
||||||
|
setcaseresult = 1;
|
||||||
} catch (Exception e) {
|
e.printStackTrace();
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!", "error", String.valueOf(i + 1), "");
|
if (testcase.getFailcontinue() == 0) {
|
||||||
LogUtil.APP.error("调用方法过程出错,方法名:{} 请重新检查脚本方法名称以及参数!",functionname, e);
|
LogUtil.APP.error("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
||||||
testnote = "CallCase调用出错!";
|
break;
|
||||||
setcaseresult = 1;
|
} else {
|
||||||
e.printStackTrace();
|
LogUtil.APP.error("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
||||||
if (testcase.getFailcontinue() == 0) {
|
}
|
||||||
LogUtil.APP.error("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
}
|
||||||
break;
|
}
|
||||||
} else {
|
|
||||||
LogUtil.APP.error("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
VARIABLE.clear(); // 清空传参MAP
|
||||||
}
|
// 如果调用方法过程中未出错,进入设置测试结果流程
|
||||||
}
|
if (!testnote.contains("CallCase调用出错!") && !testnote.contains("解析出错啦!")) {
|
||||||
}
|
LogUtil.APP.info("用例{}解析成功,并成功调用用例中方法,请继续查看执行结果!",testcase.getCaseSign());
|
||||||
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "解析成功,并成功调用用例中方法,请继续查看执行结果!", "info", "SETCASERESULT...", "");
|
||||||
VARIABLE.clear(); // 清空传参MAP
|
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), setcaseresult);
|
||||||
// 如果调用方法过程中未出错,进入设置测试结果流程
|
} else {
|
||||||
if (!testnote.contains("CallCase调用出错!") && !testnote.contains("解析出错啦!")) {
|
setcaseresult = 1;
|
||||||
LogUtil.APP.info("用例{}解析成功,并成功调用用例中方法,请继续查看执行结果!",testcase.getCaseSign());
|
LogUtil.APP.warn("用例{}解析或是调用步骤中的方法出错!",testcase.getCaseSign());
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "解析成功,并成功调用用例中方法,请继续查看执行结果!", "info", "SETCASERESULT...", "");
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "解析或是调用步骤中的方法出错!", "error", "SETCASERESULT...", "");
|
||||||
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), setcaseresult);
|
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), 2);
|
||||||
} else {
|
}
|
||||||
setcaseresult = 1;
|
if (0 == setcaseresult) {
|
||||||
LogUtil.APP.warn("用例{}解析或是调用步骤中的方法出错!",testcase.getCaseSign());
|
LogUtil.APP.info("用例{}步骤全部执行成功!",testcase.getCaseSign());
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "解析或是调用步骤中的方法出错!", "error", "SETCASERESULT...", "");
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "步骤全部执行成功!", "info", "EXECUTECASESUC...", "");
|
||||||
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), 2);
|
} else {
|
||||||
}
|
LogUtil.APP.warn("用例{}在执行过程中失败,请检查日志!",testcase.getCaseSign());
|
||||||
if (0 == setcaseresult) {
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在执行过程中失败,请检查日志!", "error", "EXECUTECASESUC...", "");
|
||||||
LogUtil.APP.info("用例{}步骤全部执行成功!",testcase.getCaseSign());
|
}
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "步骤全部执行成功!", "info", "EXECUTECASESUC...", "");
|
serverOperation.updateTaskExecuteData(taskid, 0, 2);
|
||||||
} else {
|
}
|
||||||
LogUtil.APP.warn("用例{}在执行过程中失败,请检查日志!",testcase.getCaseSign());
|
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在执行过程中失败,请检查日志!", "error", "EXECUTECASESUC...", "");
|
/**
|
||||||
}
|
* 提供给Web用例中,runcase的时候使用
|
||||||
serverOperation.updateTaskExecuteData(taskid, 0, 2);
|
* @param testCaseExternalId 用例编号
|
||||||
}
|
* @param taskid 任务ID
|
||||||
|
* @param caselog 用例日志对象
|
||||||
/**
|
* @param driver UI驱动
|
||||||
*
|
* @return 返回执行结果
|
||||||
* @param testCaseExternalId
|
*/
|
||||||
* @param taskid
|
@SuppressWarnings("unchecked")
|
||||||
* @param caselog
|
public String oneCaseExecuteForUICase(String testCaseExternalId, String taskid, serverOperation caselog, Object driver) throws InterruptedException {
|
||||||
* @param driver
|
String expectedresults;
|
||||||
* @return
|
int setresult = 1;
|
||||||
* @throws InterruptedException
|
String testnote = "初始化测试结果";
|
||||||
* 提供给Web用例中,runcase的时候使用
|
ProjectCase testcase = GetServerApi.cgetCaseBysign(testCaseExternalId);
|
||||||
*/
|
List<ProjectCaseParams> pcplist = GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
|
||||||
@SuppressWarnings("unchecked")
|
// 把公共参数加入到MAP中
|
||||||
public String oneCaseExecuteForUICase(String testCaseExternalId, String taskid, serverOperation caselog, Object driver) throws InterruptedException {
|
for (ProjectCaseParams pcp : pcplist) {
|
||||||
String expectedresults = null;
|
VARIABLE.put(pcp.getParamsName(), pcp.getParamsValue());
|
||||||
Integer setresult = 1;
|
}
|
||||||
String testnote = "初始化测试结果";
|
// 加入全局变量
|
||||||
ProjectCase testcase = GetServerApi.cgetCaseBysign(testCaseExternalId);
|
VARIABLE.putAll(ParamsManageForSteps.GLOBAL_VARIABLE);
|
||||||
List<ProjectCaseParams> pcplist = GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
|
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
||||||
// 把公共参数加入到MAP中
|
if (steps.size() == 0) {
|
||||||
for (ProjectCaseParams pcp : pcplist) {
|
setresult = 2;
|
||||||
VARIABLE.put(pcp.getParamsName(), pcp.getParamsValue());
|
LogUtil.APP.warn("用例中未找到步骤,请检查!");
|
||||||
}
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例中未找到步骤,请检查!", "error", "1", "");
|
||||||
// 加入全局变量
|
testnote = "用例中未找到步骤,请检查!";
|
||||||
VARIABLE.putAll(ParamsManageForSteps.GLOBAL_VARIABLE);
|
}
|
||||||
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
|
||||||
if (steps.size() == 0) {
|
// 进入循环,解析用例所有步骤
|
||||||
setresult = 2;
|
for (ProjectCaseSteps step : steps) {
|
||||||
LogUtil.APP.warn("用例中未找到步骤,请检查!");
|
Map<String, String> params;
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例中未找到步骤,请检查!", "error", "1", "");
|
|
||||||
testnote = "用例中未找到步骤,请检查!";
|
// 根据步骤类型来分析步骤参数
|
||||||
}
|
if (1 == step.getStepType()){
|
||||||
|
params = WebDriverAnalyticCase.analyticCaseStep(testcase, step, taskid, caselog,VARIABLE);
|
||||||
// 进入循环,解析用例所有步骤
|
}else if (3 == step.getStepType()){
|
||||||
for (ProjectCaseSteps step : steps) {
|
params = AppDriverAnalyticCase.analyticCaseStep(testcase, step, taskid,caselog,VARIABLE);
|
||||||
Map<String, String> params;
|
} else{
|
||||||
|
params = InterfaceAnalyticCase.analyticCaseStep(testcase, step, taskid, caselog,VARIABLE);
|
||||||
// 根据步骤类型来分析步骤参数
|
}
|
||||||
if (1 == step.getStepType()){
|
|
||||||
params = WebDriverAnalyticCase.analyticCaseStep(testcase, step, taskid, caselog,VARIABLE);
|
// 判断分析步骤参数是否有异常
|
||||||
}else if (3 == step.getStepType()){
|
if (params.get("exception") != null && params.get("exception").contains("解析异常")) {
|
||||||
params = AppDriverAnalyticCase.analyticCaseStep(testcase, step, taskid,caselog,VARIABLE);
|
setresult = 2;
|
||||||
} else{
|
break;
|
||||||
params = InterfaceAnalyticCase.analyticCaseStep(testcase, step, taskid, caselog,VARIABLE);
|
}
|
||||||
}
|
|
||||||
|
expectedresults = params.get("ExpectedResults");
|
||||||
// 判断分析步骤参数是否有异常
|
|
||||||
if (params.get("exception") != null && params.get("exception").contains("解析异常")) {
|
// 根据步骤类型来执行步骤
|
||||||
setresult = 2;
|
if (1 == step.getStepType()){
|
||||||
break;
|
WebDriver wd=(WebDriver)driver;
|
||||||
}
|
testnote = WebCaseExecution.runWebStep(params, wd, taskid, testcase.getCaseId(), step.getStepSerialNumber(), caselog);
|
||||||
|
// 判断结果
|
||||||
expectedresults = params.get("ExpectedResults");
|
setresult = WebCaseExecution.judgeResult(testcase, step, params, wd, taskid, expectedresults, testnote, caselog);
|
||||||
|
}else if (3 == step.getStepType()){
|
||||||
// 根据步骤类型来执行步骤
|
if (driver instanceof AndroidDriver){
|
||||||
if (1 == step.getStepType()){
|
AndroidDriver<AndroidElement> ad=(AndroidDriver<AndroidElement>)driver;
|
||||||
WebDriver wd=(WebDriver)driver;
|
testnote = AndroidCaseExecution.androidRunStep(params, ad, taskid, testcase.getCaseId(), step.getStepSerialNumber(), caselog);
|
||||||
testnote = WebCaseExecution.runWebStep(params, wd, taskid, testcase.getCaseId(), step.getStepSerialNumber(), caselog);
|
// 判断结果
|
||||||
// 判断结果
|
setresult = AndroidCaseExecution.judgeResult(testcase, step, params, ad, taskid, expectedresults, testnote, caselog);
|
||||||
setresult = WebCaseExecution.judgeResult(testcase, step, params, wd, taskid, expectedresults, testnote, caselog);
|
}else{
|
||||||
}else if (3 == step.getStepType()){
|
IOSDriver<IOSElement> ios=(IOSDriver<IOSElement>)driver;
|
||||||
if (driver instanceof AndroidDriver){
|
testnote = IosCaseExecution.iosRunStep(params, VARIABLE, ios, taskid, testcase.getCaseId(), step.getStepSerialNumber(), caselog);
|
||||||
AndroidDriver<AndroidElement> ad=(AndroidDriver<AndroidElement>)driver;
|
// 判断结果
|
||||||
testnote = AndroidCaseExecution.androidRunStep(params, ad, taskid, testcase.getCaseId(), step.getStepSerialNumber(), caselog);
|
setresult = IosCaseExecution.judgeResult(testcase, step, params, ios, taskid, expectedresults, testnote, caselog);
|
||||||
// 判断结果
|
}
|
||||||
setresult = AndroidCaseExecution.judgeResult(testcase, step, params, ad, taskid, expectedresults, testnote, caselog);
|
|
||||||
}else{
|
} else{
|
||||||
IOSDriver<IOSElement> ios=(IOSDriver<IOSElement>)driver;
|
testnote = runStep(params, taskid, testcase.getCaseSign(), step, caselog);
|
||||||
testnote = IosCaseExecution.iosRunStep(params, VARIABLE, ios, taskid, testcase.getCaseId(), step.getStepSerialNumber(), caselog);
|
// 判断结果
|
||||||
// 判断结果
|
setresult = interfaceJudgeResult(testcase, step, taskid, expectedresults, testnote, caselog);
|
||||||
setresult = IosCaseExecution.judgeResult(testcase, step, params, ios, taskid, expectedresults, testnote, caselog);
|
}
|
||||||
}
|
|
||||||
|
if (0 != setresult){
|
||||||
} else{
|
testnote = "【调用用例:"+testcase.getCaseSign()+" 第"+step.getStepSerialNumber()+"步在执行过程中失败】";
|
||||||
testnote = runStep(params, taskid, testcase.getCaseSign(), step, caselog);
|
LogUtil.APP.warn("调用用例:{} 第{}步在执行过程中失败,请检查日志!{}",testcase.getCaseSign(),step.getStepSerialNumber(),testnote);
|
||||||
// 判断结果
|
break;
|
||||||
setresult = interfaceJudgeResult(testcase, step, taskid, expectedresults, testnote, caselog);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 != setresult){
|
VARIABLE.clear(); // 清空传参MAP
|
||||||
testnote = "【调用用例:"+testcase.getCaseSign()+" 第"+step.getStepSerialNumber()+"步在执行过程中失败】";
|
if (0 == setresult) {
|
||||||
LogUtil.APP.warn("调用用例:{} 第{}步在执行过程中失败,请检查日志!{}",testcase.getCaseSign(),step.getStepSerialNumber(),testnote);
|
LogUtil.APP.info("调用用例:{}步骤全部执行成功!",testcase.getCaseSign());
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
}
|
return testnote;
|
||||||
|
}
|
||||||
VARIABLE.clear(); // 清空传参MAP
|
|
||||||
if (0 == setresult) {
|
/**
|
||||||
LogUtil.APP.info("调用用例:{}步骤全部执行成功!",testcase.getCaseSign());
|
* 其他类型测试用例中调用接口测试步骤
|
||||||
}
|
* @param params 参数
|
||||||
|
* @param taskid 任务ID
|
||||||
return testnote;
|
* @param casenum 用例编号
|
||||||
}
|
* @param step 步骤对象
|
||||||
|
* @param caselog 日志对象
|
||||||
/**
|
* @return 返回执行结果
|
||||||
* 其他类型测试用例中调用接口测试步骤
|
*/
|
||||||
* @param params
|
public String runStep(Map<String, String> params, String taskid, String casenum, ProjectCaseSteps step, serverOperation caselog) {
|
||||||
* @param variable
|
String result;
|
||||||
* @param taskid
|
String packagename;
|
||||||
* @param casenum
|
String functionname = "";
|
||||||
* @param step
|
Object[] getParameterValues;
|
||||||
* @param caselog
|
ProjectCase projectCase = GetServerApi.cgetCaseBysign(casenum);
|
||||||
* @return
|
try {
|
||||||
*/
|
packagename = params.get("PackageName");
|
||||||
public String runStep(Map<String, String> params, String taskid, String casenum, ProjectCaseSteps step, serverOperation caselog) {
|
functionname = params.get("FunctionName");
|
||||||
String result = "";
|
|
||||||
String packagename = "";
|
if (null != functionname && functionname.contains("解析异常")) {
|
||||||
String functionname = "";
|
LogUtil.APP.warn("用例:{}, 解析这个方法【{}】失败!",casenum,functionname);
|
||||||
Object[] getParameterValues = null;
|
caselog.insertTaskCaseLog(taskid, projectCase.getCaseId(), "用例: " + casenum + ", 解析这个方法【" + functionname + "】失败!", "error", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
ProjectCase projectCase = GetServerApi.cgetCaseBysign(casenum);
|
result = "步骤执行失败:解析用例失败!";
|
||||||
try {
|
} else {
|
||||||
packagename = params.get("PackageName");
|
// 判断方法是否带参数
|
||||||
functionname = params.get("FunctionName");
|
if (params.size() > 4) {
|
||||||
|
// 获取传入参数,放入对象中
|
||||||
if (null != functionname && functionname.contains("解析异常")) {
|
getParameterValues = new Object[params.size() - 4];
|
||||||
LogUtil.APP.warn("用例:{}, 解析这个方法【{}】失败!",casenum,functionname);
|
for (int j = 0; j < params.size() - 4; j++) {
|
||||||
caselog.insertTaskCaseLog(taskid, projectCase.getCaseId(), "用例: " + casenum + ", 解析这个方法【" + functionname + "】失败!", "error", String.valueOf(step.getStepSerialNumber()), "");
|
if (params.get("FunctionParams" + (j + 1)) == null) {
|
||||||
result = "步骤执行失败:解析用例失败!";
|
break;
|
||||||
} else {
|
}
|
||||||
// 判断方法是否带参数
|
String parameterValues = params.get("FunctionParams" + (j + 1));
|
||||||
if (params.size() > 4) {
|
LogUtil.APP.info("用例:{}, 解析包路径:{}; 方法名:{} 第{}个参数:{}",casenum,packagename,functionname,(j+1),parameterValues);
|
||||||
// 获取传入参数,放入对象中
|
caselog.insertTaskCaseLog(taskid, projectCase.getCaseId(), "用例: " + casenum + ", 解析包名:" + packagename + " 方法名:" + functionname + " 第" + (j + 1) + "个参数:" + parameterValues, "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
getParameterValues = new Object[params.size() - 4];
|
getParameterValues[j] = parameterValues;
|
||||||
for (int j = 0; j < params.size() - 4; j++) {
|
}
|
||||||
if (params.get("FunctionParams" + (j + 1)) == null) {
|
} else {
|
||||||
break;
|
getParameterValues = null;
|
||||||
}
|
}
|
||||||
String parameterValues = params.get("FunctionParams" + (j + 1));
|
|
||||||
LogUtil.APP.info("用例:{}, 解析包路径:{}; 方法名:{} 第{}个参数:{}",casenum,packagename,functionname,(j+1),parameterValues);
|
LogUtil.APP.info("二次解析用例过程完成,等待进行接口操作......");
|
||||||
caselog.insertTaskCaseLog(taskid, projectCase.getCaseId(), "用例: " + casenum + ", 解析包名:" + packagename + " 方法名:" + functionname + " 第" + (j + 1) + "个参数:" + parameterValues, "info", String.valueOf(step.getStepSerialNumber()), "");
|
caselog.insertTaskCaseLog(taskid, projectCase.getCaseId(), "包路径: " + packagename + "; 方法名: " + functionname, "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
getParameterValues[j] = parameterValues;
|
|
||||||
}
|
result = InvokeMethod.callCase(packagename, functionname, getParameterValues, step.getStepType(), step.getExtend());
|
||||||
} else {
|
}
|
||||||
getParameterValues = null;
|
} catch (Exception e) {
|
||||||
}
|
LogUtil.APP.error("调用方法过程出错,方法名:{},请重新检查脚本方法名称以及参数!",functionname,e);
|
||||||
|
result = "步骤执行失败:接口调用出错!";
|
||||||
LogUtil.APP.info("二次解析用例过程完成,等待进行接口操作......");
|
}
|
||||||
caselog.insertTaskCaseLog(taskid, projectCase.getCaseId(), "包路径: " + packagename + "; 方法名: " + functionname, "info", String.valueOf(step.getStepSerialNumber()), "");
|
if (result.contains("步骤执行失败:")){
|
||||||
|
caselog.insertTaskCaseLog(taskid, projectCase.getCaseId(), result, "error", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
result = InvokeMethod.callCase(packagename, functionname, getParameterValues, step.getStepType(), step.getExtend());
|
} else{
|
||||||
}
|
caselog.insertTaskCaseLog(taskid, projectCase.getCaseId(), result, "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
} catch (Exception e) {
|
}
|
||||||
LogUtil.APP.error("调用方法过程出错,方法名:{},请重新检查脚本方法名称以及参数!",functionname,e);
|
return result;
|
||||||
result = "步骤执行失败:接口调用出错!";
|
}
|
||||||
}
|
|
||||||
if (result.contains("步骤执行失败:")){
|
private int interfaceJudgeResult(ProjectCase testcase, ProjectCaseSteps step, String taskid, String expectedresults, String testnote, serverOperation caselog){
|
||||||
caselog.insertTaskCaseLog(taskid, projectCase.getCaseId(), result, "error", String.valueOf(step.getStepSerialNumber()), "");
|
int setresult = 0;
|
||||||
} else{
|
try{
|
||||||
caselog.insertTaskCaseLog(taskid, projectCase.getCaseId(), result, "info", String.valueOf(step.getStepSerialNumber()), "");
|
if (null != expectedresults && !expectedresults.isEmpty()) {
|
||||||
}
|
LogUtil.APP.info("expectedResults=【{}】",expectedresults);
|
||||||
return result;
|
// 赋值传参
|
||||||
}
|
if (expectedresults.length() > Constants.ASSIGNMENT_SIGN.length() && expectedresults.startsWith(Constants.ASSIGNMENT_SIGN)) {
|
||||||
|
VARIABLE.put(expectedresults.substring(Constants.ASSIGNMENT_SIGN.length()), testnote);
|
||||||
private int interfaceJudgeResult(ProjectCase testcase, ProjectCaseSteps step, String taskid, String expectedresults, String testnote, serverOperation caselog){
|
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给变量【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),testnote,expectedresults.substring(Constants.ASSIGNMENT_SIGN.length()));
|
||||||
int setresult = 0;
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + testnote + "】赋值给变量【" + expectedresults.substring(Constants.ASSIGNMENT_SIGN.length()) + "】", "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
try{
|
}
|
||||||
if (null != expectedresults && !expectedresults.isEmpty()) {
|
// 赋值全局变量
|
||||||
LogUtil.APP.info("expectedResults=【{}】",expectedresults);
|
else if (expectedresults.length() > Constants.ASSIGNMENT_GLOBALSIGN.length() && expectedresults.startsWith(Constants.ASSIGNMENT_GLOBALSIGN)) {
|
||||||
// 赋值传参
|
VARIABLE.put(expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), testnote);
|
||||||
if (expectedresults.length() > Constants.ASSIGNMENT_SIGN.length() && expectedresults.startsWith(Constants.ASSIGNMENT_SIGN)) {
|
ParamsManageForSteps.GLOBAL_VARIABLE.put(expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), testnote);
|
||||||
VARIABLE.put(expectedresults.substring(Constants.ASSIGNMENT_SIGN.length()), testnote);
|
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给全局变量【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),testnote,expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()));
|
||||||
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给变量【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),testnote,expectedresults.substring(Constants.ASSIGNMENT_SIGN.length()));
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + testnote + "】赋值给全局变量【" + expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()) + "】", "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + testnote + "】赋值给变量【" + expectedresults.substring(Constants.ASSIGNMENT_SIGN.length()) + "】", "info", String.valueOf(step.getStepSerialNumber()), "");
|
}
|
||||||
}
|
// 模糊匹配
|
||||||
// 赋值全局变量
|
else if (expectedresults.length() > Constants.FUZZY_MATCHING_SIGN.length() && expectedresults.startsWith(Constants.FUZZY_MATCHING_SIGN)) {
|
||||||
else if (expectedresults.length() > Constants.ASSIGNMENT_GLOBALSIGN.length() && expectedresults.startsWith(Constants.ASSIGNMENT_GLOBALSIGN)) {
|
if (testnote.contains(expectedresults.substring(Constants.FUZZY_MATCHING_SIGN.length()))) {
|
||||||
VARIABLE.put(expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), testnote);
|
LogUtil.APP.info("用例:{} 第{}步,模糊匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),testnote);
|
||||||
ParamsManageForSteps.GLOBAL_VARIABLE.put(expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), testnote);
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给全局变量【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),testnote,expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()));
|
} else {
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + testnote + "】赋值给全局变量【" + expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()) + "】", "info", String.valueOf(step.getStepSerialNumber()), "");
|
setresult = 1;
|
||||||
}
|
LogUtil.APP.warn("用例:{} 第{}步,模糊匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expectedresults.substring(Constants.FUZZY_MATCHING_SIGN.length()),testnote);
|
||||||
// 模糊匹配
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果失败!预期结果:" + expectedresults.substring(Constants.FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + testnote, "error", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
else if (expectedresults.length() > Constants.FUZZY_MATCHING_SIGN.length() && expectedresults.startsWith(Constants.FUZZY_MATCHING_SIGN)) {
|
}
|
||||||
if (testnote.contains(expectedresults.substring(Constants.FUZZY_MATCHING_SIGN.length()))) {
|
}
|
||||||
LogUtil.APP.info("用例:{} 第{}步,模糊匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),testnote);
|
// 正则匹配
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(step.getStepSerialNumber()), "");
|
else if (expectedresults.length() > Constants.REGULAR_MATCHING_SIGN.length() && expectedresults.startsWith(Constants.REGULAR_MATCHING_SIGN)) {
|
||||||
} else {
|
Pattern pattern = Pattern.compile(expectedresults.substring(Constants.REGULAR_MATCHING_SIGN.length()));
|
||||||
setresult = 1;
|
Matcher matcher = pattern.matcher(testnote);
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,模糊匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expectedresults.substring(Constants.FUZZY_MATCHING_SIGN.length()),testnote);
|
if (matcher.find()) {
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果失败!预期结果:" + expectedresults.substring(Constants.FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + testnote, "error", String.valueOf(step.getStepSerialNumber()), "");
|
LogUtil.APP.info("用例:{} 第{}步,正则匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),testnote);
|
||||||
testnote = "用例第" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!";
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
}
|
} else {
|
||||||
}
|
setresult = 1;
|
||||||
// 正则匹配
|
LogUtil.APP.warn("用例:{} 第{}步,正则匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expectedresults.substring(Constants.REGULAR_MATCHING_SIGN.length()),testnote);
|
||||||
else if (expectedresults.length() > Constants.REGULAR_MATCHING_SIGN.length() && expectedresults.startsWith(Constants.REGULAR_MATCHING_SIGN)) {
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果失败!预期结果:" + expectedresults.substring(Constants.REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + testnote, "error", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
Pattern pattern = Pattern.compile(expectedresults.substring(Constants.REGULAR_MATCHING_SIGN.length()));
|
}
|
||||||
Matcher matcher = pattern.matcher(testnote);
|
}
|
||||||
if (matcher.find()) {
|
//jsonpath断言
|
||||||
LogUtil.APP.info("用例:{} 第{}步,正则匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),testnote);
|
else if (expectedresults.length() > Constants.JSONPATH_SIGN.length() && expectedresults.startsWith(Constants.JSONPATH_SIGN)) {
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(step.getStepSerialNumber()), "");
|
expectedresults = expectedresults.substring(Constants.JSONPATH_SIGN.length());
|
||||||
} else {
|
String expression = expectedresults.split("(?<!\\\\)=")[0].replace("\\=","=");
|
||||||
setresult = 1;
|
String exceptResult = expectedresults.split("(?<!\\\\)=")[1].replace("\\=","=");
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,正则匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expectedresults.substring(Constants.REGULAR_MATCHING_SIGN.length()),testnote);
|
//对测试结果进行jsonPath取值
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果失败!预期结果:" + expectedresults.substring(Constants.REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + testnote, "error", String.valueOf(step.getStepSerialNumber()), "");
|
String result = SubString.jsonPathGetParams(expression, testnote);
|
||||||
testnote = "用例第" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!";
|
|
||||||
}
|
if (exceptResult.equals(result)) {
|
||||||
}
|
setresult = 0;
|
||||||
//jsonpath断言
|
LogUtil.APP.info("用例:{} 第{}步,jsonpath断言预期结果成功!预期结果:{} 测试结果: {} 执行结果:true",testcase.getCaseSign(),step.getStepSerialNumber(),exceptResult,result);
|
||||||
else if (expectedresults.length() > Constants.JSONPATH_SIGN.length() && expectedresults.startsWith(Constants.JSONPATH_SIGN)) {
|
} else {
|
||||||
expectedresults = expectedresults.substring(Constants.JSONPATH_SIGN.length());
|
setresult = 1;
|
||||||
String expression = expectedresults.split("(?<!\\\\)=")[0].replace("\\=","=");
|
LogUtil.APP.warn("用例:{} 第{}步,jsonpath断言预期结果失败!预期结果:{},测试结果:{}" + expectedresults + ",测试结果:" + result, "error", step.getStepSerialNumber(), "");
|
||||||
String exceptResult = expectedresults.split("(?<!\\\\)=")[1].replace("\\=","=");
|
// 某一步骤失败后,此条用例置为失败退出
|
||||||
//对测试结果进行jsonPath取值
|
}
|
||||||
String result = SubString.jsonPathGetParams(expression, testnote);
|
|
||||||
|
}
|
||||||
if (exceptResult.equals(result)) {
|
// 完全相等
|
||||||
setresult = 0;
|
else {
|
||||||
LogUtil.APP.info("用例:{} 第{}步,jsonpath断言预期结果成功!预期结果:{} 测试结果: {} 执行结果:true",testcase.getCaseSign(),step.getStepSerialNumber(),exceptResult,result);
|
if (expectedresults.equals(testnote)) {
|
||||||
} else {
|
LogUtil.APP.info("用例:{} 第{}步,精确匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),testnote);
|
||||||
setresult = 1;
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,jsonpath断言预期结果失败!预期结果:{},测试结果:{}" + expectedresults + ",测试结果:" + result.toString(), "error", String.valueOf(step.getStepSerialNumber()), "");
|
} else {
|
||||||
testnote = "用例第" + step.getStepSerialNumber() + "步,jsonpath断言预期结果失败!";
|
setresult = 1;
|
||||||
// 某一步骤失败后,此条用例置为失败退出
|
LogUtil.APP.warn("用例:{} 第{}步,精确匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expectedresults,testnote);
|
||||||
}
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果失败!预期结果:" + expectedresults + ",测试结果:" + testnote, "error", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 完全相等
|
}
|
||||||
else {
|
}catch(Exception e){
|
||||||
if (expectedresults.equals(testnote)) {
|
LogUtil.APP.error("匹配接口预期结果出现异常!",e);
|
||||||
LogUtil.APP.info("用例:{} 第{}步,精确匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),testnote);
|
setresult = 2;
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(step.getStepSerialNumber()), "");
|
return setresult;
|
||||||
} else {
|
}
|
||||||
setresult = 1;
|
return setresult;
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,精确匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expectedresults,testnote);
|
}
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果失败!预期结果:" + expectedresults + ",测试结果:" + testnote, "error", String.valueOf(step.getStepSerialNumber()), "");
|
|
||||||
testnote = "用例第" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!";
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}catch(Exception e){
|
|
||||||
LogUtil.APP.error("匹配接口预期结果出现异常!",e);
|
|
||||||
setresult = 2;
|
|
||||||
return setresult;
|
|
||||||
}
|
|
||||||
return setresult;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -38,18 +38,17 @@ public class TestControl {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 控制台模式调度计划执行用例
|
* 控制台模式调度计划执行用例
|
||||||
* @param planname
|
* @param planname 计划名称
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public static void manualExecutionPlan(String planname) throws Exception {
|
public static void manualExecutionPlan(String planname) throws Exception {
|
||||||
serverOperation.exetype = 1;
|
serverOperation.exetype = 1;
|
||||||
int threadcount = 10;
|
int threadcount = 10;
|
||||||
// 创建线程池,多线程执行用例
|
// 创建线程池,多线程执行用例
|
||||||
ThreadPoolExecutor threadExecute = new ThreadPoolExecutor(threadcount, 20, 3, TimeUnit.SECONDS,
|
ThreadPoolExecutor threadExecute = new ThreadPoolExecutor(threadcount, 20, 3, TimeUnit.SECONDS,
|
||||||
new ArrayBlockingQueue<Runnable>(1000), new ThreadPoolExecutor.CallerRunsPolicy());
|
new ArrayBlockingQueue<>(1000), new ThreadPoolExecutor.CallerRunsPolicy());
|
||||||
|
|
||||||
List<ProjectCase> testCases = GetServerApi.getCasesbyplanname(planname);
|
List<ProjectCase> testCases = GetServerApi.getCasesbyplanname(planname);
|
||||||
List<ProjectCaseParams> pcplist = new ArrayList<ProjectCaseParams>();
|
List<ProjectCaseParams> pcplist = new ArrayList<>();
|
||||||
if (testCases.size() != 0) {
|
if (testCases.size() != 0) {
|
||||||
pcplist = GetServerApi.cgetParamsByProjectid(String.valueOf(testCases.get(0).getProjectId()));
|
pcplist = GetServerApi.cgetParamsByProjectid(String.valueOf(testCases.get(0).getProjectId()));
|
||||||
}
|
}
|
||||||
|
@ -82,8 +81,7 @@ public class TestControl {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计划任务模式调度计划执行用例
|
* 计划任务模式调度计划执行用例
|
||||||
* @param task
|
* @param task 任务对象
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public static void taskExecutionPlan(TaskExecute task) throws Exception {
|
public static void taskExecutionPlan(TaskExecute task) throws Exception {
|
||||||
serverOperation.exetype = 0;
|
serverOperation.exetype = 0;
|
||||||
|
@ -99,13 +97,13 @@ public class TestControl {
|
||||||
// 初始化写用例结果以及日志模块
|
// 初始化写用例结果以及日志模块
|
||||||
serverOperation caselog = new serverOperation();
|
serverOperation caselog = new serverOperation();
|
||||||
// 判断是否要自动重启TOMCAT
|
// 判断是否要自动重启TOMCAT
|
||||||
if (restartstatus.indexOf("Status:true") > -1) {
|
if (restartstatus.contains("Status:true")) {
|
||||||
// 判断是否构建是否成功
|
// 判断是否构建是否成功
|
||||||
if (BuildResult.SUCCESS.equals(buildResult)) {
|
if (BuildResult.SUCCESS.equals(buildResult)) {
|
||||||
int threadcount = taskScheduling.getExThreadCount();
|
int threadcount = taskScheduling.getExThreadCount();
|
||||||
// 创建线程池,多线程执行用例
|
// 创建线程池,多线程执行用例
|
||||||
ThreadPoolExecutor threadExecute = new ThreadPoolExecutor(threadcount, 20, 3, TimeUnit.SECONDS,
|
ThreadPoolExecutor threadExecute = new ThreadPoolExecutor(threadcount, 20, 3, TimeUnit.SECONDS,
|
||||||
new ArrayBlockingQueue<Runnable>(1000), new ThreadPoolExecutor.CallerRunsPolicy());
|
new ArrayBlockingQueue<>(1000), new ThreadPoolExecutor.CallerRunsPolicy());
|
||||||
|
|
||||||
List<ProjectCase> cases = GetServerApi.getCasesbyplanId(taskScheduling.getPlanId());
|
List<ProjectCase> cases = GetServerApi.getCasesbyplanId(taskScheduling.getPlanId());
|
||||||
LogUtil.APP.info("当前测试任务 {} 中共有【{}】条待测试用例...",task.getTaskName(),cases.size());
|
LogUtil.APP.info("当前测试任务 {} 中共有【{}】条待测试用例...",task.getTaskName(),cases.size());
|
||||||
|
|
|
@ -1,33 +1,31 @@
|
||||||
package luckyclient.execution.httpinterface;
|
package luckyclient.execution.httpinterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
||||||
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
* @date 2017年12月1日 上午9:29:40
|
* @date 2017年12月1日 上午9:29:40
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ThreadForBatchCase extends Thread{
|
public class ThreadForBatchCase extends Thread{
|
||||||
|
|
||||||
private String projectname;
|
private Integer caseId;
|
||||||
private Integer caseId;
|
private String taskid;
|
||||||
private String taskid;
|
|
||||||
|
public ThreadForBatchCase(Integer caseId,String taskid){
|
||||||
public ThreadForBatchCase(String projectname,Integer caseId,String taskid){
|
this.caseId = caseId;
|
||||||
this.projectname = projectname;
|
this.taskid = taskid;
|
||||||
this.caseId = caseId;
|
}
|
||||||
this.taskid = taskid;
|
|
||||||
}
|
@Override
|
||||||
|
public void run(){
|
||||||
@Override
|
TestCaseExecution testCaseExecution=new TestCaseExecution();
|
||||||
public void run(){
|
testCaseExecution.oneCaseExecuteForTask(caseId, taskid);
|
||||||
TestCaseExecution testCaseExecution=new TestCaseExecution();
|
TestControl.THREAD_COUNT--; //多线程计数--,用于检测线程是否全部执行完
|
||||||
testCaseExecution.oneCaseExecuteForTask(projectname, caseId, taskid);
|
}
|
||||||
TestControl.THREAD_COUNT--; //多线程计数--,用于检测线程是否全部执行完
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,263 +1,261 @@
|
||||||
package luckyclient.execution.httpinterface;
|
package luckyclient.execution.httpinterface;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import luckyclient.driven.SubString;
|
import luckyclient.driven.SubString;
|
||||||
import luckyclient.execution.dispose.ActionManageForSteps;
|
import luckyclient.execution.dispose.ActionManageForSteps;
|
||||||
import luckyclient.execution.dispose.ParamsManageForSteps;
|
import luckyclient.execution.dispose.ParamsManageForSteps;
|
||||||
import luckyclient.execution.httpinterface.analyticsteps.InterfaceAnalyticCase;
|
import luckyclient.execution.httpinterface.analyticsteps.InterfaceAnalyticCase;
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.ProjectCase;
|
||||||
import luckyclient.remote.entity.ProjectCaseParams;
|
import luckyclient.remote.entity.ProjectCaseParams;
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
import luckyclient.remote.entity.ProjectCaseSteps;
|
||||||
import luckyclient.utils.Constants;
|
import luckyclient.utils.Constants;
|
||||||
import luckyclient.utils.InvokeMethod;
|
import luckyclient.utils.InvokeMethod;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
||||||
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @ClassName: ThreadForExecuteCase
|
* @ClassName: ThreadForExecuteCase
|
||||||
* @Description: 线程池方式执行用例
|
* @Description: 线程池方式执行用例
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
* @date 2018年3月1日
|
* @date 2018年3月1日
|
||||||
*/
|
*/
|
||||||
public class ThreadForExecuteCase extends Thread {
|
public class ThreadForExecuteCase extends Thread {
|
||||||
private Integer caseId;
|
private Integer caseId;
|
||||||
private String caseSign;
|
private String caseSign;
|
||||||
private ProjectCase testcase;
|
private ProjectCase testcase;
|
||||||
private String taskid;
|
private String taskid;
|
||||||
private Integer projectId;
|
private Integer projectId;
|
||||||
private List<ProjectCaseSteps> steps;
|
private List<ProjectCaseSteps> steps;
|
||||||
private List<ProjectCaseParams> pcplist;
|
private List<ProjectCaseParams> pcplist;
|
||||||
private serverOperation caselog;
|
private serverOperation caselog;
|
||||||
|
|
||||||
public ThreadForExecuteCase(ProjectCase projectcase, List<ProjectCaseSteps> steps, String taskid, List<ProjectCaseParams> pcplist, serverOperation caselog) {
|
public ThreadForExecuteCase(ProjectCase projectcase, List<ProjectCaseSteps> steps, String taskid, List<ProjectCaseParams> pcplist, serverOperation caselog) {
|
||||||
this.caseId = projectcase.getCaseId();
|
this.caseId = projectcase.getCaseId();
|
||||||
this.testcase = projectcase;
|
this.testcase = projectcase;
|
||||||
this.projectId = projectcase.getProjectId();
|
this.projectId = projectcase.getProjectId();
|
||||||
this.caseSign = projectcase.getCaseSign();
|
this.caseSign = projectcase.getCaseSign();
|
||||||
this.taskid = taskid;
|
this.taskid = taskid;
|
||||||
this.steps = steps;
|
this.steps = steps;
|
||||||
this.pcplist = pcplist;
|
this.pcplist = pcplist;
|
||||||
this.caselog = caselog;
|
this.caselog = caselog;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Map<String, String> variable = new HashMap<>(0);
|
Map<String, String> variable = new HashMap<>(0);
|
||||||
// 把公共参数加入到MAP中
|
// 把公共参数加入到MAP中
|
||||||
for (ProjectCaseParams pcp : pcplist) {
|
for (ProjectCaseParams pcp : pcplist) {
|
||||||
variable.put(pcp.getParamsName(), pcp.getParamsValue());
|
variable.put(pcp.getParamsName(), pcp.getParamsValue());
|
||||||
}
|
}
|
||||||
// 加入全局变量
|
// 加入全局变量
|
||||||
variable.putAll(ParamsManageForSteps.GLOBAL_VARIABLE);
|
variable.putAll(ParamsManageForSteps.GLOBAL_VARIABLE);
|
||||||
String functionname = null;
|
String functionname;
|
||||||
String packagename = null;
|
String packagename;
|
||||||
String expectedresults = null;
|
String expectedresults;
|
||||||
Integer setcaseresult = 0;
|
int setcaseresult = 0;
|
||||||
Object[] getParameterValues = null;
|
Object[] getParameterValues;
|
||||||
String testnote = "初始化测试结果";
|
String testnote = "初始化测试结果";
|
||||||
int k = 0;
|
int k = 0;
|
||||||
// 进入循环,解析单个用例所有步骤
|
// 进入循环,解析单个用例所有步骤
|
||||||
// 插入开始执行的用例
|
// 插入开始执行的用例
|
||||||
caselog.insertTaskCaseExecute(taskid, projectId, caseId, caseSign, testcase.getCaseName(), 3);
|
caselog.insertTaskCaseExecute(taskid, projectId, caseId, caseSign, testcase.getCaseName(), 3);
|
||||||
for (int i = 0; i < steps.size(); i++) {
|
for (int i = 0; i < steps.size(); i++) {
|
||||||
// 解析单个步骤中的脚本
|
// 解析单个步骤中的脚本
|
||||||
Map<String, String> casescript = InterfaceAnalyticCase.analyticCaseStep(testcase, steps.get(i), taskid, caselog,variable);
|
Map<String, String> casescript = InterfaceAnalyticCase.analyticCaseStep(testcase, steps.get(i), taskid, caselog,variable);
|
||||||
try {
|
try {
|
||||||
packagename = casescript.get("PackageName");
|
packagename = casescript.get("PackageName");
|
||||||
functionname = casescript.get("FunctionName");
|
functionname = casescript.get("FunctionName");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
k = 0;
|
LogUtil.APP.error("用例:{} 解析包名或是方法名出现异常,请检查!",testcase.getCaseSign(),e);
|
||||||
LogUtil.APP.error("用例:{} 解析包名或是方法名出现异常,请检查!",testcase.getCaseSign(),e);
|
caselog.insertTaskCaseLog(taskid, caseId, "解析包名或是方法名失败,请检查!", "error", String.valueOf(i + 1), "");
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "解析包名或是方法名失败,请检查!", "error", String.valueOf(i + 1), "");
|
break; // 某一步骤失败后,此条用例置为失败退出
|
||||||
break; // 某一步骤失败后,此条用例置为失败退出
|
}
|
||||||
}
|
// 用例名称解析出现异常或是单个步骤参数解析异常
|
||||||
// 用例名称解析出现异常或是单个步骤参数解析异常
|
if ((null != functionname && functionname.contains("解析异常")) || k == 1) {
|
||||||
if ((null != functionname && functionname.contains("解析异常")) || k == 1) {
|
testnote = "用例第" + (i + 1) + "步解析出错啦!";
|
||||||
k = 0;
|
break;
|
||||||
testnote = "用例第" + (i + 1) + "步解析出错啦!";
|
}
|
||||||
break;
|
expectedresults = casescript.get("ExpectedResults");
|
||||||
}
|
// 判断方法是否带参数
|
||||||
expectedresults = casescript.get("ExpectedResults");
|
if (casescript.size() > 4) {
|
||||||
// 判断方法是否带参数
|
// 获取传入参数,放入对象中
|
||||||
if (casescript.size() > 4) {
|
getParameterValues = new Object[casescript.size() - 4];
|
||||||
// 获取传入参数,放入对象中
|
for (int j = 0; j < casescript.size() - 4; j++) {
|
||||||
getParameterValues = new Object[casescript.size() - 4];
|
if (casescript.get("FunctionParams" + (j + 1)) == null) {
|
||||||
for (int j = 0; j < casescript.size() - 4; j++) {
|
k = 1;
|
||||||
if (casescript.get("FunctionParams" + (j + 1)) == null) {
|
break;
|
||||||
k = 1;
|
}
|
||||||
break;
|
String parameterValues = casescript.get("FunctionParams" + (j + 1));
|
||||||
}
|
LogUtil.APP.info("用例:{} 解析包名:{} 方法名:{} 第{}个参数:{}",testcase.getCaseSign(),packagename,functionname,(j+1),parameterValues);
|
||||||
String parameterValues = casescript.get("FunctionParams" + (j + 1));
|
caselog.insertTaskCaseLog(taskid, caseId, "解析包名:" + packagename + " 方法名:" + functionname + " 第" + (j + 1) + "个参数:" + parameterValues, "info", String.valueOf(i + 1), "");
|
||||||
LogUtil.APP.info("用例:{} 解析包名:{} 方法名:{} 第{}个参数:{}",testcase.getCaseSign(),packagename,functionname,(j+1),parameterValues);
|
getParameterValues[j] = parameterValues;
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "解析包名:" + packagename + " 方法名:" + functionname + " 第" + (j + 1) + "个参数:" + parameterValues, "info", String.valueOf(i + 1), "");
|
}
|
||||||
getParameterValues[j] = parameterValues;
|
} else {
|
||||||
}
|
getParameterValues = null;
|
||||||
} else {
|
}
|
||||||
getParameterValues = null;
|
// 调用动态方法,执行测试用例
|
||||||
}
|
try {
|
||||||
// 调用动态方法,执行测试用例
|
LogUtil.APP.info("用例:{}开始调用方法:{} .....",testcase.getCaseSign(),functionname);
|
||||||
try {
|
caselog.insertTaskCaseLog(taskid, caseId, "开始调用方法:" + functionname + " .....", "info", String.valueOf(i + 1), "");
|
||||||
LogUtil.APP.info("用例:{}开始调用方法:{} .....",testcase.getCaseSign(),functionname);
|
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "开始调用方法:" + functionname + " .....", "info", String.valueOf(i + 1), "");
|
testnote = InvokeMethod.callCase(packagename, functionname, getParameterValues, steps.get(i).getStepType(), steps.get(i).getExtend());
|
||||||
|
testnote = ActionManageForSteps.actionManage(casescript.get("Action"), testnote);
|
||||||
testnote = InvokeMethod.callCase(packagename, functionname, getParameterValues, steps.get(i).getStepType(), steps.get(i).getExtend());
|
if (null != expectedresults && !expectedresults.isEmpty()) {
|
||||||
testnote = ActionManageForSteps.actionManage(casescript.get("Action"), testnote);
|
LogUtil.APP.info("expectedResults=【{}】",expectedresults);
|
||||||
if (null != expectedresults && !expectedresults.isEmpty()) {
|
// 赋值传参
|
||||||
LogUtil.APP.info("expectedResults=【{}】",expectedresults);
|
if (expectedresults.length() > Constants.ASSIGNMENT_SIGN.length() && expectedresults.startsWith(Constants.ASSIGNMENT_SIGN)) {
|
||||||
// 赋值传参
|
variable.put(expectedresults.substring(Constants.ASSIGNMENT_SIGN.length()), testnote);
|
||||||
if (expectedresults.length() > Constants.ASSIGNMENT_SIGN.length() && expectedresults.startsWith(Constants.ASSIGNMENT_SIGN)) {
|
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给变量【{}】",testcase.getCaseSign(),(i+1),testnote,expectedresults.substring(Constants.ASSIGNMENT_SIGN.length()));
|
||||||
variable.put(expectedresults.substring(Constants.ASSIGNMENT_SIGN.length()), testnote);
|
caselog.insertTaskCaseLog(taskid, caseId, "将测试结果【" + testnote + "】赋值给变量【" + expectedresults.substring(Constants.ASSIGNMENT_SIGN.length()) + "】", "info", String.valueOf(i + 1), "");
|
||||||
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给变量【{}】",testcase.getCaseSign(),(i+1),testnote,expectedresults.substring(Constants.ASSIGNMENT_SIGN.length()));
|
}
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "将测试结果【" + testnote + "】赋值给变量【" + expectedresults.substring(Constants.ASSIGNMENT_SIGN.length()) + "】", "info", String.valueOf(i + 1), "");
|
// 赋值全局变量
|
||||||
}
|
else if (expectedresults.length() > Constants.ASSIGNMENT_GLOBALSIGN.length() && expectedresults.startsWith(Constants.ASSIGNMENT_GLOBALSIGN)) {
|
||||||
// 赋值全局变量
|
variable.put(expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), testnote);
|
||||||
else if (expectedresults.length() > Constants.ASSIGNMENT_GLOBALSIGN.length() && expectedresults.startsWith(Constants.ASSIGNMENT_GLOBALSIGN)) {
|
ParamsManageForSteps.GLOBAL_VARIABLE.put(expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), testnote);
|
||||||
variable.put(expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), testnote);
|
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给全局变量【{}】",testcase.getCaseSign(),(i+1),testnote,expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()));
|
||||||
ParamsManageForSteps.GLOBAL_VARIABLE.put(expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), testnote);
|
caselog.insertTaskCaseLog(taskid, caseId, "将测试结果【" + testnote + "】赋值给全局变量【" + expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()) + "】", "info", String.valueOf(i + 1), "");
|
||||||
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给全局变量【{}】",testcase.getCaseSign(),(i+1),testnote,expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()));
|
}
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "将测试结果【" + testnote + "】赋值给全局变量【" + expectedresults.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()) + "】", "info", String.valueOf(i + 1), "");
|
// 模糊匹配
|
||||||
}
|
else if (expectedresults.length() > Constants.FUZZY_MATCHING_SIGN.length() && expectedresults.startsWith(Constants.FUZZY_MATCHING_SIGN)) {
|
||||||
// 模糊匹配
|
if (testnote.contains(expectedresults.substring(Constants.FUZZY_MATCHING_SIGN.length()))) {
|
||||||
else if (expectedresults.length() > Constants.FUZZY_MATCHING_SIGN.length() && expectedresults.startsWith(Constants.FUZZY_MATCHING_SIGN)) {
|
LogUtil.APP.info("用例:{} 第{}步,模糊匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),(i+1),testnote);
|
||||||
if (testnote.contains(expectedresults.substring(Constants.FUZZY_MATCHING_SIGN.length()))) {
|
caselog.insertTaskCaseLog(taskid, caseId, "模糊匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(i + 1), "");
|
||||||
LogUtil.APP.info("用例:{} 第{}步,模糊匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),(i+1),testnote);
|
} else {
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "模糊匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(i + 1), "");
|
setcaseresult = 1;
|
||||||
} else {
|
LogUtil.APP.warn("用例:{} 第{}步,模糊匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),(i+1),expectedresults.substring(Constants.FUZZY_MATCHING_SIGN.length()),testnote);
|
||||||
setcaseresult = 1;
|
caselog.insertTaskCaseLog(taskid, caseId, "第" + (i + 1) + "步,模糊匹配预期结果失败!预期结果:" + expectedresults.substring(Constants.FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + testnote, "error", String.valueOf(i + 1), "");
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,模糊匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),(i+1),expectedresults.substring(Constants.FUZZY_MATCHING_SIGN.length()),testnote);
|
testnote = "用例第" + (i + 1) + "步,模糊匹配预期结果失败!";
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "第" + (i + 1) + "步,模糊匹配预期结果失败!预期结果:" + expectedresults.substring(Constants.FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + testnote, "error", String.valueOf(i + 1), "");
|
if (testcase.getFailcontinue() == 0) {
|
||||||
testnote = "用例第" + (i + 1) + "步,模糊匹配预期结果失败!";
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
||||||
if (testcase.getFailcontinue() == 0) {
|
break;
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
} else {
|
||||||
break;
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
||||||
} else {
|
}
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
}
|
||||||
}
|
}
|
||||||
}
|
// 正则匹配
|
||||||
}
|
else if (expectedresults.length() > Constants.REGULAR_MATCHING_SIGN.length() && expectedresults.startsWith(Constants.REGULAR_MATCHING_SIGN)) {
|
||||||
// 正则匹配
|
Pattern pattern = Pattern.compile(expectedresults.substring(Constants.REGULAR_MATCHING_SIGN.length()));
|
||||||
else if (expectedresults.length() > Constants.REGULAR_MATCHING_SIGN.length() && expectedresults.startsWith(Constants.REGULAR_MATCHING_SIGN)) {
|
Matcher matcher = pattern.matcher(testnote);
|
||||||
Pattern pattern = Pattern.compile(expectedresults.substring(Constants.REGULAR_MATCHING_SIGN.length()));
|
if (matcher.find()) {
|
||||||
Matcher matcher = pattern.matcher(testnote);
|
LogUtil.APP.info("用例:{} 第{}步,正则匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),(i+1),testnote);
|
||||||
if (matcher.find()) {
|
caselog.insertTaskCaseLog(taskid, caseId, "正则匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(i + 1), "");
|
||||||
LogUtil.APP.info("用例:{} 第{}步,正则匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),(i+1),testnote);
|
} else {
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "正则匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(i + 1), "");
|
setcaseresult = 1;
|
||||||
} else {
|
LogUtil.APP.warn("用例:{} 第{}步,正则匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),(i+1),expectedresults.substring(Constants.REGULAR_MATCHING_SIGN.length()),testnote);
|
||||||
setcaseresult = 1;
|
caselog.insertTaskCaseLog(taskid, caseId, "第" + (i + 1) + "步,正则匹配预期结果失败!预期结果:" + expectedresults.substring(Constants.REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + testnote, "error", String.valueOf(i + 1), "");
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,正则匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),(i+1),expectedresults.substring(Constants.REGULAR_MATCHING_SIGN.length()),testnote);
|
testnote = "用例第" + (i + 1) + "步,正则匹配预期结果失败!";
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "第" + (i + 1) + "步,正则匹配预期结果失败!预期结果:" + expectedresults.substring(Constants.REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + testnote, "error", String.valueOf(i + 1), "");
|
if (testcase.getFailcontinue() == 0) {
|
||||||
testnote = "用例第" + (i + 1) + "步,正则匹配预期结果失败!";
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
||||||
if (testcase.getFailcontinue() == 0) {
|
break;
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
} else {
|
||||||
break;
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
||||||
} else {
|
}
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
}
|
||||||
}
|
}
|
||||||
}
|
//jsonpath断言
|
||||||
}
|
else if (expectedresults.length() > Constants.JSONPATH_SIGN.length() && expectedresults.startsWith(Constants.JSONPATH_SIGN)) {
|
||||||
//jsonpath断言
|
expectedresults = expectedresults.substring(Constants.JSONPATH_SIGN.length());
|
||||||
else if (expectedresults.length() > Constants.JSONPATH_SIGN.length() && expectedresults.startsWith(Constants.JSONPATH_SIGN)) {
|
String expression = expectedresults.split("(?<!\\\\)=")[0].replace("\\=","=");
|
||||||
expectedresults = expectedresults.substring(Constants.JSONPATH_SIGN.length());
|
String exceptResult = expectedresults.split("(?<!\\\\)=")[1].replace("\\=","=");
|
||||||
String expression = expectedresults.split("(?<!\\\\)=")[0].replace("\\=","=");
|
//对测试结果进行jsonPath取值
|
||||||
String exceptResult = expectedresults.split("(?<!\\\\)=")[1].replace("\\=","=");
|
String result = SubString.jsonPathGetParams(expression, testnote);
|
||||||
//对测试结果进行jsonPath取值
|
|
||||||
String result = SubString.jsonPathGetParams(expression, testnote);
|
if (exceptResult.equals(result)) {
|
||||||
|
setcaseresult = 0;
|
||||||
if (exceptResult.equals(result)) {
|
LogUtil.APP.info("用例【{}】 第【{}】步,jsonpath断言预期结果成功!预期结果:{} 测试结果: {} 执行结果:true",testcase.getCaseSign(),(i+1),exceptResult,result);
|
||||||
setcaseresult = 0;
|
caselog.insertTaskCaseLog(taskid, caseId, "jsonpath断言预期结果成功!预期结果:"+ expectedresults + "测试结果:" + result + "执行结果:true","info", String.valueOf(i + 1), "");
|
||||||
LogUtil.APP.info("用例【{}】 第【{}】步,jsonpath断言预期结果成功!预期结果:{} 测试结果: {} 执行结果:true",testcase.getCaseSign(),(i+1),exceptResult,result);
|
} else {
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "jsonpath断言预期结果成功!预期结果:"+ expectedresults + "测试结果:" + result + "执行结果:true","info", String.valueOf(i + 1), "");
|
setcaseresult = 1;
|
||||||
} else {
|
LogUtil.APP.warn("用例:{} 第{}步,jsonpath断言预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),(i+1),expectedresults,result);
|
||||||
setcaseresult = 1;
|
caselog.insertTaskCaseLog(taskid, caseId, "第" + (i + 1) + "步,正则匹配预期结果失败!预期结果:" + exceptResult + ",测试结果:" + result, "error", String.valueOf(i + 1), "");
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,jsonpath断言预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),(i+1),expectedresults,result);
|
testnote = "用例第" + (i + 1) + "步,jsonpath断言预期结果失败!";
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "第" + (i + 1) + "步,正则匹配预期结果失败!预期结果:" + exceptResult + ",测试结果:" + result, "error", String.valueOf(i + 1), "");
|
if (testcase.getFailcontinue() == 0) {
|
||||||
testnote = "用例第" + (i + 1) + "步,jsonpath断言预期结果失败!";
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
||||||
if (testcase.getFailcontinue() == 0) {
|
break;
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
} else {
|
||||||
break;
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
||||||
} else {
|
}
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
|
||||||
}
|
// 某一步骤失败后,此条用例置为失败退出
|
||||||
|
break;
|
||||||
// 某一步骤失败后,此条用例置为失败退出
|
}
|
||||||
break;
|
}
|
||||||
}
|
// 完全相等
|
||||||
}
|
else {
|
||||||
// 完全相等
|
if (expectedresults.equals(testnote)) {
|
||||||
else {
|
LogUtil.APP.info("用例:{} 第{}步,精确匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),(i+1),testnote);
|
||||||
if (expectedresults.equals(testnote)) {
|
caselog.insertTaskCaseLog(taskid, caseId, "精确匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(i + 1), "");
|
||||||
LogUtil.APP.info("用例:{} 第{}步,精确匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),(i+1),testnote);
|
} else {
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "精确匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(i + 1), "");
|
setcaseresult = 1;
|
||||||
} else {
|
LogUtil.APP.warn("用例:{} 第{}步,精确匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),(i+1),expectedresults,testnote);
|
||||||
setcaseresult = 1;
|
caselog.insertTaskCaseLog(taskid, caseId, "第" + (i + 1) + "步,精确匹配预期结果失败!预期结果:" + expectedresults + ",测试结果:" + testnote, "error", String.valueOf(i + 1), "");
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,精确匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),(i+1),expectedresults,testnote);
|
testnote = "用例第" + (i + 1) + "步,精确匹配预期结果失败!";
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "第" + (i + 1) + "步,精确匹配预期结果失败!预期结果:" + expectedresults + ",测试结果:" + testnote, "error", String.valueOf(i + 1), "");
|
if (testcase.getFailcontinue() == 0) {
|
||||||
testnote = "用例第" + (i + 1) + "步,精确匹配预期结果失败!";
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
||||||
if (testcase.getFailcontinue() == 0) {
|
break;
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
} else {
|
||||||
break;
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
||||||
} else {
|
}
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
}
|
LogUtil.APP.error("用例:{}调用方法过程出错,方法名:{} 请重新检查脚本方法名称以及参数!",testcase.getCaseSign(),functionname,e);
|
||||||
} catch (Exception e) {
|
caselog.insertTaskCaseLog(taskid, caseId, "调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!", "error", String.valueOf(i + 1), "");
|
||||||
LogUtil.APP.error("用例:{}调用方法过程出错,方法名:{} 请重新检查脚本方法名称以及参数!",testcase.getCaseSign(),functionname,e);
|
testnote = "CallCase调用出错!调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!";
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!", "error", String.valueOf(i + 1), "");
|
setcaseresult = 1;
|
||||||
testnote = "CallCase调用出错!调用方法过程出错,方法名:" + functionname + " 请重新检查脚本方法名称以及参数!";
|
if (testcase.getFailcontinue() == 0) {
|
||||||
setcaseresult = 1;
|
LogUtil.APP.error("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
||||||
if (testcase.getFailcontinue() == 0) {
|
break;
|
||||||
LogUtil.APP.error("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
} else {
|
||||||
break;
|
LogUtil.APP.error("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
||||||
} else {
|
}
|
||||||
LogUtil.APP.error("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
}
|
||||||
}
|
}
|
||||||
}
|
// 如果调用方法过程中未出错,进入设置测试结果流程
|
||||||
}
|
try {
|
||||||
// 如果调用方法过程中未出错,进入设置测试结果流程
|
// 成功跟失败的用例走此流程
|
||||||
try {
|
if (!testnote.contains("CallCase调用出错!") && !testnote.contains("解析出错啦!")) {
|
||||||
// 成功跟失败的用例走此流程
|
caselog.updateTaskCaseExecuteStatus(taskid, caseId, setcaseresult);
|
||||||
if (!testnote.contains("CallCase调用出错!") && !testnote.contains("解析出错啦!")) {
|
} else {
|
||||||
caselog.updateTaskCaseExecuteStatus(taskid, caseId, setcaseresult);
|
// 解析用例或是调用方法出错,全部把用例置为锁定
|
||||||
} else {
|
LogUtil.APP.warn("用例:{} 设置执行结果为锁定,请参考错误日志查找锁定用例的原因.....",testcase.getCaseSign());
|
||||||
// 解析用例或是调用方法出错,全部把用例置为锁定
|
caselog.insertTaskCaseLog(taskid, caseId, "设置执行结果为锁定,请参考错误日志查找锁定用例的原因.....","error", "SETCASERESULT...", "");
|
||||||
LogUtil.APP.warn("用例:{} 设置执行结果为锁定,请参考错误日志查找锁定用例的原因.....",testcase.getCaseSign());
|
setcaseresult = 2;
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "设置执行结果为锁定,请参考错误日志查找锁定用例的原因.....","error", "SETCASERESULT...", "");
|
caselog.updateTaskCaseExecuteStatus(taskid, caseId, setcaseresult);
|
||||||
setcaseresult = 2;
|
}
|
||||||
caselog.updateTaskCaseExecuteStatus(taskid, caseId, setcaseresult);
|
if (0 == setcaseresult) {
|
||||||
}
|
LogUtil.APP.info("用例:{}执行结果成功......",testcase.getCaseSign());
|
||||||
if (0 == setcaseresult) {
|
caselog.insertTaskCaseLog(taskid, caseId, "用例步骤执行全部成功......", "info", "ending", "");
|
||||||
LogUtil.APP.info("用例:{}执行结果成功......",testcase.getCaseSign());
|
LogUtil.APP.info("*********用例【{}】执行完成,测试结果:成功*********",testcase.getCaseSign());
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "用例步骤执行全部成功......", "info", "ending", "");
|
} else if (1 == setcaseresult) {
|
||||||
LogUtil.APP.info("*********用例【{}】执行完成,测试结果:成功*********",testcase.getCaseSign());
|
LogUtil.APP.warn("用例:{}执行结果失败......",testcase.getCaseSign());
|
||||||
} else if (1 == setcaseresult) {
|
caselog.insertTaskCaseLog(taskid, caseId, "用例执行结果失败......", "error", "ending", "");
|
||||||
LogUtil.APP.warn("用例:{}执行结果失败......",testcase.getCaseSign());
|
LogUtil.APP.warn("*********用例【{}】执行完成,测试结果:失败*********",testcase.getCaseSign());
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "用例执行结果失败......", "error", "ending", "");
|
} else {
|
||||||
LogUtil.APP.warn("*********用例【{}】执行完成,测试结果:失败*********",testcase.getCaseSign());
|
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "执行结果锁定......");
|
||||||
} else {
|
caselog.insertTaskCaseLog(taskid, caseId, "用例执行结果锁定......", "error", "ending", "");
|
||||||
LogUtil.APP.warn("用例:" + testcase.getCaseSign() + "执行结果锁定......");
|
LogUtil.APP.warn("*********用例【{}】执行完成,测试结果:锁定*********",testcase.getCaseSign());
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "用例执行结果锁定......", "error", "ending", "");
|
}
|
||||||
LogUtil.APP.warn("*********用例【{}】执行完成,测试结果:锁定*********",testcase.getCaseSign());
|
} catch (Exception e) {
|
||||||
}
|
LogUtil.APP.error("用例:{}设置执行结果过程出错......",testcase.getCaseSign(),e);
|
||||||
} catch (Exception e) {
|
caselog.insertTaskCaseLog(taskid, caseId, "设置执行结果过程出错......", "error", "ending", "");
|
||||||
LogUtil.APP.error("用例:{}设置执行结果过程出错......",testcase.getCaseSign(),e);
|
} finally {
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "设置执行结果过程出错......", "error", "ending", "");
|
variable.clear(); // 一条用例结束后,清空变量存储空间
|
||||||
} finally {
|
TestControl.THREAD_COUNT--; // 多线程计数--,用于检测线程是否全部执行完
|
||||||
variable.clear(); // 一条用例结束后,清空变量存储空间
|
}
|
||||||
TestControl.THREAD_COUNT--; // 多线程计数--,用于检测线程是否全部执行完
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -34,16 +34,16 @@ import luckyclient.utils.LogUtil;
|
||||||
public class WebTestCaseDebug {
|
public class WebTestCaseDebug {
|
||||||
/**
|
/**
|
||||||
* 用于在WEB页面上调试用例时提供的接口
|
* 用于在WEB页面上调试用例时提供的接口
|
||||||
* @param caseIdStr
|
* @param caseIdStr 用例ID
|
||||||
* @param userIdStr
|
* @param userIdStr 用户ID
|
||||||
*/
|
*/
|
||||||
public static void oneCaseDebug(String caseIdStr, String userIdStr) {
|
public static void oneCaseDebug(String caseIdStr, String userIdStr) {
|
||||||
Map<String, String> variable = new HashMap<>(0);
|
Map<String, String> variable = new HashMap<>(0);
|
||||||
String packagename = null;
|
String packagename;
|
||||||
String functionname = null;
|
String functionname;
|
||||||
String expectedresults = null;
|
String expectedresults;
|
||||||
Integer setcaseresult = 0;
|
int setcaseresult = 0;
|
||||||
Object[] getParameterValues = null;
|
Object[] getParameterValues;
|
||||||
String testnote = "初始化测试结果";
|
String testnote = "初始化测试结果";
|
||||||
int k = 0;
|
int k = 0;
|
||||||
Integer caseId = Integer.valueOf(caseIdStr);
|
Integer caseId = Integer.valueOf(caseIdStr);
|
||||||
|
@ -64,14 +64,12 @@ public class WebTestCaseDebug {
|
||||||
packagename = casescript.get("PackageName");
|
packagename = casescript.get("PackageName");
|
||||||
functionname = casescript.get("FunctionName");
|
functionname = casescript.get("FunctionName");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
k = 0;
|
|
||||||
LogUtil.APP.error("解析包名或是方法名出现异常!",e);
|
LogUtil.APP.error("解析包名或是方法名出现异常!",e);
|
||||||
PostServerApi.cPostDebugLog(userId, caseId, "ERROR", "解析包名或是方法名失败,请检查!",2);
|
PostServerApi.cPostDebugLog(userId, caseId, "ERROR", "解析包名或是方法名失败,请检查!",2);
|
||||||
break; //某一步骤失败后,此条用例置为失败退出
|
break; //某一步骤失败后,此条用例置为失败退出
|
||||||
}
|
}
|
||||||
//用例名称解析出现异常或是单个步骤参数解析异常
|
//用例名称解析出现异常或是单个步骤参数解析异常
|
||||||
if ((null != functionname && functionname.contains("解析异常")) || k == 1) {
|
if ((null != functionname && functionname.contains("解析异常")) || k == 1) {
|
||||||
k = 0;
|
|
||||||
testnote = "用例第" + (i + 1) + "步解析出错啦!";
|
testnote = "用例第" + (i + 1) + "步解析出错啦!";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -156,10 +154,10 @@ public class WebTestCaseDebug {
|
||||||
|
|
||||||
if (exceptResult.equals(result)) {
|
if (exceptResult.equals(result)) {
|
||||||
setcaseresult = 0;
|
setcaseresult = 0;
|
||||||
PostServerApi.cPostDebugLog(userId, caseId, "INFO", "jsonpath断言预期结果成功!预期结果:" + exceptResult + " 测试结果: " + result.toString() + "校验结果: true", 0);
|
PostServerApi.cPostDebugLog(userId, caseId, "INFO", "jsonpath断言预期结果成功!预期结果:" + exceptResult + " 测试结果: " + result + "校验结果: true", 0);
|
||||||
} else {
|
} else {
|
||||||
setcaseresult = 1;
|
setcaseresult = 1;
|
||||||
PostServerApi.cPostDebugLog(userId, caseId, "ERROR", "第" + (i + 1) + "步,jsonpath断言预期结果失败!预期结果:" + exceptResult + ",测试结果:" + result.toString(),0);
|
PostServerApi.cPostDebugLog(userId, caseId, "ERROR", "第" + (i + 1) + "步,jsonpath断言预期结果失败!预期结果:" + exceptResult + ",测试结果:" + result,0);
|
||||||
testnote = "用例第" + (i + 1) + "步,jsonpath断言预期结果失败!";
|
testnote = "用例第" + (i + 1) + "步,jsonpath断言预期结果失败!";
|
||||||
if (testcase.getFailcontinue() == 0) {
|
if (testcase.getFailcontinue() == 0) {
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
||||||
|
@ -211,7 +209,4 @@ public class WebTestCaseDebug {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,186 +1,187 @@
|
||||||
package luckyclient.execution.httpinterface.analyticsteps;
|
package luckyclient.execution.httpinterface.analyticsteps;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import luckyclient.execution.dispose.ChangString;
|
import luckyclient.execution.dispose.ChangString;
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.ProjectCase;
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
import luckyclient.remote.entity.ProjectCaseSteps;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
||||||
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* @ClassName: AnalyticCase
|
* @ClassName: AnalyticCase
|
||||||
* @Description: 解析单个用例中描述部分的脚本
|
* @Description: 解析单个用例中描述部分的脚本
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
* @date 2017年7月14日 上午9:29:40
|
* @date 2017年7月14日 上午9:29:40
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class InterfaceAnalyticCase{
|
public class InterfaceAnalyticCase{
|
||||||
/**
|
/**
|
||||||
* 解析用例步骤
|
* 解析用例步骤
|
||||||
* @param projectcase
|
* @param projectcase 待解析用例对象
|
||||||
* @param step
|
* @param step 用例步骤对象
|
||||||
* @param taskid
|
* @param taskid 任务ID
|
||||||
* @param caselog
|
* @param caselog 日志对象
|
||||||
* @return
|
* @return 返回解析的用例MAP
|
||||||
*/
|
*/
|
||||||
public static Map<String,String> analyticCaseStep(ProjectCase projectcase,ProjectCaseSteps step,String taskid,serverOperation caselog, Map<String, String> variable){
|
public static Map<String,String> analyticCaseStep(ProjectCase projectcase,ProjectCaseSteps step,String taskid,serverOperation caselog, Map<String, String> variable){
|
||||||
Map<String,String> params = new HashMap<String,String>(0);
|
Map<String,String> params = new HashMap<>(0);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String resultstr = step.getExpectedResult();
|
String resultstr = step.getExpectedResult();
|
||||||
params.put("Action", step.getAction());
|
params.put("Action", step.getAction());
|
||||||
// 处理值传递
|
// 处理值传递
|
||||||
String packageName = ChangString.changparams(step.getStepPath().trim(), variable, "包路径");
|
String packageName = ChangString.changparams(step.getStepPath().trim(), variable, "包路径");
|
||||||
params.put("PackageName", packageName);
|
params.put("PackageName", packageName);
|
||||||
// 处理值传递
|
// 处理值传递
|
||||||
String functionName = ChangString.changparams(step.getStepOperation().trim(), variable, "方法名");
|
String functionName = ChangString.changparams(step.getStepOperation().trim(), variable, "方法名");
|
||||||
params.put("FunctionName", functionName);
|
params.put("FunctionName", functionName);
|
||||||
String stepParams = replaceSpi(step.getStepParameters(),0);
|
String stepParams = replaceSpi(step.getStepParameters(),0);
|
||||||
String[] temp=stepParams.split("\\|",-1);
|
String[] temp=stepParams.split("\\|",-1);
|
||||||
for(int i=0;i<temp.length;i++){
|
for(int i=0;i<temp.length;i++){
|
||||||
if("".equals(temp[i])){
|
if("".equals(temp[i])){
|
||||||
continue;
|
continue;
|
||||||
}if(" ".equals(temp[i])){
|
}if(" ".equals(temp[i])){
|
||||||
//带一个空格的时候,传入空字符串
|
//带一个空格的时候,传入空字符串
|
||||||
params.put("FunctionParams"+(i+1), "");
|
params.put("FunctionParams"+(i+1), "");
|
||||||
}else{
|
}else{
|
||||||
//set第N个传入参数
|
//set第N个传入参数
|
||||||
String parameterValues = ChangString.changparams(replaceSpi(temp[i],1), variable, "用例参数");
|
String parameterValues = ChangString.changparams(replaceSpi(temp[i],1), variable, "用例参数");
|
||||||
params.put("FunctionParams"+(i+1), parameterValues);
|
params.put("FunctionParams"+(i+1), parameterValues);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//set预期结果
|
//set预期结果
|
||||||
if(null==resultstr||"".equals(resultstr)){
|
if(null==resultstr||"".equals(resultstr)){
|
||||||
params.put("ExpectedResults", "");
|
params.put("ExpectedResults", "");
|
||||||
}else{
|
}else{
|
||||||
String expectedResults = ChangString.changparams(subComment(resultstr), variable, "预期结果");
|
String expectedResults = ChangString.changparams(subComment(resultstr), variable, "预期结果");
|
||||||
params.put("ExpectedResults", expectedResults);
|
params.put("ExpectedResults", expectedResults);
|
||||||
}
|
}
|
||||||
LogUtil.APP.info("用例编号:{} 步骤编号:{} 解析自动化用例步骤脚本完成!",projectcase.getCaseSign(),step.getStepSerialNumber());
|
LogUtil.APP.info("用例编号:{} 步骤编号:{} 解析自动化用例步骤脚本完成!",projectcase.getCaseSign(),step.getStepSerialNumber());
|
||||||
if(null!=caselog){
|
if(null!=caselog){
|
||||||
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),"步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本完成!","info",String.valueOf(step.getStepSerialNumber()),"");
|
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),"步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本完成!","info",String.valueOf(step.getStepSerialNumber()),"");
|
||||||
}
|
}
|
||||||
}catch(Exception e) {
|
}catch(Exception e) {
|
||||||
if(null!=caselog){
|
if(null!=caselog){
|
||||||
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),"步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本出错!","error",String.valueOf(step.getStepSerialNumber()),"");
|
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),"步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本出错!","error",String.valueOf(step.getStepSerialNumber()),"");
|
||||||
}
|
}
|
||||||
LogUtil.APP.error("用例编号:{} 步骤编号:{} 解析自动化用例步骤脚本出错!",projectcase.getCaseSign(),step.getStepSerialNumber(),e);
|
LogUtil.APP.error("用例编号:{} 步骤编号:{} 解析自动化用例步骤脚本出错!",projectcase.getCaseSign(),step.getStepSerialNumber(),e);
|
||||||
params.put("exception","用例编号:"+projectcase.getCaseSign()+"|解析异常,用例步骤为空或是用例脚本错误!");
|
params.put("exception","用例编号:"+projectcase.getCaseSign()+"|解析异常,用例步骤为空或是用例脚本错误!");
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
return params;
|
return params;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String subComment(String htmlStr) throws InterruptedException{
|
public static String subComment(String htmlStr) {
|
||||||
// 定义script的正则表达式
|
// 定义script的正则表达式
|
||||||
String regExscript = "<script[^>]*?>[\\s\\S]*?<\\/script>";
|
String regExscript = "<script[^>]*?>[\\s\\S]*?</script>";
|
||||||
// 定义style的正则表达式
|
// 定义style的正则表达式
|
||||||
String regExstyle = "<style[^>]*?>[\\s\\S]*?<\\/style>";
|
String regExstyle = "<style[^>]*?>[\\s\\S]*?</style>";
|
||||||
// 定义HTML标签的正则表达式
|
// 定义HTML标签的正则表达式
|
||||||
String regExhtml = "<[^>]+>";
|
String regExhtml = "<[^>]+>";
|
||||||
//定义空格回车换行符
|
//定义空格回车换行符
|
||||||
String regExspace = "\t|\r|\n";
|
String regExspace = "[\t\r\n]";
|
||||||
|
|
||||||
String scriptstr = null;
|
String scriptstr;
|
||||||
if (htmlStr!=null) {
|
if (htmlStr!=null) {
|
||||||
Pattern pScript = Pattern.compile(regExscript, Pattern.CASE_INSENSITIVE);
|
Pattern pScript = Pattern.compile(regExscript, Pattern.CASE_INSENSITIVE);
|
||||||
Matcher mScript = pScript.matcher(htmlStr);
|
Matcher mScript = pScript.matcher(htmlStr);
|
||||||
// 过滤script标签
|
// 过滤script标签
|
||||||
htmlStr = mScript.replaceAll("");
|
htmlStr = mScript.replaceAll("");
|
||||||
|
|
||||||
Pattern pStyle = Pattern.compile(regExstyle, Pattern.CASE_INSENSITIVE);
|
Pattern pStyle = Pattern.compile(regExstyle, Pattern.CASE_INSENSITIVE);
|
||||||
Matcher mStyle = pStyle.matcher(htmlStr);
|
Matcher mStyle = pStyle.matcher(htmlStr);
|
||||||
// 过滤style标签
|
// 过滤style标签
|
||||||
htmlStr = mStyle.replaceAll("");
|
htmlStr = mStyle.replaceAll("");
|
||||||
|
|
||||||
Pattern pHtml = Pattern.compile(regExhtml, Pattern.CASE_INSENSITIVE);
|
Pattern pHtml = Pattern.compile(regExhtml, Pattern.CASE_INSENSITIVE);
|
||||||
Matcher mHtml = pHtml.matcher(htmlStr);
|
Matcher mHtml = pHtml.matcher(htmlStr);
|
||||||
// 过滤html标签
|
// 过滤html标签
|
||||||
htmlStr = mHtml.replaceAll("");
|
htmlStr = mHtml.replaceAll("");
|
||||||
|
|
||||||
Pattern pSpace = Pattern.compile(regExspace, Pattern.CASE_INSENSITIVE);
|
Pattern pSpace = Pattern.compile(regExspace, Pattern.CASE_INSENSITIVE);
|
||||||
Matcher mSpace = pSpace.matcher(htmlStr);
|
Matcher mSpace = pSpace.matcher(htmlStr);
|
||||||
// 过滤空格回车标签
|
// 过滤空格回车标签
|
||||||
htmlStr = mSpace.replaceAll("");
|
htmlStr = mSpace.replaceAll("");
|
||||||
|
|
||||||
}
|
}
|
||||||
if(htmlStr.indexOf("/*")>-1&&htmlStr.indexOf("*/")>-1){
|
assert htmlStr != null;
|
||||||
String commentstr = htmlStr.substring(htmlStr.trim().indexOf("/*"),htmlStr.indexOf("*/")+2);
|
if(htmlStr.contains("/*") && htmlStr.contains("*/")){
|
||||||
//去注释
|
String commentstr = htmlStr.substring(htmlStr.trim().indexOf("/*"),htmlStr.indexOf("*/")+2);
|
||||||
scriptstr = htmlStr.replace(commentstr, "");
|
//去注释
|
||||||
}else{
|
scriptstr = htmlStr.replace(commentstr, "");
|
||||||
scriptstr = htmlStr;
|
}else{
|
||||||
}
|
scriptstr = htmlStr;
|
||||||
//去掉字符串前后的空格
|
}
|
||||||
scriptstr = trimInnerSpaceStr(scriptstr);
|
//去掉字符串前后的空格
|
||||||
//替换空格转义
|
scriptstr = trimInnerSpaceStr(scriptstr);
|
||||||
scriptstr = scriptstr.replaceAll(" ", " ");
|
//替换空格转义
|
||||||
//转义双引号
|
scriptstr = scriptstr.replaceAll(" ", " ");
|
||||||
scriptstr = scriptstr.replaceAll(""", "\"");
|
//转义双引号
|
||||||
//转义单引号
|
scriptstr = scriptstr.replaceAll(""", "\"");
|
||||||
scriptstr = scriptstr.replaceAll("'", "\'");
|
//转义单引号
|
||||||
//转义链接符
|
scriptstr = scriptstr.replaceAll("'", "'");
|
||||||
scriptstr = scriptstr.replaceAll("&", "&");
|
//转义链接符
|
||||||
scriptstr = scriptstr.replaceAll("<", "<");
|
scriptstr = scriptstr.replaceAll("&", "&");
|
||||||
scriptstr = scriptstr.replaceAll(">", ">");
|
scriptstr = scriptstr.replaceAll("<", "<");
|
||||||
|
scriptstr = scriptstr.replaceAll(">", ">");
|
||||||
return scriptstr;
|
|
||||||
}
|
return scriptstr;
|
||||||
|
}
|
||||||
/***
|
|
||||||
* 去掉字符串前后的空格,中间的空格保留
|
/***
|
||||||
* @param str
|
* 去掉字符串前后的空格,中间的空格保留
|
||||||
* @return
|
* @param str 待处理字符串
|
||||||
*/
|
* @return 返回去掉空格后的结果
|
||||||
public static String trimInnerSpaceStr(String str){
|
*/
|
||||||
str = str.trim();
|
public static String trimInnerSpaceStr(String str){
|
||||||
while(str.startsWith(" ")){
|
str = str.trim();
|
||||||
str = str.substring(1,str.length()).trim();
|
while(str.startsWith(" ")){
|
||||||
}
|
str = str.substring(1).trim();
|
||||||
while(str.startsWith(" ")){
|
}
|
||||||
str = str.substring(6,str.length()).trim();
|
while(str.startsWith(" ")){
|
||||||
}
|
str = str.substring(6).trim();
|
||||||
while(str.endsWith(" ")){
|
}
|
||||||
str = str.substring(0,str.length()-1).trim();
|
while(str.endsWith(" ")){
|
||||||
}
|
str = str.substring(0,str.length()-1).trim();
|
||||||
while(str.endsWith(" ")){
|
}
|
||||||
str = str.substring(0,str.length()-6).trim();
|
while(str.endsWith(" ")){
|
||||||
}
|
str = str.substring(0,str.length()-6).trim();
|
||||||
return str;
|
}
|
||||||
}
|
return str;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* 当遇到参数中带了|字符串时,在界面\\|进行转义
|
/**
|
||||||
* @param str
|
* 当遇到参数中带了|字符串时,在界面\\|进行转义
|
||||||
* @param flag
|
* @param str 待处理字符串
|
||||||
* @return
|
* @param flag 处理标识
|
||||||
*/
|
* @return 返回处理后结果
|
||||||
private static String replaceSpi(String str,int flag){
|
*/
|
||||||
String replacestr="¦_rep;";
|
private static String replaceSpi(String str,int flag){
|
||||||
if(null==str){
|
String replacestr="¦_rep;";
|
||||||
str = "";
|
if(null==str){
|
||||||
}
|
str = "";
|
||||||
String result=str;
|
}
|
||||||
if(str.contains("\\\\|")&&flag==0){
|
String result=str;
|
||||||
result=str.replace("\\\\|", replacestr);
|
if(str.contains("\\\\|")&&flag==0){
|
||||||
}
|
result=str.replace("\\\\|", replacestr);
|
||||||
if(str.contains(replacestr)&&flag==1){
|
}
|
||||||
result=str.replace(replacestr,"|");
|
if(str.contains(replacestr)&&flag==1){
|
||||||
}
|
result=str.replace(replacestr,"|");
|
||||||
return result;
|
}
|
||||||
}
|
return result;
|
||||||
|
}
|
||||||
public static void main(String[] args){
|
|
||||||
// TODO Auto-generated method stub
|
public static void main(String[] args){
|
||||||
|
// TODO Auto-generated method stub
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -31,12 +31,10 @@ public class BaseWebDrive {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 进测试结果进行截图
|
* 进测试结果进行截图
|
||||||
* @param driver
|
* @param driver 驱动
|
||||||
* @param imgname
|
* @param imgname 图片名称
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static Boolean webScreenShot(WebDriver driver,String imgname) {
|
public static void webScreenShot(WebDriver driver, String imgname) {
|
||||||
Boolean result = false;
|
|
||||||
String relativelyPath = System.getProperty("user.dir");
|
String relativelyPath = System.getProperty("user.dir");
|
||||||
String pngpath=relativelyPath +File.separator+ "log"+File.separator+"ScreenShot" +File.separator+ imgname + ".png";
|
String pngpath=relativelyPath +File.separator+ "log"+File.separator+"ScreenShot" +File.separator+ imgname + ".png";
|
||||||
|
|
||||||
|
@ -51,19 +49,18 @@ public class BaseWebDrive {
|
||||||
scrFile.deleteOnExit();
|
scrFile.deleteOnExit();
|
||||||
LogUtil.APP
|
LogUtil.APP
|
||||||
.info("已对当前界面进行截图操作,可通过用例执行界面的日志明细查看,也可以前往客户端上查看...【{}】",pngpath);
|
.info("已对当前界面进行截图操作,可通过用例执行界面的日志明细查看,也可以前往客户端上查看...【{}】",pngpath);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在自动化过程中加入点击显示效果
|
* 在自动化过程中加入点击显示效果
|
||||||
* @param driver
|
* @param driver 驱动
|
||||||
* @param element
|
* @param element 定位元素
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年9月6日
|
* @date 2019年9月6日
|
||||||
*/
|
*/
|
||||||
public static void highLightElement(WebDriver driver, WebElement element){
|
public static void highLightElement(WebDriver driver, WebElement element){
|
||||||
Properties properties = SysConfig.getConfiguration();
|
Properties properties = SysConfig.getConfiguration();
|
||||||
Boolean highLight = BooleanUtil.toBoolean(properties.getProperty("webdriver.highlight"));
|
boolean highLight = BooleanUtil.toBoolean(properties.getProperty("webdriver.highlight"));
|
||||||
|
|
||||||
if(highLight){
|
if(highLight){
|
||||||
JavascriptExecutor js = (JavascriptExecutor) driver;
|
JavascriptExecutor js = (JavascriptExecutor) driver;
|
||||||
|
|
|
@ -1,73 +1,73 @@
|
||||||
package luckyclient.execution.webdriver;
|
package luckyclient.execution.webdriver;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
|
|
||||||
import luckyclient.execution.webdriver.ex.WebCaseExecution;
|
import luckyclient.execution.webdriver.ex.WebCaseExecution;
|
||||||
import luckyclient.remote.api.GetServerApi;
|
import luckyclient.remote.api.GetServerApi;
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.ProjectCase;
|
||||||
import luckyclient.remote.entity.ProjectCaseParams;
|
import luckyclient.remote.entity.ProjectCaseParams;
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
import luckyclient.remote.entity.ProjectCaseSteps;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
||||||
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
* @date 2017年12月1日 上午9:29:40
|
* @date 2017年12月1日 上午9:29:40
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class CaseLocalDebug{
|
public class CaseLocalDebug{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单个用例Web UI调试
|
* 单个用例Web UI调试
|
||||||
* @param wd
|
* @param wd 驱动
|
||||||
* @param testCaseExternalId
|
* @param testCaseExternalId 用例编号
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2020年1月20日
|
* @date 2020年1月20日
|
||||||
*/
|
*/
|
||||||
public static void oneCasedebug(WebDriver wd,String testCaseExternalId){
|
public static void oneCasedebug(WebDriver wd,String testCaseExternalId){
|
||||||
//不记录日志到数据库
|
//不记录日志到数据库
|
||||||
serverOperation.exetype = 1;
|
serverOperation.exetype = 1;
|
||||||
serverOperation caselog = new serverOperation();
|
serverOperation caselog = new serverOperation();
|
||||||
try {
|
try {
|
||||||
ProjectCase testcase = GetServerApi.cgetCaseBysign(testCaseExternalId);
|
ProjectCase testcase = GetServerApi.cgetCaseBysign(testCaseExternalId);
|
||||||
List<ProjectCaseParams> pcplist=GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
|
List<ProjectCaseParams> pcplist=GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
|
||||||
LogUtil.APP.info("开始执行用例:【{}】......",testCaseExternalId);
|
LogUtil.APP.info("开始执行用例:【{}】......",testCaseExternalId);
|
||||||
List<ProjectCaseSteps> steps=GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
List<ProjectCaseSteps> steps=GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
||||||
WebCaseExecution.caseExcution(testcase,steps, "888888",wd,caselog,pcplist);
|
WebCaseExecution.caseExcution(testcase,steps, "888888",wd,caselog,pcplist);
|
||||||
LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
|
LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
||||||
}
|
}
|
||||||
//关闭浏览器
|
//关闭浏览器
|
||||||
wd.quit();
|
wd.quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 多个用例串行Web UI调试
|
* 多个用例串行Web UI调试
|
||||||
* @param wd
|
* @param wd 驱动
|
||||||
* @param projectname
|
* @param projectname 项目名称
|
||||||
* @param addtestcase
|
* @param addtestcase 用例集
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2020年1月20日
|
* @date 2020年1月20日
|
||||||
*/
|
*/
|
||||||
public static void moreCaseDebug(WebDriver wd,String projectname,List<String> addtestcase){
|
public static void moreCaseDebug(WebDriver wd,String projectname,List<String> addtestcase){
|
||||||
System.out.println("当前调试用例总共:"+addtestcase.size());
|
System.out.println("当前调试用例总共:"+addtestcase.size());
|
||||||
for(String testCaseExternalId:addtestcase) {
|
for(String testCaseExternalId:addtestcase) {
|
||||||
try{
|
try{
|
||||||
LogUtil.APP.info("开始调用方法,项目名:{},用例编号:{}",projectname,testCaseExternalId);
|
LogUtil.APP.info("开始调用方法,项目名:{},用例编号:{}",projectname,testCaseExternalId);
|
||||||
oneCasedebug(wd,testCaseExternalId);
|
oneCasedebug(wd,testCaseExternalId);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
continue;
|
LogUtil.APP.error("用例运行出现异常,用例编号:{}",testCaseExternalId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,21 +0,0 @@
|
||||||
package luckyclient.execution.webdriver;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* =================================================================
|
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
|
||||||
* =================================================================
|
|
||||||
* @author Seagull
|
|
||||||
* @date 2019年8月8日
|
|
||||||
*/
|
|
||||||
public class TestGoogle {
|
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException, IOException {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,132 +1,134 @@
|
||||||
package luckyclient.execution.webdriver;
|
package luckyclient.execution.webdriver;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
import org.openqa.selenium.WebDriverException;
|
import org.openqa.selenium.WebDriverException;
|
||||||
import org.openqa.selenium.chrome.ChromeDriver;
|
import org.openqa.selenium.chrome.ChromeDriver;
|
||||||
import org.openqa.selenium.chrome.ChromeOptions;
|
import org.openqa.selenium.chrome.ChromeOptions;
|
||||||
import org.openqa.selenium.edge.EdgeDriver;
|
import org.openqa.selenium.edge.EdgeDriver;
|
||||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||||
import org.openqa.selenium.firefox.FirefoxOptions;
|
import org.openqa.selenium.firefox.FirefoxOptions;
|
||||||
import org.openqa.selenium.ie.InternetExplorerDriver;
|
import org.openqa.selenium.ie.InternetExplorerDriver;
|
||||||
|
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
||||||
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
* @date 2017年12月1日 上午9:29:40
|
* @date 2017年12月1日 上午9:29:40
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class WebDriverInitialization{
|
public class WebDriverInitialization{
|
||||||
private static final String OS=System.getProperty("os.name").toLowerCase();
|
private static final String OS=System.getProperty("os.name").toLowerCase();
|
||||||
/**
|
/**
|
||||||
* 初始化WebDriver
|
* 初始化WebDriver
|
||||||
* @param drivertype
|
* @param drivertype 浏览器类型
|
||||||
* @return
|
* @return 返回初始化结果
|
||||||
* @throws WebDriverException
|
* @throws WebDriverException 驱动抛出异常
|
||||||
* @throws IOException
|
* @throws IOException 读取配置文件异常
|
||||||
*/
|
*/
|
||||||
public static WebDriver setWebDriverForTask(int drivertype) throws WebDriverException,IOException{
|
public static WebDriver setWebDriverForTask(int drivertype) throws WebDriverException,IOException{
|
||||||
// 参数为空
|
// 参数为空
|
||||||
File directory = new File("");
|
File directory = new File("");
|
||||||
String drivenpath=directory.getCanonicalPath()+File.separator+"BrowserDriven"+File.separator;
|
String drivenpath=directory.getCanonicalPath()+File.separator+"BrowserDriven"+File.separator;
|
||||||
WebDriver webDriver = null;
|
WebDriver webDriver = null;
|
||||||
LogUtil.APP.info("准备初始化WebDriver对象...检查到当前操作系统是:{}",OS);
|
LogUtil.APP.info("准备初始化WebDriver对象...检查到当前操作系统是:{}",OS);
|
||||||
if(drivertype==0){
|
if(drivertype==0){
|
||||||
if(OS.startsWith("win")){
|
if(OS.startsWith("win")){
|
||||||
System.setProperty("webdriver.ie.driver",drivenpath+"IEDriverServer.exe");
|
System.setProperty("webdriver.ie.driver",drivenpath+"IEDriverServer.exe");
|
||||||
webDriver = new InternetExplorerDriver();
|
webDriver = new InternetExplorerDriver();
|
||||||
}else{
|
}else{
|
||||||
LogUtil.APP.warn("当前操作系统无法进行IE浏览器的Web UI测试,请选择火狐或是谷歌浏览器!");
|
LogUtil.APP.warn("当前操作系统无法进行IE浏览器的Web UI测试,请选择火狐或是谷歌浏览器!");
|
||||||
}
|
}
|
||||||
}else if(drivertype==1){
|
}else if(drivertype==1){
|
||||||
FirefoxOptions options = new FirefoxOptions();
|
FirefoxOptions options = new FirefoxOptions();
|
||||||
if(OS.startsWith("win")){
|
if(OS.startsWith("win")){
|
||||||
System.setProperty("webdriver.gecko.driver",drivenpath+"geckodriver.exe");
|
System.setProperty("webdriver.gecko.driver",drivenpath+"geckodriver.exe");
|
||||||
}else if(OS.contains("mac")){
|
}else if(OS.contains("mac")){
|
||||||
options.addArguments("start-maximized");
|
options.addArguments("start-maximized");
|
||||||
System.setProperty("webdriver.gecko.driver",drivenpath+"geckodriver_mac");
|
System.setProperty("webdriver.gecko.driver",drivenpath+"geckodriver_mac");
|
||||||
}else{
|
}else{
|
||||||
LogUtil.APP.info("检测到当前系统环境是Linux,默认使用headless方式运行Firefox浏览器的Web UI自动化...");
|
LogUtil.APP.info("检测到当前系统环境是Linux,默认使用headless方式运行Firefox浏览器的Web UI自动化...");
|
||||||
//无界面参数
|
//无界面参数
|
||||||
options.setHeadless(true);
|
options.setHeadless(true);
|
||||||
//禁用沙盒
|
//禁用沙盒
|
||||||
options.addArguments("no-sandbox");
|
options.addArguments("no-sandbox");
|
||||||
options.addArguments("start-maximized");
|
options.addArguments("start-maximized");
|
||||||
System.setProperty("webdriver.gecko.driver",drivenpath+"geckodriver_linux64");
|
System.setProperty("webdriver.gecko.driver",drivenpath+"geckodriver_linux64");
|
||||||
}
|
}
|
||||||
webDriver = new FirefoxDriver(options);
|
webDriver = new FirefoxDriver(options);
|
||||||
}else if(drivertype==2){
|
}else if(drivertype==2){
|
||||||
ChromeOptions options = new ChromeOptions();
|
ChromeOptions options = new ChromeOptions();
|
||||||
if(OS.startsWith("win")){
|
if(OS.startsWith("win")){
|
||||||
System.setProperty("webdriver.chrome.driver",drivenpath+"chromedriver.exe");
|
System.setProperty("webdriver.chrome.driver",drivenpath+"chromedriver.exe");
|
||||||
}else if(OS.contains("mac")){
|
}else if(OS.contains("mac")){
|
||||||
options.addArguments("start-maximized");
|
options.addArguments("start-maximized");
|
||||||
System.setProperty("webdriver.chrome.driver",drivenpath+"chromedriver_mac");
|
System.setProperty("webdriver.chrome.driver",drivenpath+"chromedriver_mac");
|
||||||
}else{
|
}else{
|
||||||
LogUtil.APP.info("检测到当前系统环境是Linux,默认使用headless方式运行Chrome浏览器的Web UI自动化...");
|
LogUtil.APP.info("检测到当前系统环境是Linux,默认使用headless方式运行Chrome浏览器的Web UI自动化...");
|
||||||
//无界面参数
|
//无界面参数
|
||||||
options.setHeadless(true);
|
options.setHeadless(true);
|
||||||
//禁用沙盒
|
//禁用沙盒
|
||||||
options.addArguments("no-sandbox");
|
options.addArguments("no-sandbox");
|
||||||
options.addArguments("start-maximized");
|
options.addArguments("start-maximized");
|
||||||
System.setProperty("webdriver.chrome.driver",drivenpath+"chromedriver_linux64");
|
System.setProperty("webdriver.chrome.driver",drivenpath+"chromedriver_linux64");
|
||||||
}
|
}
|
||||||
webDriver = new ChromeDriver(options);
|
webDriver = new ChromeDriver(options);
|
||||||
}else if(drivertype==3){
|
}else if(drivertype==3){
|
||||||
if(OS.startsWith("win")){
|
if(OS.startsWith("win")){
|
||||||
System.setProperty("webdriver.edge.driver",drivenpath+"msedgedriver.exe");
|
System.setProperty("webdriver.edge.driver",drivenpath+"msedgedriver.exe");
|
||||||
webDriver = new EdgeDriver();
|
webDriver = new EdgeDriver();
|
||||||
}else if(OS.contains("mac")){
|
}else if(OS.contains("mac")){
|
||||||
System.setProperty("webdriver.edge.driver",drivenpath+"msedgedriver_mac");
|
System.setProperty("webdriver.edge.driver",drivenpath+"msedgedriver_mac");
|
||||||
webDriver = new EdgeDriver();
|
webDriver = new EdgeDriver();
|
||||||
}else{
|
}else{
|
||||||
LogUtil.APP.warn("当前操作系统无法进行Edge浏览器的Web UI测试,请选择火狐或是谷歌浏览器!");
|
LogUtil.APP.warn("当前操作系统无法进行Edge浏览器的Web UI测试,请选择火狐或是谷歌浏览器!");
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
LogUtil.APP.warn("浏览器类型标识:{},获取到的浏览器类型标识未定义,默认IE浏览器进行执行....",drivertype);
|
LogUtil.APP.warn("浏览器类型标识:{},获取到的浏览器类型标识未定义,默认IE浏览器进行执行....",drivertype);
|
||||||
System.setProperty("webdriver.ie.driver",drivenpath+"IEDriverServer.exe");
|
System.setProperty("webdriver.ie.driver",drivenpath+"IEDriverServer.exe");
|
||||||
webDriver = new InternetExplorerDriver();
|
webDriver = new InternetExplorerDriver();
|
||||||
}
|
}
|
||||||
|
|
||||||
//解决webdriver在unix环境中,最大化会出现异常的bug,unix最大化在options中单独设置
|
//解决webdriver在unix环境中,最大化会出现异常的bug,unix最大化在options中单独设置
|
||||||
if(OS.startsWith("win")){
|
if(OS.startsWith("win")){
|
||||||
webDriver.manage().window().maximize();
|
assert webDriver != null;
|
||||||
}
|
webDriver.manage().window().maximize();
|
||||||
|
}
|
||||||
//设置页面加载最大时长30秒
|
|
||||||
webDriver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
|
//设置页面加载最大时长30秒
|
||||||
//设置元素出现最大时长30秒
|
assert webDriver != null;
|
||||||
webDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
|
webDriver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
|
||||||
|
//设置元素出现最大时长30秒
|
||||||
return webDriver;
|
webDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
|
||||||
}
|
|
||||||
|
return webDriver;
|
||||||
/**
|
}
|
||||||
* 初始化WebDriver
|
|
||||||
* @return
|
/**
|
||||||
* @throws IOException
|
* 初始化WebDriver
|
||||||
*/
|
* @return 返回初始化结果
|
||||||
public static WebDriver setWebDriverForLocal() throws IOException{
|
* @throws IOException 读取配置文件异常
|
||||||
File directory = new File("");
|
*/
|
||||||
String drivenpath=directory.getCanonicalPath()+File.separator+"BrowserDriven"+File.separator;
|
public static WebDriver setWebDriverForLocal() throws IOException{
|
||||||
System.setProperty("webdriver.ie.driver",drivenpath+"IEDriverServer.exe");
|
File directory = new File("");
|
||||||
WebDriver webDriver = new InternetExplorerDriver();
|
String drivenpath=directory.getCanonicalPath()+File.separator+"BrowserDriven"+File.separator;
|
||||||
webDriver.manage().window().maximize();
|
System.setProperty("webdriver.ie.driver",drivenpath+"IEDriverServer.exe");
|
||||||
//设置页面加载最大时长30秒
|
WebDriver webDriver = new InternetExplorerDriver();
|
||||||
webDriver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
|
webDriver.manage().window().maximize();
|
||||||
//设置元素出现最大时长30秒
|
//设置页面加载最大时长30秒
|
||||||
webDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
|
webDriver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
|
||||||
return webDriver;
|
//设置元素出现最大时长30秒
|
||||||
}
|
webDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
|
||||||
|
return webDriver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class WebTestControl {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 控制台模式调度计划执行用例
|
* 控制台模式调度计划执行用例
|
||||||
* @param planname
|
* @param planname ¼Æ»®Ãû³Æ
|
||||||
*/
|
*/
|
||||||
public static void manualExecutionPlan(String planname) {
|
public static void manualExecutionPlan(String planname) {
|
||||||
// 不记日志到数据库
|
// 不记日志到数据库
|
||||||
|
@ -54,7 +54,7 @@ public class WebTestControl {
|
||||||
}
|
}
|
||||||
serverOperation caselog = new serverOperation();
|
serverOperation caselog = new serverOperation();
|
||||||
List<ProjectCase> testCases = GetServerApi.getCasesbyplanname(planname);
|
List<ProjectCase> testCases = GetServerApi.getCasesbyplanname(planname);
|
||||||
List<ProjectCaseParams> pcplist = new ArrayList<ProjectCaseParams>();
|
List<ProjectCaseParams> pcplist = new ArrayList<>();
|
||||||
if (testCases.size() != 0) {
|
if (testCases.size() != 0) {
|
||||||
pcplist = GetServerApi.cgetParamsByProjectid(String.valueOf(testCases.get(0).getProjectId()));
|
pcplist = GetServerApi.cgetParamsByProjectid(String.valueOf(testCases.get(0).getProjectId()));
|
||||||
}
|
}
|
||||||
|
@ -69,14 +69,14 @@ public class WebTestControl {
|
||||||
LogUtil.APP.info("开始执行第{}条用例:【{}】......",i,testcase.getCaseSign());
|
LogUtil.APP.info("开始执行第{}条用例:【{}】......",i,testcase.getCaseSign());
|
||||||
try {
|
try {
|
||||||
WebCaseExecution.caseExcution(testcase, steps, taskid, wd, caselog, pcplist);
|
WebCaseExecution.caseExcution(testcase, steps, taskid, wd, caselog, pcplist);
|
||||||
} catch (InterruptedException e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
|
||||||
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
||||||
}
|
}
|
||||||
LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
|
LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
|
||||||
}
|
}
|
||||||
LogUtil.APP.info("当前项目测试计划中的用例已经全部执行完成...");
|
LogUtil.APP.info("当前项目测试计划中的用例已经全部执行完成...");
|
||||||
// 关闭浏览器
|
// 关闭浏览器
|
||||||
|
assert wd != null;
|
||||||
wd.quit();
|
wd.quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,12 +90,12 @@ public class WebTestControl {
|
||||||
List<ProjectCaseParams> pcplist = GetServerApi.cgetParamsByProjectid(task.getProjectId().toString());
|
List<ProjectCaseParams> pcplist = GetServerApi.cgetParamsByProjectid(task.getProjectId().toString());
|
||||||
TaskScheduling taskScheduling = GetServerApi.cGetTaskSchedulingByTaskId(task.getTaskId());
|
TaskScheduling taskScheduling = GetServerApi.cGetTaskSchedulingByTaskId(task.getTaskId());
|
||||||
String projectname = taskScheduling.getProject().getProjectName();
|
String projectname = taskScheduling.getProject().getProjectName();
|
||||||
task = GetServerApi.cgetTaskbyid(Integer.valueOf(taskid));
|
task = GetServerApi.cgetTaskbyid(Integer.parseInt(taskid));
|
||||||
String jobname = taskScheduling.getSchedulingName();
|
String jobname = taskScheduling.getSchedulingName();
|
||||||
int drivertype = serverOperation.querydrivertype(taskid);
|
int drivertype = serverOperation.querydrivertype(taskid);
|
||||||
int[] tastcount = null;
|
int[] tastcount = null;
|
||||||
// 判断是否要自动重启TOMCAT
|
// 判断是否要自动重启TOMCAT
|
||||||
if (restartstatus.indexOf("Status:true") > -1) {
|
if (restartstatus.contains("Status:true")) {
|
||||||
// 判断是否构建是否成功
|
// 判断是否构建是否成功
|
||||||
if (BuildResult.SUCCESS.equals(buildResult)) {
|
if (BuildResult.SUCCESS.equals(buildResult)) {
|
||||||
WebDriver wd = null;
|
WebDriver wd = null;
|
||||||
|
@ -123,7 +123,7 @@ public class WebTestControl {
|
||||||
// 插入开始执行的用例
|
// 插入开始执行的用例
|
||||||
caselog.insertTaskCaseExecute(taskid, taskScheduling.getProjectId(),testcase.getCaseId(),testcase.getCaseSign(), testcase.getCaseName(), 4);
|
caselog.insertTaskCaseExecute(taskid, taskScheduling.getProjectId(),testcase.getCaseId(),testcase.getCaseSign(), testcase.getCaseName(), 4);
|
||||||
WebCaseExecution.caseExcution(testcase, steps, taskid, wd, caselog, pcplist);
|
WebCaseExecution.caseExcution(testcase, steps, taskid, wd, caselog, pcplist);
|
||||||
} catch (InterruptedException e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
||||||
}
|
}
|
||||||
|
@ -137,6 +137,7 @@ public class WebTestControl {
|
||||||
HtmlMail.htmlContentFormat(tastcount, taskid, buildResult.toString(), restartstatus, testtime, jobname),
|
HtmlMail.htmlContentFormat(tastcount, taskid, buildResult.toString(), restartstatus, testtime, jobname),
|
||||||
taskid, taskScheduling, tastcount);
|
taskid, taskScheduling, tastcount);
|
||||||
// 关闭浏览器
|
// 关闭浏览器
|
||||||
|
assert wd != null;
|
||||||
wd.quit();
|
wd.quit();
|
||||||
} else {
|
} else {
|
||||||
LogUtil.APP.warn("项目构建失败,自动化测试自动退出!请前往JENKINS中检查项目构建情况。");
|
LogUtil.APP.warn("项目构建失败,自动化测试自动退出!请前往JENKINS中检查项目构建情况。");
|
||||||
|
|
|
@ -1,82 +1,80 @@
|
||||||
package luckyclient.execution.webdriver.ex;
|
package luckyclient.execution.webdriver.ex;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
|
|
||||||
import luckyclient.execution.httpinterface.TestControl;
|
import luckyclient.execution.httpinterface.TestControl;
|
||||||
import luckyclient.execution.webdriver.WebDriverInitialization;
|
import luckyclient.execution.webdriver.WebDriverInitialization;
|
||||||
import luckyclient.remote.api.GetServerApi;
|
import luckyclient.remote.api.GetServerApi;
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.ProjectCase;
|
||||||
import luckyclient.remote.entity.ProjectCaseParams;
|
import luckyclient.remote.entity.ProjectCaseParams;
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
import luckyclient.remote.entity.ProjectCaseSteps;
|
||||||
import luckyclient.remote.entity.TaskExecute;
|
import luckyclient.remote.entity.TaskExecute;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
||||||
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
* @date 2017年12月1日 上午9:29:40
|
* @date 2017年12月1日 上午9:29:40
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class WebBatchExecute{
|
public class WebBatchExecute{
|
||||||
|
|
||||||
public static void batchCaseExecuteForTast(String projectname,String taskid,String batchcase) throws IOException{
|
public static void batchCaseExecuteForTast(String taskid, String batchcase) throws IOException{
|
||||||
//记录日志到数据库
|
//记录日志到数据库
|
||||||
serverOperation.exetype = 0;
|
serverOperation.exetype = 0;
|
||||||
TestControl.TASKID = taskid;
|
TestControl.TASKID = taskid;
|
||||||
int drivertype = serverOperation.querydrivertype(taskid);
|
int drivertype = serverOperation.querydrivertype(taskid);
|
||||||
WebDriver wd = null;
|
WebDriver wd = null;
|
||||||
try {
|
try {
|
||||||
wd = WebDriverInitialization.setWebDriverForTask(drivertype);
|
wd = WebDriverInitialization.setWebDriverForTask(drivertype);
|
||||||
} catch (MalformedURLException e1) {
|
} catch (MalformedURLException e1) {
|
||||||
// TODO Auto-generated catch block
|
LogUtil.APP.error("初始化WebDriver出现异常!", e1);
|
||||||
LogUtil.APP.error("初始化WebDriver出现异常!", e1);
|
}
|
||||||
}
|
serverOperation caselog = new serverOperation();
|
||||||
serverOperation caselog = new serverOperation();
|
TaskExecute task=GetServerApi.cgetTaskbyid(Integer.parseInt(taskid));
|
||||||
TaskExecute task=GetServerApi.cgetTaskbyid(Integer.valueOf(taskid));
|
List<ProjectCaseParams> pcplist=GetServerApi.cgetParamsByProjectid(task.getProjectId().toString());
|
||||||
List<ProjectCaseParams> pcplist=GetServerApi.cgetParamsByProjectid(task.getProjectId().toString());
|
//执行全部非成功状态用例
|
||||||
//执行全部非成功状态用例
|
if(batchcase.contains("ALLFAIL")){
|
||||||
if(batchcase.indexOf("ALLFAIL")>-1){
|
List<Integer> caseIdList = caselog.getCaseListForUnSucByTaskId(taskid);
|
||||||
List<Integer> caseIdList = caselog.getCaseListForUnSucByTaskId(taskid);
|
for (Integer integer : caseIdList) {
|
||||||
for(int i=0;i<caseIdList.size();i++){
|
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(integer);
|
||||||
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(caseIdList.get(i));
|
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
||||||
List<ProjectCaseSteps> steps=GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
//删除旧的日志
|
||||||
//删除旧的日志
|
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
||||||
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
try {
|
||||||
try {
|
WebCaseExecution.caseExcution(testcase, steps, taskid, wd, caselog, pcplist);
|
||||||
WebCaseExecution.caseExcution(testcase, steps, taskid,wd,caselog,pcplist);
|
} catch (Exception e) {
|
||||||
} catch (InterruptedException e) {
|
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
||||||
// TODO Auto-generated catch block
|
}
|
||||||
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
}
|
||||||
}
|
}else{ //批量执行用例
|
||||||
}
|
String[] temp=batchcase.split("#");
|
||||||
}else{ //批量执行用例
|
for (String s : temp) {
|
||||||
String[] temp=batchcase.split("\\#");
|
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(Integer.valueOf(s));
|
||||||
for(int i=0;i<temp.length;i++){
|
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
||||||
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(Integer.valueOf(temp[i]));
|
//删除旧的日志
|
||||||
List<ProjectCaseSteps> steps=GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
||||||
//删除旧的日志
|
try {
|
||||||
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
WebCaseExecution.caseExcution(testcase, steps, taskid, wd, caselog, pcplist);
|
||||||
try {
|
} catch (Exception e) {
|
||||||
WebCaseExecution.caseExcution(testcase, steps,taskid,wd,caselog,pcplist);
|
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
||||||
} catch (InterruptedException e) {
|
}
|
||||||
// TODO Auto-generated catch block
|
}
|
||||||
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
}
|
||||||
}
|
serverOperation.updateTaskExecuteData(taskid, 0,2);
|
||||||
}
|
//关闭浏览器
|
||||||
}
|
assert wd != null;
|
||||||
serverOperation.updateTaskExecuteData(taskid, 0,2);
|
wd.quit();
|
||||||
//关闭浏览器
|
}
|
||||||
wd.quit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,336 +1,335 @@
|
||||||
package luckyclient.execution.webdriver.ex;
|
package luckyclient.execution.webdriver.ex;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
|
|
||||||
import luckyclient.execution.dispose.ActionManageForSteps;
|
import luckyclient.execution.dispose.ActionManageForSteps;
|
||||||
import luckyclient.execution.dispose.ParamsManageForSteps;
|
import luckyclient.execution.dispose.ParamsManageForSteps;
|
||||||
import luckyclient.execution.httpinterface.TestCaseExecution;
|
import luckyclient.execution.httpinterface.TestCaseExecution;
|
||||||
import luckyclient.execution.httpinterface.analyticsteps.InterfaceAnalyticCase;
|
import luckyclient.execution.httpinterface.analyticsteps.InterfaceAnalyticCase;
|
||||||
import luckyclient.execution.webdriver.BaseWebDrive;
|
import luckyclient.execution.webdriver.BaseWebDrive;
|
||||||
import luckyclient.execution.webdriver.EncapsulateOperation;
|
import luckyclient.execution.webdriver.EncapsulateOperation;
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.ProjectCase;
|
||||||
import luckyclient.remote.entity.ProjectCaseParams;
|
import luckyclient.remote.entity.ProjectCaseParams;
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
import luckyclient.remote.entity.ProjectCaseSteps;
|
||||||
import luckyclient.utils.Constants;
|
import luckyclient.utils.Constants;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
||||||
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
* @date 2018年3月1日
|
* @date 2018年3月1日
|
||||||
*/
|
*/
|
||||||
public class WebCaseExecution{
|
public class WebCaseExecution{
|
||||||
private static Map<String, String> variable = new HashMap<>();
|
private static Map<String, String> variable = new HashMap<>();
|
||||||
private static String casenote = "备注初始化";
|
private static String casenote = "备注初始化";
|
||||||
private static String imagname = "";
|
|
||||||
|
public static void caseExcution(ProjectCase testcase, List<ProjectCaseSteps> steps, String taskid, WebDriver wd, serverOperation caselog, List<ProjectCaseParams> pcplist) {
|
||||||
public static void caseExcution(ProjectCase testcase, List<ProjectCaseSteps> steps, String taskid, WebDriver wd, serverOperation caselog, List<ProjectCaseParams> pcplist) throws InterruptedException {
|
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), 3);
|
||||||
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), 3);
|
// 把公共参数加入到MAP中
|
||||||
// 把公共参数加入到MAP中
|
for (ProjectCaseParams pcp : pcplist) {
|
||||||
for (ProjectCaseParams pcp : pcplist) {
|
variable.put(pcp.getParamsName(), pcp.getParamsValue());
|
||||||
variable.put(pcp.getParamsName(), pcp.getParamsValue());
|
}
|
||||||
}
|
// 加入全局变量
|
||||||
// 加入全局变量
|
variable.putAll(ParamsManageForSteps.GLOBAL_VARIABLE);
|
||||||
variable.putAll(ParamsManageForSteps.GLOBAL_VARIABLE);
|
// 0:成功 1:失败 2:锁定 其他:锁定
|
||||||
// 0:成功 1:失败 2:锁定 其他:锁定
|
int setcaseresult = 0;
|
||||||
int setcaseresult = 0;
|
for (ProjectCaseSteps step : steps) {
|
||||||
for (ProjectCaseSteps step : steps) {
|
Map<String, String> params;
|
||||||
Map<String, String> params;
|
String result;
|
||||||
String result;
|
|
||||||
|
// 根据步骤类型来分析步骤参数
|
||||||
// 根据步骤类型来分析步骤参数
|
if (1 == step.getStepType()){
|
||||||
if (1 == step.getStepType()){
|
params = WebDriverAnalyticCase.analyticCaseStep(testcase, step, taskid, caselog, variable);
|
||||||
params = WebDriverAnalyticCase.analyticCaseStep(testcase, step, taskid, caselog, variable);
|
}else{
|
||||||
}else{
|
params = InterfaceAnalyticCase.analyticCaseStep(testcase, step, taskid, caselog, variable);
|
||||||
params = InterfaceAnalyticCase.analyticCaseStep(testcase, step, taskid, caselog, variable);
|
}
|
||||||
}
|
|
||||||
|
// 判断分析步骤参数是否有异常
|
||||||
// 判断分析步骤参数是否有异常
|
if (null != params.get("exception") && params.get("exception").contains("解析异常")) {
|
||||||
if (null != params.get("exception") && params.get("exception").contains("解析异常")) {
|
setcaseresult = 2;
|
||||||
setcaseresult = 2;
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
// 根据步骤类型来执行步骤
|
||||||
// 根据步骤类型来执行步骤
|
if (1 == step.getStepType()){
|
||||||
if (1 == step.getStepType()){
|
result = runWebStep(params, wd, taskid, testcase.getCaseId(), step.getStepSerialNumber(), caselog);
|
||||||
result = runWebStep(params, wd, taskid, testcase.getCaseId(), step.getStepSerialNumber(), caselog);
|
}else{
|
||||||
}else{
|
TestCaseExecution testCaseExecution=new TestCaseExecution();
|
||||||
TestCaseExecution testCaseExecution=new TestCaseExecution();
|
result = testCaseExecution.runStep(params, taskid, testcase.getCaseSign(), step, caselog);
|
||||||
result = testCaseExecution.runStep(params, taskid, testcase.getCaseSign(), step, caselog);
|
}
|
||||||
}
|
|
||||||
|
String expectedResults = params.get("ExpectedResults");
|
||||||
String expectedResults = params.get("ExpectedResults");
|
|
||||||
|
// 判断结果
|
||||||
// 判断结果
|
int stepresult = judgeResult(testcase, step, params, wd, taskid, expectedResults, result, caselog);
|
||||||
int stepresult = judgeResult(testcase, step, params, wd, taskid, expectedResults, result, caselog);
|
// 失败,并且不在继续,直接终止
|
||||||
// 失败,并且不在继续,直接终止
|
if (0 != stepresult) {
|
||||||
if (0 != stepresult) {
|
setcaseresult = stepresult;
|
||||||
setcaseresult = stepresult;
|
if (testcase.getFailcontinue() == 0) {
|
||||||
if (testcase.getFailcontinue() == 0) {
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),step.getStepSerialNumber());
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),step.getStepSerialNumber());
|
break;
|
||||||
break;
|
} else {
|
||||||
} else {
|
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),step.getStepSerialNumber());
|
||||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),step.getStepSerialNumber());
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
variable.clear();
|
||||||
variable.clear();
|
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), setcaseresult);
|
||||||
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), setcaseresult);
|
if (setcaseresult == 0) {
|
||||||
if (setcaseresult == 0) {
|
LogUtil.APP.info("用例【{}】全部步骤执行结果成功...",testcase.getCaseSign());
|
||||||
LogUtil.APP.info("用例【{}】全部步骤执行结果成功...",testcase.getCaseSign());
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例全部步骤执行结果成功", "info", "ending", "");
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例全部步骤执行结果成功", "info", "ending", "");
|
} else {
|
||||||
} else {
|
LogUtil.APP.warn("用例【{}】步骤执行过程中失败或是锁定...请查看具体原因:{}",testcase.getCaseSign(),casenote);
|
||||||
LogUtil.APP.warn("用例【{}】步骤执行过程中失败或是锁定...请查看具体原因:{}",testcase.getCaseSign(),casenote);
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例执行过程中失败或是锁定" + casenote, "error", "ending", "");
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例执行过程中失败或是锁定" + casenote, "error", "ending", "");
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public static String runWebStep(Map<String, String> params, WebDriver wd, String taskid, Integer caseId, int stepno, serverOperation caselog) {
|
||||||
public static String runWebStep(Map<String, String> params, WebDriver wd, String taskid, Integer caseId, int stepno, serverOperation caselog) {
|
String result;
|
||||||
String result = "";
|
String property;
|
||||||
String property;
|
String propertyValue;
|
||||||
String propertyValue;
|
String operation;
|
||||||
String operation;
|
String operationValue;
|
||||||
String operationValue;
|
|
||||||
|
try {
|
||||||
try {
|
property = params.get("property");
|
||||||
property = params.get("property");
|
propertyValue = params.get("property_value");
|
||||||
propertyValue = params.get("property_value");
|
operation = params.get("operation");
|
||||||
operation = params.get("operation");
|
operationValue = params.get("operation_value");
|
||||||
operationValue = params.get("operation_value");
|
|
||||||
|
LogUtil.APP.info("二次解析用例过程完成,等待进行对象操作......");
|
||||||
LogUtil.APP.info("二次解析用例过程完成,等待进行对象操作......");
|
caselog.insertTaskCaseLog(taskid, caseId, "对象操作:" + operation + "; 操作值:" + operationValue, "info", String.valueOf(stepno), "");
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, "对象操作:" + operation + "; 操作值:" + operationValue, "info", String.valueOf(stepno), "");
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
LogUtil.APP.error("二次解析用例过程抛出异常!",e);
|
||||||
LogUtil.APP.error("二次解析用例过程抛出异常!",e);
|
return "步骤执行失败:解析用例失败!";
|
||||||
return "步骤执行失败:解析用例失败!";
|
}
|
||||||
}
|
|
||||||
|
try {
|
||||||
try {
|
//调用另一条用例,支持接口,web类型用例
|
||||||
//调用另一条用例,支持接口,web类型用例
|
if (null != operationValue && "runcase".equals(operation)) {
|
||||||
if (null != operation && null != operationValue && "runcase".equals(operation)) {
|
String[] temp = operationValue.split(",", -1);
|
||||||
String[] temp = operationValue.split(",", -1);
|
TestCaseExecution testCaseExecution=new TestCaseExecution();
|
||||||
TestCaseExecution testCaseExecution=new TestCaseExecution();
|
String ex = testCaseExecution.oneCaseExecuteForUICase(temp[0], taskid, caselog, wd);
|
||||||
String ex = testCaseExecution.oneCaseExecuteForUICase(temp[0], taskid, caselog, wd);
|
if (!ex.contains("CallCase调用出错!") && !ex.contains("解析出错啦!") && !ex.contains("失败")) {
|
||||||
if (!ex.contains("CallCase调用出错!") && !ex.contains("解析出错啦!") && !ex.contains("失败")) {
|
return ex;
|
||||||
return ex;
|
} else {
|
||||||
} else {
|
return "步骤执行失败:"+ex;
|
||||||
return "步骤执行失败:"+ex;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// 页面元素层
|
||||||
// 页面元素层
|
if (null != property && null != propertyValue && null != operation) {
|
||||||
if (null != property && null != propertyValue && null != operation) {
|
WebElement we = isElementExist(wd, property, propertyValue);
|
||||||
WebElement we = isElementExist(wd, property, propertyValue);
|
|
||||||
|
//判断元素是否存在关键字
|
||||||
//判断元素是否存在关键字
|
if(operation.equals("iselementexist")){
|
||||||
if(operation.equals("iselementexist")){
|
// 判断此元素是否存在
|
||||||
// 判断此元素是否存在
|
if (null == we) {
|
||||||
if (null == we) {
|
LogUtil.APP.warn("获取到的值是【false】");
|
||||||
LogUtil.APP.warn("获取到的值是【false】");
|
return "获取到的值是【false】";
|
||||||
return "获取到的值是【false】";
|
}else{
|
||||||
}else{
|
LogUtil.APP.info("获取到的值是【true】");
|
||||||
LogUtil.APP.info("获取到的值是【true】");
|
return "获取到的值是【true】";
|
||||||
return "获取到的值是【true】";
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// 判断此元素是否存在
|
||||||
// 判断此元素是否存在
|
if (null == we) {
|
||||||
if (null == we) {
|
LogUtil.APP.warn("定位对象失败,isElementExist为null!");
|
||||||
LogUtil.APP.warn("定位对象失败,isElementExist为null!");
|
return "步骤执行失败:定位的元素不存在!";
|
||||||
return "步骤执行失败:定位的元素不存在!";
|
}
|
||||||
}
|
|
||||||
|
//点亮即将操作的元素
|
||||||
//点亮即将操作的元素
|
BaseWebDrive.highLightElement(wd, we);
|
||||||
BaseWebDrive.highLightElement(wd, we);
|
|
||||||
|
if (operation.contains("select")) {
|
||||||
if (operation.contains("select")) {
|
result = EncapsulateOperation.selectOperation(we, operation, operationValue);
|
||||||
result = EncapsulateOperation.selectOperation(we, operation, operationValue);
|
} else if (operation.contains("get")) {
|
||||||
} else if (operation.contains("get")) {
|
result = EncapsulateOperation.getOperation(wd, we, operation, operationValue);
|
||||||
result = EncapsulateOperation.getOperation(wd, we, operation, operationValue);
|
} else if (operation.contains("mouse")) {
|
||||||
} else if (operation.contains("mouse")) {
|
result = EncapsulateOperation.actionWeOperation(wd, we, operation, operationValue, property, propertyValue);
|
||||||
result = EncapsulateOperation.actionWeOperation(wd, we, operation, operationValue, property, propertyValue);
|
} else {
|
||||||
} else {
|
result = EncapsulateOperation.objectOperation(wd, we, operation, operationValue, property, propertyValue);
|
||||||
result = EncapsulateOperation.objectOperation(wd, we, operation, operationValue, property, propertyValue);
|
}
|
||||||
}
|
// Driver层操作
|
||||||
// Driver层操作
|
} else if (null == property && null != operation) {
|
||||||
} else if (null == property && null != operation) {
|
// 处理弹出框事件
|
||||||
// 处理弹出框事件
|
if (operation.contains("alert")) {
|
||||||
if (operation.contains("alert")) {
|
result = EncapsulateOperation.alertOperation(wd, operation);
|
||||||
result = EncapsulateOperation.alertOperation(wd, operation);
|
} else if (operation.contains("mouse")) {
|
||||||
} else if (operation.contains("mouse")) {
|
result = EncapsulateOperation.actionOperation(wd, operation, operationValue);
|
||||||
result = EncapsulateOperation.actionOperation(wd, operation, operationValue);
|
} else {
|
||||||
} else {
|
result = EncapsulateOperation.driverOperation(wd, operation, operationValue);
|
||||||
result = EncapsulateOperation.driverOperation(wd, operation, operationValue);
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
LogUtil.APP.warn("元素操作过程失败!");
|
||||||
LogUtil.APP.warn("元素操作过程失败!");
|
result = "步骤执行失败:元素操作过程失败!";
|
||||||
result = "步骤执行失败:元素操作过程失败!";
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
LogUtil.APP.error("元素定位过程或是操作过程失败或异常!",e);
|
||||||
LogUtil.APP.error("元素定位过程或是操作过程失败或异常!",e);
|
return "步骤执行失败:元素定位过程或是操作过程失败或异常!" + e.getMessage();
|
||||||
return "步骤执行失败:元素定位过程或是操作过程失败或异常!" + e.getMessage();
|
}
|
||||||
}
|
|
||||||
|
if (result.contains("步骤执行失败:")){
|
||||||
if (result.contains("步骤执行失败:")){
|
caselog.insertTaskCaseLog(taskid, caseId, result, "error", String.valueOf(stepno), "");
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, result, "error", String.valueOf(stepno), "");
|
} else{
|
||||||
} else{
|
caselog.insertTaskCaseLog(taskid, caseId, result, "info", String.valueOf(stepno), "");
|
||||||
caselog.insertTaskCaseLog(taskid, caseId, result, "info", String.valueOf(stepno), "");
|
}
|
||||||
}
|
|
||||||
|
if (result.contains("获取到的值是【") && result.contains("】")) {
|
||||||
if (result.contains("获取到的值是【") && result.contains("】")) {
|
result = result.substring(result.indexOf("获取到的值是【") + "获取到的值是【".length(), result.length() - 1);
|
||||||
result = result.substring(result.indexOf("获取到的值是【") + "获取到的值是【".length(), result.length() - 1);
|
}
|
||||||
}
|
return result;
|
||||||
return result;
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
private static WebElement isElementExist(WebDriver wd, String property, String propertyValue) {
|
||||||
private static WebElement isElementExist(WebDriver wd, String property, String propertyValue) {
|
try {
|
||||||
try {
|
WebElement we = null;
|
||||||
WebElement we = null;
|
property = property.toLowerCase();
|
||||||
property = property.toLowerCase();
|
// 处理WebElement对象定位
|
||||||
// 处理WebElement对象定位
|
switch (property) {
|
||||||
switch (property) {
|
case "id":
|
||||||
case "id":
|
we = wd.findElement(By.id(propertyValue));
|
||||||
we = wd.findElement(By.id(propertyValue));
|
break;
|
||||||
break;
|
case "name":
|
||||||
case "name":
|
we = wd.findElement(By.name(propertyValue));
|
||||||
we = wd.findElement(By.name(propertyValue));
|
break;
|
||||||
break;
|
case "xpath":
|
||||||
case "xpath":
|
we = wd.findElement(By.xpath(propertyValue));
|
||||||
we = wd.findElement(By.xpath(propertyValue));
|
break;
|
||||||
break;
|
case "linktext":
|
||||||
case "linktext":
|
we = wd.findElement(By.linkText(propertyValue));
|
||||||
we = wd.findElement(By.linkText(propertyValue));
|
break;
|
||||||
break;
|
case "tagname":
|
||||||
case "tagname":
|
we = wd.findElement(By.tagName(propertyValue));
|
||||||
we = wd.findElement(By.tagName(propertyValue));
|
break;
|
||||||
break;
|
case "cssselector":
|
||||||
case "cssselector":
|
we = wd.findElement(By.cssSelector(propertyValue));
|
||||||
we = wd.findElement(By.cssSelector(propertyValue));
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
return we;
|
||||||
return we;
|
|
||||||
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
LogUtil.APP.error("当前对象定位失败!",e);
|
||||||
LogUtil.APP.error("当前对象定位失败!",e);
|
return null;
|
||||||
return null;
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
public static int judgeResult(ProjectCase testcase, ProjectCaseSteps step, Map<String, String> params, WebDriver driver, String taskid, String expect, String result, serverOperation caselog) {
|
||||||
public static int judgeResult(ProjectCase testcase, ProjectCaseSteps step, Map<String, String> params, WebDriver driver, String taskid, String expect, String result, serverOperation caselog) throws InterruptedException {
|
int setresult = 0;
|
||||||
int setresult = 0;
|
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
|
||||||
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
|
String imagname = timeformat.format(new Date());
|
||||||
imagname = timeformat.format(new Date());
|
|
||||||
|
result = ActionManageForSteps.actionManage(step.getAction(), result);
|
||||||
result = ActionManageForSteps.actionManage(step.getAction(), result);
|
if (null != result && !result.contains("步骤执行失败:")) {
|
||||||
if (null != result && !result.contains("步骤执行失败:")) {
|
// 有预期结果
|
||||||
// 有预期结果
|
if (null != expect && !expect.isEmpty()) {
|
||||||
if (null != expect && !expect.isEmpty()) {
|
LogUtil.APP.info("期望结果为【{}】",expect);
|
||||||
LogUtil.APP.info("期望结果为【{}】",expect);
|
// 赋值传参模式
|
||||||
// 赋值传参模式
|
if (expect.length() > Constants.ASSIGNMENT_SIGN.length() && expect.startsWith(Constants.ASSIGNMENT_SIGN)) {
|
||||||
if (expect.length() > Constants.ASSIGNMENT_SIGN.length() && expect.startsWith(Constants.ASSIGNMENT_SIGN)) {
|
variable.put(expect.substring(Constants.ASSIGNMENT_SIGN.length()), result);
|
||||||
variable.put(expect.substring(Constants.ASSIGNMENT_SIGN.length()), result);
|
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给变量【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),result,expect.substring(Constants.ASSIGNMENT_SIGN.length()));
|
||||||
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给变量【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),result,expect.substring(Constants.ASSIGNMENT_SIGN.length()));
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给变量【" + expect.substring(Constants.ASSIGNMENT_SIGN.length()) + "】", "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给变量【" + expect.substring(Constants.ASSIGNMENT_SIGN.length()) + "】", "info", String.valueOf(step.getStepSerialNumber()), "");
|
}
|
||||||
}
|
// 赋值全局变量
|
||||||
// 赋值全局变量
|
else if (expect.length() > Constants.ASSIGNMENT_GLOBALSIGN.length() && expect.startsWith(Constants.ASSIGNMENT_GLOBALSIGN)) {
|
||||||
else if (expect.length() > Constants.ASSIGNMENT_GLOBALSIGN.length() && expect.startsWith(Constants.ASSIGNMENT_GLOBALSIGN)) {
|
variable.put(expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), result);
|
||||||
variable.put(expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), result);
|
ParamsManageForSteps.GLOBAL_VARIABLE.put(expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), result);
|
||||||
ParamsManageForSteps.GLOBAL_VARIABLE.put(expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()), result);
|
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给全局变量【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),result,expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()));
|
||||||
LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给全局变量【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),result,expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()));
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给全局变量【" + expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()) + "】", "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给全局变量【" + expect.substring(Constants.ASSIGNMENT_GLOBALSIGN.length()) + "】", "info", String.valueOf(step.getStepSerialNumber()), "");
|
}
|
||||||
}
|
// WebUI检查模式
|
||||||
// WebUI检查模式
|
else if (1 == step.getStepType() && params.get("checkproperty") != null && params.get("checkproperty_value") != null) {
|
||||||
else if (1 == step.getStepType() && params.get("checkproperty") != null && params.get("checkproperty_value") != null) {
|
String checkproperty = params.get("checkproperty");
|
||||||
String checkproperty = params.get("checkproperty");
|
String checkPropertyValue = params.get("checkproperty_value");
|
||||||
String checkPropertyValue = params.get("checkproperty_value");
|
|
||||||
|
WebElement we = isElementExist(driver, checkproperty, checkPropertyValue);
|
||||||
WebElement we = isElementExist(driver, checkproperty, checkPropertyValue);
|
if (null != we) {
|
||||||
if (null != we) {
|
LogUtil.APP.info("用例:{} 第{}步,在当前页面中找到预期结果中对象。当前步骤执行成功!",testcase.getCaseSign(),step.getStepSerialNumber());
|
||||||
LogUtil.APP.info("用例:{} 第{}步,在当前页面中找到预期结果中对象。当前步骤执行成功!",testcase.getCaseSign(),step.getStepSerialNumber());
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中找到预期结果中对象。当前步骤执行成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中找到预期结果中对象。当前步骤执行成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
|
} else {
|
||||||
} else {
|
casenote = "第" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。执行失败!";
|
||||||
casenote = "第" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。执行失败!";
|
setresult = 1;
|
||||||
setresult = 1;
|
BaseWebDrive.webScreenShot(driver, imagname);
|
||||||
BaseWebDrive.webScreenShot(driver, imagname);
|
LogUtil.APP.warn("用例:{} 第{}步,没有在当前页面中找到预期结果中对象。当前步骤执行失败!",testcase.getCaseSign(),step.getStepSerialNumber());
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,没有在当前页面中找到预期结果中对象。当前步骤执行失败!",testcase.getCaseSign(),step.getStepSerialNumber());
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中没有找到预期结果中对象。当前步骤执行失败!" + "checkproperty【" + checkproperty + "】 checkproperty_value【" + checkPropertyValue + "】", "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中没有找到预期结果中对象。当前步骤执行失败!" + "checkproperty【" + checkproperty + "】 checkproperty_value【" + checkPropertyValue + "】", "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
}
|
||||||
}
|
}
|
||||||
}
|
// 其它匹配模式
|
||||||
// 其它匹配模式
|
else {
|
||||||
else {
|
// 模糊匹配预期结果模式
|
||||||
// 模糊匹配预期结果模式
|
if (expect.length() > Constants.FUZZY_MATCHING_SIGN.length() && expect.startsWith(Constants.FUZZY_MATCHING_SIGN)) {
|
||||||
if (expect.length() > Constants.FUZZY_MATCHING_SIGN.length() && expect.startsWith(Constants.FUZZY_MATCHING_SIGN)) {
|
if (result.contains(expect.substring(Constants.FUZZY_MATCHING_SIGN.length()))) {
|
||||||
if (result.contains(expect.substring(Constants.FUZZY_MATCHING_SIGN.length()))) {
|
LogUtil.APP.info("用例:{} 第{}步,模糊匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
|
||||||
LogUtil.APP.info("用例:{} 第{}步,模糊匹配预期结果成功!执行结果:",testcase.getCaseSign(),step.getStepSerialNumber(),result);
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果成功!执行结果:" + result, "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果成功!执行结果:" + result, "info", String.valueOf(step.getStepSerialNumber()), "");
|
} else {
|
||||||
} else {
|
casenote = "第" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!";
|
||||||
casenote = "第" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!";
|
setresult = 1;
|
||||||
setresult = 1;
|
BaseWebDrive.webScreenShot(driver, imagname);
|
||||||
BaseWebDrive.webScreenShot(driver, imagname);
|
LogUtil.APP.warn("用例:{} 第{}步,模糊匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expect.substring(Constants.FUZZY_MATCHING_SIGN.length()),result);
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,模糊匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expect.substring(Constants.FUZZY_MATCHING_SIGN.length()),result);
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果失败!预期结果:" + expect.substring(Constants.FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果失败!预期结果:" + expect.substring(Constants.FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
}
|
||||||
}
|
}
|
||||||
}
|
// 正则匹配预期结果模式
|
||||||
// 正则匹配预期结果模式
|
else if (expect.length() > Constants.REGULAR_MATCHING_SIGN.length() && expect.startsWith(Constants.REGULAR_MATCHING_SIGN)) {
|
||||||
else if (expect.length() > Constants.REGULAR_MATCHING_SIGN.length() && expect.startsWith(Constants.REGULAR_MATCHING_SIGN)) {
|
Pattern pattern = Pattern.compile(expect.substring(Constants.REGULAR_MATCHING_SIGN.length()));
|
||||||
Pattern pattern = Pattern.compile(expect.substring(Constants.REGULAR_MATCHING_SIGN.length()));
|
Matcher matcher = pattern.matcher(result);
|
||||||
Matcher matcher = pattern.matcher(result);
|
if (matcher.find()) {
|
||||||
if (matcher.find()) {
|
LogUtil.APP.info("用例:{} 第{}步,正则匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
|
||||||
LogUtil.APP.info("用例:{} 第{}步,正则匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
|
} else {
|
||||||
} else {
|
casenote = "第" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!";
|
||||||
casenote = "第" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!";
|
setresult = 1;
|
||||||
setresult = 1;
|
BaseWebDrive.webScreenShot(driver, imagname);
|
||||||
BaseWebDrive.webScreenShot(driver, imagname);
|
LogUtil.APP.warn("用例:{} 第{}步,正则匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expect.substring(Constants.REGULAR_MATCHING_SIGN.length()),result);
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,正则匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expect.substring(Constants.REGULAR_MATCHING_SIGN.length()),result);
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果失败!预期结果:" + expect.substring(Constants.REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果失败!预期结果:" + expect.substring(Constants.REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
}
|
||||||
}
|
}
|
||||||
}
|
// 精确匹配预期结果模式
|
||||||
// 精确匹配预期结果模式
|
else {
|
||||||
else {
|
if (expect.equals(result)) {
|
||||||
if (expect.equals(result)) {
|
LogUtil.APP.info("用例:{} 第{}步,精确匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
|
||||||
LogUtil.APP.info("用例:{} 第{}步,精确匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
|
} else {
|
||||||
} else {
|
casenote = "第" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!";
|
||||||
casenote = "第" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!";
|
setresult = 1;
|
||||||
setresult = 1;
|
BaseWebDrive.webScreenShot(driver, imagname);
|
||||||
BaseWebDrive.webScreenShot(driver, imagname);
|
LogUtil.APP.warn("用例:{} 第{}步,精确匹配预期结果失败!预期结果是:【{}】 执行结果:【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),expect,result);
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,精确匹配预期结果失败!预期结果是:【{}】 执行结果:【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),expect,result);
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果失败!预期结果是:【"+expect+"】 执行结果:【"+ result+"】", "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果失败!预期结果是:【"+expect+"】 执行结果:【"+ result+"】", "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
casenote = (null != result) ? result : "";
|
||||||
casenote = (null != result) ? result : "";
|
setresult = 2;
|
||||||
setresult = 2;
|
BaseWebDrive.webScreenShot(driver, imagname);
|
||||||
BaseWebDrive.webScreenShot(driver, imagname);
|
LogUtil.APP.warn("用例:{} 第{}步,执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),casenote);
|
||||||
LogUtil.APP.warn("用例:{} 第{}步,执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),casenote);
|
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "当前步骤在执行过程中解析|定位元素|操作对象失败!" + casenote, "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
||||||
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "当前步骤在执行过程中解析|定位元素|操作对象失败!" + casenote, "error", String.valueOf(step.getStepSerialNumber()), imagname);
|
}
|
||||||
}
|
|
||||||
|
return setresult;
|
||||||
return setresult;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,193 +1,194 @@
|
||||||
package luckyclient.execution.webdriver.ex;
|
package luckyclient.execution.webdriver.ex;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import luckyclient.execution.dispose.ChangString;
|
import luckyclient.execution.dispose.ChangString;
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.ProjectCase;
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
import luckyclient.remote.entity.ProjectCaseSteps;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @ClassName: AnalyticCase
|
* @ClassName: AnalyticCase
|
||||||
* @Description: 解析单个用例中描述部分的脚本 @author: seagull
|
* @Description: 解析单个用例中描述部分的脚本 @author: seagull
|
||||||
* @date 2016年9月18日
|
* @date 2016年9月18日
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class WebDriverAnalyticCase {
|
public class WebDriverAnalyticCase {
|
||||||
// private static String splitFlag = "\\|";
|
// private static String splitFlag = "\\|";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Web UI类型的步骤解析
|
* Web UI类型的步骤解析
|
||||||
*
|
*
|
||||||
* @param projectcase
|
* @param projectcase 用例对象
|
||||||
* @param step
|
* @param step 用例步骤对象
|
||||||
* @param taskid
|
* @param taskid 任务ID
|
||||||
* @param caselog
|
* @param caselog 日志对象
|
||||||
* @return
|
* @return 返回解析结果MAP
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年1月17日
|
* @date 2019年1月17日
|
||||||
*/
|
*/
|
||||||
public static Map<String, String> analyticCaseStep(ProjectCase projectcase, ProjectCaseSteps step, String taskid,
|
public static Map<String, String> analyticCaseStep(ProjectCase projectcase, ProjectCaseSteps step, String taskid,
|
||||||
serverOperation caselog, Map<String, String> variable) {
|
serverOperation caselog, Map<String, String> variable) {
|
||||||
Map<String, String> params = new HashMap<String, String>(0);
|
Map<String, String> params = new HashMap<>(0);
|
||||||
|
|
||||||
String resultstr = null;
|
String resultstr;
|
||||||
try {
|
try {
|
||||||
// 处理值传递
|
// 处理值传递
|
||||||
String path = ChangString.changparams(step.getStepPath(), variable, "包路径|定位路径");
|
String path = ChangString.changparams(step.getStepPath(), variable, "包路径|定位路径");
|
||||||
if (null != path && path.contains("=")) {
|
if (null != path && path.contains("=")) {
|
||||||
String property = path.substring(0, path.indexOf("=")).trim();
|
String property = path.substring(0, path.indexOf("=")).trim();
|
||||||
String propertyValue = path.substring(path.indexOf("=") + 1, path.length()).trim();
|
String propertyValue = path.substring(path.indexOf("=") + 1).trim();
|
||||||
// set属性
|
// set属性
|
||||||
params.put("property", property.toLowerCase());
|
params.put("property", property.toLowerCase());
|
||||||
// set属性值
|
// set属性值
|
||||||
params.put("property_value", propertyValue);
|
params.put("property_value", propertyValue);
|
||||||
LogUtil.APP.info("对象属性解析结果:property:{}; property_value:{}", property, propertyValue);
|
LogUtil.APP.info("对象属性解析结果:property:{}; property_value:{}", property, propertyValue);
|
||||||
}
|
}
|
||||||
// set操作方法,处理值传递
|
// set操作方法,处理值传递
|
||||||
String operation = ChangString.changparams(step.getStepOperation().toLowerCase(), variable, "操作");
|
String operation = ChangString.changparams(step.getStepOperation().toLowerCase(), variable, "操作");
|
||||||
params.put("operation", operation);
|
params.put("operation", operation);
|
||||||
// set属性值,处理值传递
|
// set属性值,处理值传递
|
||||||
String operationValue = ChangString.changparams(step.getStepParameters(), variable, "操作参数");
|
String operationValue = ChangString.changparams(step.getStepParameters(), variable, "操作参数");
|
||||||
if (StringUtils.isNotEmpty(operationValue)) {
|
if (StringUtils.isNotEmpty(operationValue)) {
|
||||||
params.put("operation_value", operationValue);
|
params.put("operation_value", operationValue);
|
||||||
}
|
}
|
||||||
LogUtil.APP.info("对象操作解析结果:operation:{}; operation_value:{}", operation,operationValue);
|
LogUtil.APP.info("对象操作解析结果:operation:{}; operation_value:{}", operation,operationValue);
|
||||||
// 获取预期结果字符串
|
// 获取预期结果字符串
|
||||||
resultstr = step.getExpectedResult();
|
resultstr = step.getExpectedResult();
|
||||||
|
|
||||||
// set预期结果
|
// set预期结果
|
||||||
if (null == resultstr || "".equals(resultstr)) {
|
if (null == resultstr || "".equals(resultstr)) {
|
||||||
params.put("ExpectedResults", "");
|
params.put("ExpectedResults", "");
|
||||||
} else if (null != resultstr) {
|
} else {
|
||||||
String expectedResults = subComment(resultstr);
|
String expectedResults = subComment(resultstr);
|
||||||
|
|
||||||
// 处理check字段
|
// 处理check字段
|
||||||
if (expectedResults.toLowerCase().startsWith("check(")) {
|
if (expectedResults.toLowerCase().startsWith("check(")) {
|
||||||
expectedResults = expectedResults.replace("Check(", "check(");
|
expectedResults = expectedResults.replace("Check(", "check(");
|
||||||
params.put("checkproperty", expectedResults.substring(expectedResults.indexOf("check(") + 6,
|
params.put("checkproperty", expectedResults.substring(expectedResults.indexOf("check(") + 6,
|
||||||
expectedResults.indexOf("=")));
|
expectedResults.indexOf("=")));
|
||||||
params.put("checkproperty_value", expectedResults.substring(expectedResults.indexOf("=") + 1,
|
params.put("checkproperty_value", expectedResults.substring(expectedResults.indexOf("=") + 1,
|
||||||
expectedResults.lastIndexOf(")")));
|
expectedResults.lastIndexOf(")")));
|
||||||
}
|
}
|
||||||
//处理值传递
|
//处理值传递
|
||||||
expectedResults = ChangString.changparams(expectedResults, variable, "预期结果");
|
expectedResults = ChangString.changparams(expectedResults, variable, "预期结果");
|
||||||
params.put("ExpectedResults", expectedResults);
|
params.put("ExpectedResults", expectedResults);
|
||||||
LogUtil.APP.info("预期结果解析:ExpectedResults:{}", expectedResults);
|
LogUtil.APP.info("预期结果解析:ExpectedResults:{}", expectedResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
LogUtil.APP.info("用例编号:{} 第{}步,解析自动化用例步骤脚本完成!", projectcase.getCaseSign(), step.getStepSerialNumber());
|
LogUtil.APP.info("用例编号:{} 第{}步,解析自动化用例步骤脚本完成!", projectcase.getCaseSign(), step.getStepSerialNumber());
|
||||||
if (null != caselog) {
|
if (null != caselog) {
|
||||||
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),
|
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),
|
||||||
"步骤编号:" + step.getStepSerialNumber() + " 解析自动化用例步骤脚本完成!", "info",
|
"步骤编号:" + step.getStepSerialNumber() + " 解析自动化用例步骤脚本完成!", "info",
|
||||||
String.valueOf(step.getStepSerialNumber()), "");
|
String.valueOf(step.getStepSerialNumber()), "");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.APP.error("用例编号:{} 第{}步,解析自动化用例步骤脚本出现异常!", projectcase.getCaseSign(), step.getStepSerialNumber(),
|
LogUtil.APP.error("用例编号:{} 第{}步,解析自动化用例步骤脚本出现异常!", projectcase.getCaseSign(), step.getStepSerialNumber(),
|
||||||
e);
|
e);
|
||||||
if (null != caselog) {
|
if (null != caselog) {
|
||||||
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),
|
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),
|
||||||
"步骤编号:" + step.getStepSerialNumber() + " 解析自动化用例步骤脚本出错!", "error",
|
"步骤编号:" + step.getStepSerialNumber() + " 解析自动化用例步骤脚本出错!", "error",
|
||||||
String.valueOf(step.getStepSerialNumber()), "");
|
String.valueOf(step.getStepSerialNumber()), "");
|
||||||
}
|
}
|
||||||
params.put("exception", "用例编号:" + projectcase.getCaseSign() + "|解析异常,用例步骤为空或是用例脚本错误!");
|
params.put("exception", "用例编号:" + projectcase.getCaseSign() + "|解析异常,用例步骤为空或是用例脚本错误!");
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String subComment(String htmlStr) throws InterruptedException {
|
private static String subComment(String htmlStr) {
|
||||||
// 定义script的正则表达式
|
// 定义script的正则表达式
|
||||||
String regExScript = "<script[^>]*?>[\\s\\S]*?<\\/script>";
|
String regExScript = "<script[^>]*?>[\\s\\S]*?</script>";
|
||||||
// 定义style的正则表达式
|
// 定义style的正则表达式
|
||||||
String regExStyle = "<style[^>]*?>[\\s\\S]*?<\\/style>";
|
String regExStyle = "<style[^>]*?>[\\s\\S]*?</style>";
|
||||||
// 定义HTML标签的正则表达式
|
// 定义HTML标签的正则表达式
|
||||||
String regExHtml = "<[^>]+>";
|
String regExHtml = "<[^>]+>";
|
||||||
// 定义空格回车换行符
|
// 定义空格回车换行符
|
||||||
String regExSpace = "\t|\r|\n";
|
String regExSpace = "[\t\r\n]";
|
||||||
|
|
||||||
String scriptstr = null;
|
String scriptstr;
|
||||||
if (htmlStr != null) {
|
if (htmlStr != null) {
|
||||||
Pattern pScript = Pattern.compile(regExScript, Pattern.CASE_INSENSITIVE);
|
Pattern pScript = Pattern.compile(regExScript, Pattern.CASE_INSENSITIVE);
|
||||||
Matcher mScript = pScript.matcher(htmlStr);
|
Matcher mScript = pScript.matcher(htmlStr);
|
||||||
// 过滤script标签
|
// 过滤script标签
|
||||||
htmlStr = mScript.replaceAll("");
|
htmlStr = mScript.replaceAll("");
|
||||||
|
|
||||||
Pattern pStyle = Pattern.compile(regExStyle, Pattern.CASE_INSENSITIVE);
|
Pattern pStyle = Pattern.compile(regExStyle, Pattern.CASE_INSENSITIVE);
|
||||||
Matcher mStyle = pStyle.matcher(htmlStr);
|
Matcher mStyle = pStyle.matcher(htmlStr);
|
||||||
// 过滤style标签
|
// 过滤style标签
|
||||||
htmlStr = mStyle.replaceAll("");
|
htmlStr = mStyle.replaceAll("");
|
||||||
|
|
||||||
Pattern pHtml = Pattern.compile(regExHtml, Pattern.CASE_INSENSITIVE);
|
Pattern pHtml = Pattern.compile(regExHtml, Pattern.CASE_INSENSITIVE);
|
||||||
Matcher mHtml = pHtml.matcher(htmlStr);
|
Matcher mHtml = pHtml.matcher(htmlStr);
|
||||||
// 过滤html标签
|
// 过滤html标签
|
||||||
htmlStr = mHtml.replaceAll("");
|
htmlStr = mHtml.replaceAll("");
|
||||||
|
|
||||||
Pattern pSpace = Pattern.compile(regExSpace, Pattern.CASE_INSENSITIVE);
|
Pattern pSpace = Pattern.compile(regExSpace, Pattern.CASE_INSENSITIVE);
|
||||||
Matcher mSpace = pSpace.matcher(htmlStr);
|
Matcher mSpace = pSpace.matcher(htmlStr);
|
||||||
// 过滤空格回车标签
|
// 过滤空格回车标签
|
||||||
htmlStr = mSpace.replaceAll("");
|
htmlStr = mSpace.replaceAll("");
|
||||||
|
|
||||||
}
|
}
|
||||||
if (htmlStr.indexOf("/*") > -1 && htmlStr.indexOf("*/") > -1) {
|
assert htmlStr != null;
|
||||||
String commentstr = htmlStr.substring(htmlStr.trim().indexOf("/*"), htmlStr.indexOf("*/") + 2);
|
if (htmlStr.contains("/*") && htmlStr.contains("*/")) {
|
||||||
// 去注释
|
String commentstr = htmlStr.substring(htmlStr.trim().indexOf("/*"), htmlStr.indexOf("*/") + 2);
|
||||||
scriptstr = htmlStr.replace(commentstr, "");
|
// 去注释
|
||||||
} else {
|
scriptstr = htmlStr.replace(commentstr, "");
|
||||||
scriptstr = htmlStr;
|
} else {
|
||||||
}
|
scriptstr = htmlStr;
|
||||||
// 去掉字符串前后的空格
|
}
|
||||||
scriptstr = trimInnerSpaceStr(scriptstr);
|
// 去掉字符串前后的空格
|
||||||
// 替换空格转义
|
scriptstr = trimInnerSpaceStr(scriptstr);
|
||||||
scriptstr = scriptstr.replaceAll(" ", " ");
|
// 替换空格转义
|
||||||
// 转义双引号
|
scriptstr = scriptstr.replaceAll(" ", " ");
|
||||||
scriptstr = scriptstr.replaceAll(""", "\"");
|
// 转义双引号
|
||||||
// 转义单引号
|
scriptstr = scriptstr.replaceAll(""", "\"");
|
||||||
scriptstr = scriptstr.replaceAll("'", "\'");
|
// 转义单引号
|
||||||
// 转义链接符
|
scriptstr = scriptstr.replaceAll("'", "'");
|
||||||
scriptstr = scriptstr.replaceAll("&", "&");
|
// 转义链接符
|
||||||
scriptstr = scriptstr.replaceAll("<", "<");
|
scriptstr = scriptstr.replaceAll("&", "&");
|
||||||
scriptstr = scriptstr.replaceAll(">", ">");
|
scriptstr = scriptstr.replaceAll("<", "<");
|
||||||
|
scriptstr = scriptstr.replaceAll(">", ">");
|
||||||
return scriptstr;
|
|
||||||
}
|
return scriptstr;
|
||||||
|
}
|
||||||
/***
|
|
||||||
* 去掉字符串前后的空格,中间的空格保留
|
/***
|
||||||
*
|
* 去掉字符串前后的空格,中间的空格保留
|
||||||
* @param str
|
*
|
||||||
* @return
|
* @param str 原始字符串
|
||||||
*/
|
* @return 返回去除结果
|
||||||
public static String trimInnerSpaceStr(String str) {
|
*/
|
||||||
str = str.trim();
|
public static String trimInnerSpaceStr(String str) {
|
||||||
while (str.startsWith(" ")) {
|
str = str.trim();
|
||||||
str = str.substring(1, str.length()).trim();
|
while (str.startsWith(" ")) {
|
||||||
}
|
str = str.substring(1).trim();
|
||||||
while (str.startsWith(" ")) {
|
}
|
||||||
str = str.substring(6, str.length()).trim();
|
while (str.startsWith(" ")) {
|
||||||
}
|
str = str.substring(6).trim();
|
||||||
while (str.endsWith(" ")) {
|
}
|
||||||
str = str.substring(0, str.length() - 1).trim();
|
while (str.endsWith(" ")) {
|
||||||
}
|
str = str.substring(0, str.length() - 1).trim();
|
||||||
while (str.endsWith(" ")) {
|
}
|
||||||
str = str.substring(0, str.length() - 6).trim();
|
while (str.endsWith(" ")) {
|
||||||
}
|
str = str.substring(0, str.length() - 6).trim();
|
||||||
return str;
|
}
|
||||||
}
|
return str;
|
||||||
|
}
|
||||||
public static void main(String[] args) {
|
|
||||||
// TODO Auto-generated method stub
|
public static void main(String[] args) {
|
||||||
}
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,60 +1,61 @@
|
||||||
package luckyclient.execution.webdriver.ex;
|
package luckyclient.execution.webdriver.ex;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
|
|
||||||
import luckyclient.execution.httpinterface.TestControl;
|
import luckyclient.execution.httpinterface.TestControl;
|
||||||
import luckyclient.execution.webdriver.WebDriverInitialization;
|
import luckyclient.execution.webdriver.WebDriverInitialization;
|
||||||
import luckyclient.remote.api.GetServerApi;
|
import luckyclient.remote.api.GetServerApi;
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.ProjectCase;
|
||||||
import luckyclient.remote.entity.ProjectCaseParams;
|
import luckyclient.remote.entity.ProjectCaseParams;
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
import luckyclient.remote.entity.ProjectCaseSteps;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
||||||
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
* @date 2017年12月1日 上午9:29:40
|
* @date 2017年12月1日 上午9:29:40
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class WebOneCaseExecute{
|
public class WebOneCaseExecute{
|
||||||
|
|
||||||
public static void oneCaseExecuteForTast(String projectname,Integer caseId,int version,String taskid){
|
public static void oneCaseExecuteForTast(Integer caseId, String taskid){
|
||||||
//记录日志到数据库
|
//记录日志到数据库
|
||||||
serverOperation.exetype = 0;
|
serverOperation.exetype = 0;
|
||||||
TestControl.TASKID = taskid;
|
TestControl.TASKID = taskid;
|
||||||
int drivertype = serverOperation.querydrivertype(taskid);
|
int drivertype = serverOperation.querydrivertype(taskid);
|
||||||
WebDriver wd = null;
|
WebDriver wd = null;
|
||||||
try {
|
try {
|
||||||
wd = WebDriverInitialization.setWebDriverForTask(drivertype);
|
wd = WebDriverInitialization.setWebDriverForTask(drivertype);
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
LogUtil.APP.error("初始化WebDriver出错!", e1);
|
LogUtil.APP.error("初始化WebDriver出错!", e1);
|
||||||
}
|
}
|
||||||
serverOperation caselog = new serverOperation();
|
serverOperation caselog = new serverOperation();
|
||||||
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(caseId);
|
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(caseId);
|
||||||
//删除旧的日志
|
//删除旧的日志
|
||||||
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
serverOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
|
||||||
|
|
||||||
List<ProjectCaseParams> pcplist=GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
|
List<ProjectCaseParams> pcplist=GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
|
||||||
LogUtil.APP.info("开始执行用例:【{}】......",testcase.getCaseSign());
|
LogUtil.APP.info("开始执行用例:【{}】......",testcase.getCaseSign());
|
||||||
try {
|
try {
|
||||||
List<ProjectCaseSteps> steps=GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
List<ProjectCaseSteps> steps=GetServerApi.getStepsbycaseid(testcase.getCaseId());
|
||||||
WebCaseExecution.caseExcution(testcase, steps, taskid,wd,caselog,pcplist);
|
WebCaseExecution.caseExcution(testcase, steps, taskid,wd,caselog,pcplist);
|
||||||
LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
|
LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
|
||||||
} catch (InterruptedException e) {
|
} catch (Exception e) {
|
||||||
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
LogUtil.APP.error("用户执行过程中抛出异常!", e);
|
||||||
}
|
}
|
||||||
serverOperation.updateTaskExecuteData(taskid, 0,2);
|
serverOperation.updateTaskExecuteData(taskid, 0,2);
|
||||||
//关闭浏览器
|
//关闭浏览器
|
||||||
wd.quit();
|
assert wd != null;
|
||||||
}
|
wd.quit();
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
|
@ -41,18 +41,14 @@ public class Ocr {
|
||||||
/**
|
/**
|
||||||
* 批处理文件路径
|
* 批处理文件路径
|
||||||
*/
|
*/
|
||||||
private static String cmdpath = System.getProperty("user.dir");
|
private static String cmdpath = System.getProperty("user.dir");
|
||||||
/**
|
|
||||||
* 默认把截图放在C盘根目录
|
|
||||||
*/
|
|
||||||
private static String cmdname = "handlingCAPTCHA.bat";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取生成的TXT文件中的验证码
|
* 读取生成的TXT文件中的验证码
|
||||||
* @return
|
* @return 返回结果
|
||||||
*/
|
*/
|
||||||
private static String readTextFile() {
|
private static String readTextFile() {
|
||||||
String lineTxt = "";
|
String lineTxt;
|
||||||
try {
|
try {
|
||||||
String encoding = "GBK";
|
String encoding = "GBK";
|
||||||
File file = new File(readtextpath);
|
File file = new File(readtextpath);
|
||||||
|
@ -77,8 +73,8 @@ public class Ocr {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 截取验证码位置的图片
|
* 截取验证码位置的图片
|
||||||
*
|
* @param driver webDriver驱动
|
||||||
* @param
|
* @param element 对象定位
|
||||||
*/
|
*/
|
||||||
private static void screenShotForElement(WebDriver driver, WebElement element){
|
private static void screenShotForElement(WebDriver driver, WebElement element){
|
||||||
driver = new Augmenter().augment(driver);
|
driver = new Augmenter().augment(driver);
|
||||||
|
@ -106,10 +102,12 @@ public class Ocr {
|
||||||
|
|
||||||
|
|
||||||
public static String getCAPTCHA(WebDriver driver, WebElement element) {
|
public static String getCAPTCHA(WebDriver driver, WebElement element) {
|
||||||
String code = "";
|
String code;
|
||||||
screenShotForElement(driver, element);
|
screenShotForElement(driver, element);
|
||||||
Runtime run = Runtime.getRuntime();
|
Runtime run = Runtime.getRuntime();
|
||||||
try {
|
try {
|
||||||
|
//默认把截图放在C盘根目录
|
||||||
|
String cmdname = "handlingCAPTCHA.bat";
|
||||||
run.exec("cmd.exe /k start " + cmdname, null, new File(cmdpath));
|
run.exec("cmd.exe /k start " + cmdname, null, new File(cmdpath));
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
|
@ -125,9 +123,5 @@ public class Ocr {
|
||||||
}*/
|
}*/
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException, InterruptedException {
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -51,8 +51,6 @@ public class ClientHandler extends ChannelHandlerAdapter {
|
||||||
|
|
||||||
private static final String SERVER_PORT = SysConfig.getConfiguration().getProperty("server.web.port");
|
private static final String SERVER_PORT = SysConfig.getConfiguration().getProperty("server.web.port");
|
||||||
|
|
||||||
private int byteRead;
|
|
||||||
|
|
||||||
|
|
||||||
private volatile int lastLength = 0;
|
private volatile int lastLength = 0;
|
||||||
|
|
||||||
|
@ -61,15 +59,15 @@ public class ClientHandler extends ChannelHandlerAdapter {
|
||||||
|
|
||||||
private static ChannelHandlerContext ctx;
|
private static ChannelHandlerContext ctx;
|
||||||
|
|
||||||
public ClientHandler() throws IOException {
|
public ClientHandler() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws UnsupportedEncodingException, InterruptedException {
|
public void channelRead(ChannelHandlerContext ctx, Object msg) throws UnsupportedEncodingException {
|
||||||
//统一转编码
|
//统一转编码
|
||||||
String jsonStr = URLDecoder.decode(msg.toString(), "GBK");
|
String jsonStr = URLDecoder.decode(msg.toString(), "GBK");
|
||||||
//服务端消息处理,如果接收到测试任务方法,则直接产生一个http请求并发送请求到本地
|
//服务端消息处理,如果接收到测试任务方法,则直接产生一个http请求并发送请求到本地
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json;
|
||||||
try {
|
try {
|
||||||
json = JSON.parseObject(jsonStr);
|
json = JSON.parseObject(jsonStr);
|
||||||
|
|
||||||
|
@ -80,41 +78,37 @@ public class ClientHandler extends ChannelHandlerAdapter {
|
||||||
log.info("收到服务端消息:" + json.toString());
|
log.info("收到服务端消息:" + json.toString());
|
||||||
//解析消息
|
//解析消息
|
||||||
if ("run".equals(json.get("method"))) {
|
if ("run".equals(json.get("method"))) {
|
||||||
try {
|
//返回请求
|
||||||
//返回请求
|
JSONObject re = new JSONObject();
|
||||||
JSONObject re = new JSONObject();
|
re.put("method", "return");
|
||||||
re.put("method", "return");
|
Result result = new Result(1, "同步等待消息返回", json.get("uuid").toString(), null);
|
||||||
Result result = new Result(1, "同步等待消息返回", json.get("uuid").toString(), null);
|
//如果是调度请求,则发起一个HTTP请求
|
||||||
//如果是调度请求,则发起一个HTTP请求
|
//获取是get方法还是post方法
|
||||||
//获取是get方法还是post方法
|
String getOrPost = json.get("getOrPost").toString();
|
||||||
String getOrPost = json.get("getOrPost").toString();
|
String urlParam = "http://127.0.0.1:" + port + "/" + json.get("url").toString();
|
||||||
String urlParam = "http://127.0.0.1:" + port + "/" + json.get("url").toString();
|
Integer socketTimeout = Integer.valueOf(json.get("socketTimeout").toString());
|
||||||
Integer socketTimeout = Integer.valueOf(json.get("socketTimeout").toString());
|
String tmpResult = "";
|
||||||
String tmpResult = "";
|
if ("get".equals(getOrPost)) {
|
||||||
if ("get".equals(getOrPost)) {
|
@SuppressWarnings("unchecked")
|
||||||
@SuppressWarnings("unchecked")
|
Map<String, Object> jsonparams = (Map<String, Object>) json.get("data");
|
||||||
Map<String, Object> jsonparams = (Map<String, Object>) json.get("data");
|
//get方法
|
||||||
//get方法
|
try {
|
||||||
try {
|
tmpResult = HttpRequest.httpClientGet(urlParam, jsonparams, socketTimeout);
|
||||||
tmpResult = HttpRequest.httpClientGet(urlParam, jsonparams, socketTimeout);
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
log.error("转发服务端GET请求出错");
|
||||||
log.error("转发服务端GET请求出错");
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
String jsonparams = json.get("data").toString();
|
||||||
String jsonparams = json.get("data").toString();
|
//post方法
|
||||||
//post方法
|
try {
|
||||||
try {
|
tmpResult = HttpRequest.httpClientPost(urlParam, jsonparams, socketTimeout);
|
||||||
tmpResult = HttpRequest.httpClientPost(urlParam, jsonparams, socketTimeout);
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
log.error("转发服务端POST请求出错");
|
||||||
log.error("转发服务端POST请求出错");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
result.setMessage(tmpResult);
|
|
||||||
re.put("data", result);
|
|
||||||
sendMessage(re.toString());
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
result.setMessage(tmpResult);
|
||||||
|
re.put("data", result);
|
||||||
|
sendMessage(re.toString());
|
||||||
} else if ("download".equals(json.get("method"))) {
|
} else if ("download".equals(json.get("method"))) {
|
||||||
String loadpath = json.get("path").toString();
|
String loadpath = json.get("path").toString();
|
||||||
String path = System.getProperty("user.dir") + loadpath;
|
String path = System.getProperty("user.dir") + loadpath;
|
||||||
|
@ -147,7 +141,7 @@ public class ClientHandler extends ChannelHandlerAdapter {
|
||||||
String fileName = jsonparams.get("imgName").toString();
|
String fileName = jsonparams.get("imgName").toString();
|
||||||
String ctxPath = System.getProperty("user.dir") + File.separator + "log" + File.separator + "ScreenShot" + File.separator + fileName;
|
String ctxPath = System.getProperty("user.dir") + File.separator + "log" + File.separator + "ScreenShot" + File.separator + fileName;
|
||||||
File file = new File(ctxPath);
|
File file = new File(ctxPath);
|
||||||
int start = Integer.valueOf(json.get("start").toString());
|
int start = Integer.parseInt(json.get("start").toString());
|
||||||
FileUploadFile fileUploadFile = new FileUploadFile();
|
FileUploadFile fileUploadFile = new FileUploadFile();
|
||||||
fileUploadFile.setFile(file);
|
fileUploadFile.setFile(file);
|
||||||
if (start != -1) {
|
if (start != -1) {
|
||||||
|
@ -164,6 +158,7 @@ public class ClientHandler extends ChannelHandlerAdapter {
|
||||||
log.info("文件长度:" + (randomAccessFile.length()) + ",start:" + start + ",a:" + a + ",b:" + b + ",lastLength:" + lastLength);
|
log.info("文件长度:" + (randomAccessFile.length()) + ",start:" + start + ",a:" + a + ",b:" + b + ",lastLength:" + lastLength);
|
||||||
byte[] bytes = new byte[lastLength];
|
byte[] bytes = new byte[lastLength];
|
||||||
log.info("bytes的长度是=" + bytes.length);
|
log.info("bytes的长度是=" + bytes.length);
|
||||||
|
int byteRead;
|
||||||
if ((byteRead = randomAccessFile.read(bytes)) != -1 && (randomAccessFile.length() - start) > 0) {
|
if ((byteRead = randomAccessFile.read(bytes)) != -1 && (randomAccessFile.length() - start) > 0) {
|
||||||
log.info("byteRead = " + byteRead);
|
log.info("byteRead = " + byteRead);
|
||||||
fileUploadFile.setEndPos(byteRead);
|
fileUploadFile.setEndPos(byteRead);
|
||||||
|
@ -209,7 +204,7 @@ public class ClientHandler extends ChannelHandlerAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
public void channelActive(ChannelHandlerContext ctx) {
|
||||||
//发送客户端登录消息
|
//发送客户端登录消息
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("hostName", NETTY_HOST);
|
json.put("hostName", NETTY_HOST);
|
||||||
|
@ -226,14 +221,11 @@ public class ClientHandler extends ChannelHandlerAdapter {
|
||||||
log.info("连接已断开,正在尝试重连...");
|
log.info("连接已断开,正在尝试重连...");
|
||||||
//使用过程中断线重连
|
//使用过程中断线重连
|
||||||
final EventLoop eventLoop = ctx.channel().eventLoop();
|
final EventLoop eventLoop = ctx.channel().eventLoop();
|
||||||
eventLoop.schedule(new Runnable() {
|
eventLoop.schedule(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
NettyClient.start();
|
||||||
try {
|
} catch (Exception e) {
|
||||||
NettyClient.start();
|
log.error("链接出现异常,正在尝试重连...",e);
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, 1, TimeUnit.SECONDS);
|
}, 1, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
@ -252,7 +244,7 @@ public class ClientHandler extends ChannelHandlerAdapter {
|
||||||
if (evt instanceof IdleStateEvent) {
|
if (evt instanceof IdleStateEvent) {
|
||||||
IdleStateEvent event = (IdleStateEvent) evt;
|
IdleStateEvent event = (IdleStateEvent) evt;
|
||||||
if (event.state().equals(IdleState.READER_IDLE)) {
|
if (event.state().equals(IdleState.READER_IDLE)) {
|
||||||
/**发送心跳,保持长连接*/
|
//发送心跳,保持长连接
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("method", "ping");
|
json.put("method", "ping");
|
||||||
json.put("hostName", NETTY_HOST);
|
json.put("hostName", NETTY_HOST);
|
||||||
|
@ -264,7 +256,7 @@ public class ClientHandler extends ChannelHandlerAdapter {
|
||||||
super.userEventTriggered(ctx, evt);
|
super.userEventTriggered(ctx, evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendMessage(String json) throws InterruptedException {
|
public static void sendMessage(String json) {
|
||||||
ctx.channel().writeAndFlush(Unpooled.copiedBuffer((json + "$_").getBytes()));
|
ctx.channel().writeAndFlush(Unpooled.copiedBuffer((json + "$_").getBytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
package luckyclient.netty;
|
package luckyclient.netty;
|
||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.NoHttpResponseException;
|
|
||||||
import org.apache.http.client.config.RequestConfig;
|
import org.apache.http.client.config.RequestConfig;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.conn.HttpHostConnectException;
|
|
||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
@ -19,9 +17,7 @@ import java.net.ConnectException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.KeyManagementException;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
@ -29,19 +25,15 @@ public class HttpRequest {
|
||||||
private static final Logger log = LoggerFactory.getLogger(HttpRequest.class);
|
private static final Logger log = LoggerFactory.getLogger(HttpRequest.class);
|
||||||
/**
|
/**
|
||||||
* 使用HttpClient以JSON格式发送post请求
|
* 使用HttpClient以JSON格式发送post请求
|
||||||
* @param urlParam
|
* @param urlParam 请求地址
|
||||||
* @param jsonparams
|
* @param jsonparams 请求参数
|
||||||
* @param socketTimeout
|
* @param socketTimeout 超时时间
|
||||||
* @return
|
* @return 返回请求结果
|
||||||
* @throws NoSuchAlgorithmException
|
|
||||||
* @throws KeyManagementException
|
|
||||||
* @throws UnsupportedEncodingException
|
|
||||||
* @throws IOException
|
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年5月14日
|
* @date 2019年5月14日
|
||||||
*/
|
*/
|
||||||
public static String httpClientPost(String urlParam,String jsonparams,Integer socketTimeout) throws NoSuchAlgorithmException, KeyManagementException, UnsupportedEncodingException, IOException{
|
public static String httpClientPost(String urlParam,String jsonparams,Integer socketTimeout) throws IOException{
|
||||||
StringBuffer resultBuffer = null;
|
StringBuffer resultBuffer;
|
||||||
CloseableHttpClient httpclient= HttpClients.createDefault();
|
CloseableHttpClient httpclient= HttpClients.createDefault();
|
||||||
HttpPost httpPost = new HttpPost(urlParam);
|
HttpPost httpPost = new HttpPost(urlParam);
|
||||||
RequestConfig requestConfig = RequestConfig.custom()
|
RequestConfig requestConfig = RequestConfig.custom()
|
||||||
|
@ -62,7 +54,7 @@ public class HttpRequest {
|
||||||
// 读取服务器响应数据
|
// 读取服务器响应数据
|
||||||
resultBuffer = new StringBuffer();
|
resultBuffer = new StringBuffer();
|
||||||
if(null!=response.getEntity()){
|
if(null!=response.getEntity()){
|
||||||
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "utf-8"));
|
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8));
|
||||||
String temp;
|
String temp;
|
||||||
while ((temp = br.readLine()) != null) {
|
while ((temp = br.readLine()) != null) {
|
||||||
resultBuffer.append(temp);
|
resultBuffer.append(temp);
|
||||||
|
@ -79,8 +71,7 @@ public class HttpRequest {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
br = null;
|
log.error("关闭流出现异常...",e);
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,22 +80,19 @@ public class HttpRequest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用HttpClient以JSON格式发送get请求
|
* 使用HttpClient以JSON格式发送get请求
|
||||||
* @param urlParam
|
* @param urlParam 请求地址
|
||||||
* @param params
|
* @param params 请求参数
|
||||||
* @param socketTimeout
|
* @param socketTimeout 超时时间
|
||||||
* @return
|
* @return 返回请求结果
|
||||||
* @throws NoSuchAlgorithmException
|
|
||||||
* @throws KeyManagementException
|
|
||||||
* @throws NoHttpResponseException
|
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年5月14日
|
* @date 2019年5月14日
|
||||||
*/
|
*/
|
||||||
public static String httpClientGet(String urlParam, Map<String, Object> params,Integer socketTimeout) throws NoSuchAlgorithmException, KeyManagementException, NoHttpResponseException {
|
public static String httpClientGet(String urlParam, Map<String, Object> params,Integer socketTimeout) {
|
||||||
StringBuffer resultBuffer = null;
|
StringBuffer resultBuffer;
|
||||||
CloseableHttpClient httpclient= HttpClients.createDefault();
|
CloseableHttpClient httpclient= HttpClients.createDefault();
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
// 构建请求参数
|
// 构建请求参数
|
||||||
StringBuffer sbParams = new StringBuffer();
|
StringBuilder sbParams = new StringBuilder();
|
||||||
if (params != null && params.size() > 0) {
|
if (params != null && params.size() > 0) {
|
||||||
for (Entry<String, Object> entry : params.entrySet()) {
|
for (Entry<String, Object> entry : params.entrySet()) {
|
||||||
sbParams.append(entry.getKey());
|
sbParams.append(entry.getKey());
|
||||||
|
@ -117,7 +105,7 @@ public class HttpRequest {
|
||||||
sbParams.append("&");
|
sbParams.append("&");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sbParams != null && sbParams.length() > 0) {
|
if (sbParams.length() > 0) {
|
||||||
urlParam = urlParam + "?" + sbParams.substring(0, sbParams.length() - 1);
|
urlParam = urlParam + "?" + sbParams.substring(0, sbParams.length() - 1);
|
||||||
}
|
}
|
||||||
HttpGet httpGet = new HttpGet(urlParam);
|
HttpGet httpGet = new HttpGet(urlParam);
|
||||||
|
@ -129,7 +117,7 @@ public class HttpRequest {
|
||||||
CloseableHttpResponse response = httpclient.execute(httpGet);
|
CloseableHttpResponse response = httpclient.execute(httpGet);
|
||||||
|
|
||||||
// 读取服务器响应数据
|
// 读取服务器响应数据
|
||||||
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "utf-8"));
|
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8));
|
||||||
String temp;
|
String temp;
|
||||||
resultBuffer = new StringBuffer();
|
resultBuffer = new StringBuffer();
|
||||||
while ((temp = br.readLine()) != null) {
|
while ((temp = br.readLine()) != null) {
|
||||||
|
@ -142,8 +130,7 @@ public class HttpRequest {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
br = null;
|
log.error("关闭流出现异常...",e);
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,18 +140,15 @@ public class HttpRequest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传文件
|
* 上传文件
|
||||||
* @param urlParam
|
* @param urlParam 请求地址
|
||||||
* @param loadpath
|
* @param loadpath 文件加载路径
|
||||||
* @param file
|
* @param file 文件对象
|
||||||
* @return
|
* @return 返回上传结果
|
||||||
* @throws NoSuchAlgorithmException
|
|
||||||
* @throws KeyManagementException
|
|
||||||
* @throws HttpHostConnectException
|
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年3月15日
|
* @date 2019年3月15日
|
||||||
*/
|
*/
|
||||||
public static String httpClientUploadFile(String urlParam, String loadpath, File file) throws NoSuchAlgorithmException, KeyManagementException, HttpHostConnectException {
|
public static String httpClientUploadFile(String urlParam, String loadpath, File file) {
|
||||||
StringBuffer resultBuffer = null;
|
StringBuffer resultBuffer;
|
||||||
CloseableHttpClient httpclient= HttpClients.createDefault();
|
CloseableHttpClient httpclient= HttpClients.createDefault();
|
||||||
HttpPost httpPost = new HttpPost(urlParam);
|
HttpPost httpPost = new HttpPost(urlParam);
|
||||||
// 构建请求参数
|
// 构建请求参数
|
||||||
|
@ -172,7 +156,7 @@ public class HttpRequest {
|
||||||
try {
|
try {
|
||||||
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
|
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
|
||||||
//设置请求的编码格式
|
//设置请求的编码格式
|
||||||
entityBuilder.setCharset(Charset.forName("utf-8"));
|
entityBuilder.setCharset(StandardCharsets.UTF_8);
|
||||||
entityBuilder.addBinaryBody("jarfile", file);
|
entityBuilder.addBinaryBody("jarfile", file);
|
||||||
entityBuilder.addTextBody("loadpath", loadpath);
|
entityBuilder.addTextBody("loadpath", loadpath);
|
||||||
HttpEntity reqEntity =entityBuilder.build();
|
HttpEntity reqEntity =entityBuilder.build();
|
||||||
|
@ -184,13 +168,13 @@ public class HttpRequest {
|
||||||
// 读取服务器响应数据
|
// 读取服务器响应数据
|
||||||
resultBuffer = new StringBuffer();
|
resultBuffer = new StringBuffer();
|
||||||
|
|
||||||
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "utf-8"));
|
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8));
|
||||||
String temp;
|
String temp;
|
||||||
while ((temp = br.readLine()) != null) {
|
while ((temp = br.readLine()) != null) {
|
||||||
resultBuffer.append(temp);
|
resultBuffer.append(temp);
|
||||||
}
|
}
|
||||||
if(resultBuffer.length()==0){
|
if(resultBuffer.length()==0){
|
||||||
resultBuffer.append("上传文件异常,响应码:"+responsecode);
|
resultBuffer.append("上传文件异常,响应码:").append(responsecode);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -199,8 +183,7 @@ public class HttpRequest {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
br = null;
|
log.error("关闭流出现异常...",e);
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,17 +192,15 @@ public class HttpRequest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文件流
|
* 获取文件流
|
||||||
* @param urlParam
|
* @param urlParam 请求地址
|
||||||
* @param params
|
* @param params 请求参数
|
||||||
* @return
|
* @return 返回获取到的文件流
|
||||||
* @throws IOException
|
|
||||||
* @throws HttpHostConnectException
|
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年3月15日
|
* @date 2019年3月15日
|
||||||
*/
|
*/
|
||||||
public static byte[] getFile(String urlParam, Map<String, Object> params) throws IOException, HttpHostConnectException {
|
public static byte[] getFile(String urlParam, Map<String, Object> params) throws IOException {
|
||||||
// 构建请求参数
|
// 构建请求参数
|
||||||
StringBuffer sbParams = new StringBuffer();
|
StringBuilder sbParams = new StringBuilder();
|
||||||
if (params != null && params.size() > 0) {
|
if (params != null && params.size() > 0) {
|
||||||
for (Entry<String, Object> entry : params.entrySet()) {
|
for (Entry<String, Object> entry : params.entrySet()) {
|
||||||
sbParams.append(entry.getKey());
|
sbParams.append(entry.getKey());
|
||||||
|
@ -232,7 +213,7 @@ public class HttpRequest {
|
||||||
sbParams.append("&");
|
sbParams.append("&");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sbParams != null && sbParams.length() > 0) {
|
if (sbParams.length() > 0) {
|
||||||
urlParam = urlParam + "?" + sbParams.substring(0, sbParams.length() - 1);
|
urlParam = urlParam + "?" + sbParams.substring(0, sbParams.length() - 1);
|
||||||
}
|
}
|
||||||
URL urlConet = new URL(urlParam);
|
URL urlConet = new URL(urlParam);
|
||||||
|
@ -242,23 +223,21 @@ public class HttpRequest {
|
||||||
InputStream inStream = con .getInputStream(); //通过输入流获取图片数据
|
InputStream inStream = con .getInputStream(); //通过输入流获取图片数据
|
||||||
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
||||||
byte[] buffer = new byte[2048];
|
byte[] buffer = new byte[2048];
|
||||||
int len = 0;
|
int len;
|
||||||
while( (len=inStream.read(buffer)) != -1 ){
|
while( (len=inStream.read(buffer)) != -1 ){
|
||||||
outStream.write(buffer, 0, len);
|
outStream.write(buffer, 0, len);
|
||||||
}
|
}
|
||||||
inStream.close();
|
inStream.close();
|
||||||
byte[] data = outStream.toByteArray();
|
return outStream.toByteArray();
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从网络Url中下载文件
|
* 从网络Url中下载文件
|
||||||
* @param urlStr
|
* @param urlStr 请求地址
|
||||||
* @param fileName
|
* @param fileName 文件名
|
||||||
* @param savePath
|
* @param savePath 保存路径
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
public static boolean downLoadFromUrl(String urlStr,String fileName,String savePath) throws IOException{
|
public static void downLoadFromUrl(String urlStr, String fileName, String savePath) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
URL url = new URL(urlStr);
|
URL url = new URL(urlStr);
|
||||||
|
@ -281,28 +260,21 @@ public class HttpRequest {
|
||||||
File file = new File(saveDir+File.separator+fileName);
|
File file = new File(saveDir+File.separator+fileName);
|
||||||
FileOutputStream fos = new FileOutputStream(file);
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
fos.write(getData);
|
fos.write(getData);
|
||||||
if(fos!=null){
|
fos.close();
|
||||||
fos.close();
|
inputStream.close();
|
||||||
}
|
|
||||||
if(inputStream!=null){
|
|
||||||
inputStream.close();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从输入流中获取字节数组
|
* 从输入流中获取字节数组
|
||||||
* @param inputStream
|
* @param inputStream 字节流
|
||||||
* @return
|
* @return 返回字节
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
public static byte[] readInputStream(InputStream inputStream) throws IOException {
|
public static byte[] readInputStream(InputStream inputStream) throws IOException {
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
int len = 0;
|
int len;
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
while((len = inputStream.read(buffer)) != -1) {
|
while((len = inputStream.read(buffer)) != -1) {
|
||||||
bos.write(buffer, 0, len);
|
bos.write(buffer, 0, len);
|
||||||
|
|
|
@ -1,23 +1,9 @@
|
||||||
package luckyclient.netty;
|
package luckyclient.netty;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.*;
|
||||||
import io.netty.channel.ChannelFuture;
|
|
||||||
import io.netty.channel.ChannelFutureListener;
|
|
||||||
import io.netty.channel.ChannelInitializer;
|
|
||||||
import io.netty.channel.ChannelOption;
|
|
||||||
import io.netty.channel.ChannelPipeline;
|
|
||||||
import io.netty.channel.EventLoop;
|
|
||||||
import io.netty.channel.EventLoopGroup;
|
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
|
@ -26,6 +12,12 @@ import io.netty.handler.codec.string.StringDecoder;
|
||||||
import io.netty.handler.codec.string.StringEncoder;
|
import io.netty.handler.codec.string.StringEncoder;
|
||||||
import io.netty.handler.timeout.IdleStateHandler;
|
import io.netty.handler.timeout.IdleStateHandler;
|
||||||
import luckyclient.utils.config.SysConfig;
|
import luckyclient.utils.config.SysConfig;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class NettyClient {
|
public class NettyClient {
|
||||||
private static final String NETTY_SERVER_IP= SysConfig.getConfiguration().getProperty("server.web.ip");
|
private static final String NETTY_SERVER_IP= SysConfig.getConfiguration().getProperty("server.web.ip");
|
||||||
|
@ -34,61 +26,46 @@ public class NettyClient {
|
||||||
|
|
||||||
protected static Channel channel;
|
protected static Channel channel;
|
||||||
|
|
||||||
private static ChannelFuture connect;
|
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(NettyClient.class);
|
private static final Logger log = LoggerFactory.getLogger(NettyClient.class);
|
||||||
|
|
||||||
private static ClientHandler clientHandler;
|
private static ClientHandler clientHandler;
|
||||||
public static void start() throws InterruptedException{
|
public static void start() {
|
||||||
EventLoopGroup group = new NioEventLoopGroup();
|
EventLoopGroup group = new NioEventLoopGroup();
|
||||||
try {
|
Bootstrap b = new Bootstrap();
|
||||||
Bootstrap b = new Bootstrap();
|
clientHandler=new ClientHandler();
|
||||||
clientHandler=new ClientHandler();
|
b.group(group)
|
||||||
b.group(group)
|
.channel(NioSocketChannel.class)
|
||||||
.channel(NioSocketChannel.class)
|
.option(ChannelOption.SO_KEEPALIVE,true)
|
||||||
.option(ChannelOption.SO_KEEPALIVE,true)
|
.handler(new ChannelInitializer<SocketChannel>() {
|
||||||
.handler(new ChannelInitializer<SocketChannel>() {
|
@Override
|
||||||
@Override
|
public void initChannel(SocketChannel ch) {
|
||||||
public void initChannel(SocketChannel ch) throws Exception {
|
ByteBuf delimiter = Unpooled.copiedBuffer("$_".getBytes());
|
||||||
ByteBuf delimiter = Unpooled.copiedBuffer("$_".getBytes());
|
ChannelPipeline p = ch.pipeline();
|
||||||
ChannelPipeline p = ch.pipeline();
|
p.addLast(new DelimiterBasedFrameDecoder(1024, delimiter));
|
||||||
p.addLast(new DelimiterBasedFrameDecoder(1024, delimiter));
|
p.addLast("decoder", new StringDecoder(StandardCharsets.UTF_8));
|
||||||
p.addLast("decoder", new StringDecoder(Charset.forName("UTF-8")));
|
p.addLast("encoder", new StringEncoder(Charset.forName("GBK")));
|
||||||
p.addLast("encoder", new StringEncoder(Charset.forName("GBK")));
|
p.addLast(new IdleStateHandler(1,0,0,TimeUnit.SECONDS));
|
||||||
p.addLast(new IdleStateHandler(1,0,0,TimeUnit.SECONDS));
|
p.addLast(clientHandler);
|
||||||
p.addLast(clientHandler);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
//连接服务端
|
|
||||||
connect = b.connect(NETTY_SERVER_IP, NETTY_SERVER_PORT);
|
|
||||||
//断线重连
|
|
||||||
connect.addListener(new ChannelFutureListener() {
|
|
||||||
@Override
|
|
||||||
public void operationComplete(ChannelFuture channelFuture) throws Exception {
|
|
||||||
if (!channelFuture.isSuccess()) {
|
|
||||||
final EventLoop loop = channelFuture.channel().eventLoop();
|
|
||||||
loop.schedule(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
log.error("服务端链接不上,开始重连操作...");
|
|
||||||
start();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 1L, TimeUnit.SECONDS);
|
|
||||||
} else {
|
|
||||||
channel = channelFuture.channel();
|
|
||||||
log.info("服务端链接成功...");
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
//连接服务端
|
||||||
} catch (IOException e) {
|
ChannelFuture connect = b.connect(NETTY_SERVER_IP, NETTY_SERVER_PORT);
|
||||||
e.printStackTrace();
|
//断线重连
|
||||||
} finally {
|
connect.addListener((ChannelFutureListener) channelFuture -> {
|
||||||
//不关闭通道
|
if (!channelFuture.isSuccess()) {
|
||||||
//group.shutdownGracefully();
|
final EventLoop loop = channelFuture.channel().eventLoop();
|
||||||
}
|
loop.schedule(() -> {
|
||||||
|
try {
|
||||||
|
log.error("服务端链接不上,开始重连操作...");
|
||||||
|
start();
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}, 1L, TimeUnit.SECONDS);
|
||||||
|
} else {
|
||||||
|
channel = channelFuture.channel();
|
||||||
|
log.info("服务端链接成功...");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,12 @@
|
||||||
package luckyclient.remote.api;
|
package luckyclient.remote.api;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
import luckyclient.execution.dispose.ParamsManageForSteps;
|
import luckyclient.execution.dispose.ParamsManageForSteps;
|
||||||
import luckyclient.remote.entity.ProjectCase;
|
import luckyclient.remote.entity.*;
|
||||||
import luckyclient.remote.entity.ProjectCaseParams;
|
|
||||||
import luckyclient.remote.entity.ProjectCaseSteps;
|
|
||||||
import luckyclient.remote.entity.ProjectProtocolTemplate;
|
|
||||||
import luckyclient.remote.entity.ProjectTemplateParams;
|
|
||||||
import luckyclient.remote.entity.TaskExecute;
|
|
||||||
import luckyclient.remote.entity.TaskScheduling;
|
|
||||||
import luckyclient.utils.httputils.HttpRequest;
|
import luckyclient.utils.httputils.HttpRequest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
|
@ -33,85 +25,78 @@ public class GetServerApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过计划ID获取测试用例对象集
|
* 通过计划ID获取测试用例对象集
|
||||||
* @param planId
|
* @param planId 测试计划ID
|
||||||
* @return
|
* @return 返回用例List
|
||||||
*/
|
*/
|
||||||
public static List<ProjectCase> getCasesbyplanId(int planId) {
|
public static List<ProjectCase> getCasesbyplanId(int planId) {
|
||||||
String result = HttpRequest.loadJSON(PREFIX+"/clientGetCaseListByPlanId.do?planId=" + planId);
|
String result = HttpRequest.loadJSON(PREFIX+"/clientGetCaseListByPlanId.do?planId=" + planId);
|
||||||
List<ProjectCase> caseList = JSONObject.parseArray(result, ProjectCase.class);
|
return JSONObject.parseArray(result, ProjectCase.class);
|
||||||
return caseList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过计划名称获取测试用例对象集
|
* 通过计划名称获取测试用例对象集
|
||||||
* @param name
|
* @param name 测试计划名称
|
||||||
* @return
|
* @return 返回用例List
|
||||||
*/
|
*/
|
||||||
public static List<ProjectCase> getCasesbyplanname(String name) {
|
public static List<ProjectCase> getCasesbyplanname(String name) {
|
||||||
String result = HttpRequest.loadJSON(PREFIX+"/clientGetCaseListByPlanName.do?planName=" + name);
|
String result = HttpRequest.loadJSON(PREFIX+"/clientGetCaseListByPlanName.do?planName=" + name);
|
||||||
List<ProjectCase> caseList = JSONObject.parseArray(result, ProjectCase.class);
|
return JSONObject.parseArray(result, ProjectCase.class);
|
||||||
return caseList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用例ID获取下面的步骤对象
|
* 通过用例ID获取下面的步骤对象
|
||||||
* @param caseid
|
* @param caseid 用例ID
|
||||||
* @return
|
* @return 返回用例步骤List
|
||||||
*/
|
*/
|
||||||
public static List<ProjectCaseSteps> getStepsbycaseid(Integer caseid) {
|
public static List<ProjectCaseSteps> getStepsbycaseid(Integer caseid) {
|
||||||
String result = HttpRequest.loadJSON(PREFIX+"/clientGetStepListByCaseId.do?caseId=" + caseid);
|
String result = HttpRequest.loadJSON(PREFIX+"/clientGetStepListByCaseId.do?caseId=" + caseid);
|
||||||
List<ProjectCaseSteps> stepsList = JSONObject.parseArray(result, ProjectCaseSteps.class);
|
return JSONObject.parseArray(result, ProjectCaseSteps.class);
|
||||||
return stepsList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过taskid获取对象
|
* 通过taskid获取对象
|
||||||
* @param taskid
|
* @param taskid 测试任务ID
|
||||||
* @return
|
* @return 返回测试任务对象
|
||||||
*/
|
*/
|
||||||
public static TaskExecute cgetTaskbyid(int taskid) {
|
public static TaskExecute cgetTaskbyid(int taskid) {
|
||||||
String result = HttpRequest.loadJSON(PREFIX+"/clientGetTaskByTaskId.do?taskId=" + taskid);
|
String result = HttpRequest.loadJSON(PREFIX+"/clientGetTaskByTaskId.do?taskId=" + taskid);
|
||||||
TaskExecute task = JSONObject.parseObject(result, TaskExecute.class);
|
return JSONObject.parseObject(result, TaskExecute.class);
|
||||||
return task;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过taskid获取调度对象
|
* 通过taskid获取调度对象
|
||||||
* @param taskid
|
* @param taskid 测试任务ID
|
||||||
* @return
|
* @return 返回调度对象
|
||||||
*/
|
*/
|
||||||
public static TaskScheduling cGetTaskSchedulingByTaskId(int taskid) {
|
public static TaskScheduling cGetTaskSchedulingByTaskId(int taskid) {
|
||||||
String result = HttpRequest.loadJSON(PREFIX+"/clientGetTaskSchedulingByTaskId.do?taskId=" + taskid);
|
String result = HttpRequest.loadJSON(PREFIX+"/clientGetTaskSchedulingByTaskId.do?taskId=" + taskid);
|
||||||
TaskScheduling taskScheduling = JSONObject.parseObject(result, TaskScheduling.class);
|
return JSONObject.parseObject(result, TaskScheduling.class);
|
||||||
return taskScheduling;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用例编号获取对象
|
* 通过用例编号获取对象
|
||||||
* @param sign
|
* @param sign 用例编号
|
||||||
* @return
|
* @return 用例对象
|
||||||
*/
|
*/
|
||||||
public static ProjectCase cgetCaseBysign(String sign) {
|
public static ProjectCase cgetCaseBysign(String sign) {
|
||||||
String result = HttpRequest.loadJSON(PREFIX+"/clientGetCaseByCaseSign.do?caseSign=" + sign);
|
String result = HttpRequest.loadJSON(PREFIX+"/clientGetCaseByCaseSign.do?caseSign=" + sign);
|
||||||
ProjectCase projectCase = JSONObject.parseObject(result, ProjectCase.class);
|
return JSONObject.parseObject(result, ProjectCase.class);
|
||||||
return projectCase;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用例ID获取对象
|
* 通过用例ID获取对象
|
||||||
* @param caseId
|
* @param caseId 用例ID
|
||||||
* @return
|
* @return 用例对象
|
||||||
*/
|
*/
|
||||||
public static ProjectCase cGetCaseByCaseId(Integer caseId) {
|
public static ProjectCase cGetCaseByCaseId(Integer caseId) {
|
||||||
String result = HttpRequest.loadJSON(PREFIX+"/clientGetCaseByCaseId.do?caseId=" + caseId);
|
String result = HttpRequest.loadJSON(PREFIX+"/clientGetCaseByCaseId.do?caseId=" + caseId);
|
||||||
ProjectCase projectCase = JSONObject.parseObject(result, ProjectCase.class);
|
return JSONObject.parseObject(result, ProjectCase.class);
|
||||||
return projectCase;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取项目下的所有公共参数
|
* 获取项目下的所有公共参数
|
||||||
* @param projectid
|
* @param projectid 项目ID
|
||||||
* @return
|
* @return 公共参数集合
|
||||||
*/
|
*/
|
||||||
public static List<ProjectCaseParams> cgetParamsByProjectid(String projectid) {
|
public static List<ProjectCaseParams> cgetParamsByProjectid(String projectid) {
|
||||||
String result = HttpRequest.loadJSON(PREFIX+"/clientGetParamsByProjectId.do?projectId="+projectid);
|
String result = HttpRequest.loadJSON(PREFIX+"/clientGetParamsByProjectId.do?projectId="+projectid);
|
||||||
|
@ -125,43 +110,36 @@ public class GetServerApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过计划ID获取测试用例对象集
|
* 通过计划ID获取测试用例对象集
|
||||||
* @param taskId
|
* @param taskId 测试任务ID
|
||||||
* @return
|
* @return 测试用例ID集合
|
||||||
*/
|
*/
|
||||||
public static List<Integer> clientGetCaseListForUnSucByTaskId(Integer taskId) {
|
public static List<Integer> clientGetCaseListForUnSucByTaskId(Integer taskId) {
|
||||||
String result = HttpRequest.loadJSON(PREFIX+"/clientGetCaseListForUnSucByTaskId.do?taskId=" + taskId);
|
String result = HttpRequest.loadJSON(PREFIX+"/clientGetCaseListForUnSucByTaskId.do?taskId=" + taskId);
|
||||||
List<Integer> caseIdList = JSONObject.parseArray(result, Integer.class);
|
return JSONObject.parseArray(result, Integer.class);
|
||||||
return caseIdList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过templateId获取实体
|
* 通过templateId获取实体
|
||||||
* @param templateId
|
* @param templateId 模板ID
|
||||||
* @return
|
* @return 协议模板对象
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年4月24日
|
* @date 2019年4月24日
|
||||||
*/
|
*/
|
||||||
public static ProjectProtocolTemplate clientGetProjectProtocolTemplateByTemplateId(Integer templateId) {
|
public static ProjectProtocolTemplate clientGetProjectProtocolTemplateByTemplateId(Integer templateId) {
|
||||||
String result = HttpRequest.loadJSON(PREFIX+"/clientGetProjectProtocolTemplateByTemplateId.do?templateId=" + templateId);
|
String result = HttpRequest.loadJSON(PREFIX+"/clientGetProjectProtocolTemplateByTemplateId.do?templateId=" + templateId);
|
||||||
ProjectProtocolTemplate projectProtocolTemplate = JSONObject.parseObject(result, ProjectProtocolTemplate.class);
|
return JSONObject.parseObject(result, ProjectProtocolTemplate.class);
|
||||||
return projectProtocolTemplate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过模板ID获取参数列表
|
* 通过模板ID获取参数列表
|
||||||
* @param templateId
|
* @param templateId 模板ID
|
||||||
* @return
|
* @return 参数集合
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年4月24日
|
* @date 2019年4月24日
|
||||||
*/
|
*/
|
||||||
public static List<ProjectTemplateParams> clientGetProjectTemplateParamsListByTemplateId(Integer templateId) {
|
public static List<ProjectTemplateParams> clientGetProjectTemplateParamsListByTemplateId(Integer templateId) {
|
||||||
String result = HttpRequest.loadJSON(PREFIX+"/clientGetProjectTemplateParamsListByTemplateId.do?templateId=" + templateId);
|
String result = HttpRequest.loadJSON(PREFIX+"/clientGetProjectTemplateParamsListByTemplateId.do?templateId=" + templateId);
|
||||||
List<ProjectTemplateParams> projectTemplateParamsList = JSONObject.parseArray(result, ProjectTemplateParams.class);
|
return JSONObject.parseArray(result, ProjectTemplateParams.class);
|
||||||
return projectTemplateParamsList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,11 +24,11 @@ public class PostServerApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* put web界面的数据到服务端
|
* put web界面的数据到服务端
|
||||||
* @param userId
|
* @param userId 用户ID
|
||||||
* @param caseId
|
* @param caseId 用例ID
|
||||||
* @param logLevel
|
* @param logLevel 日志级别
|
||||||
* @param logDetail
|
* @param logDetail 日志明细
|
||||||
* @param debugIsend
|
* @param debugIsend 结束标志
|
||||||
*/
|
*/
|
||||||
public static void cPostDebugLog(Integer userId, Integer caseId, String logLevel, String logDetail,Integer debugIsend){
|
public static void cPostDebugLog(Integer userId, Integer caseId, String logLevel, String logDetail,Integer debugIsend){
|
||||||
ProjectCaseDebug projectCaseDebug = new ProjectCaseDebug();
|
ProjectCaseDebug projectCaseDebug = new ProjectCaseDebug();
|
||||||
|
@ -43,12 +43,12 @@ public class PostServerApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插入用例执行明细到数据库
|
* 插入用例执行明细到数据库
|
||||||
* @param taskId
|
* @param taskId 任务ID
|
||||||
* @param projectId
|
* @param projectId 项目ID
|
||||||
* @param caseId
|
* @param caseId 用例ID
|
||||||
* @param caseSign
|
* @param caseSign 用例编号
|
||||||
* @param caseName
|
* @param caseName 用例名称
|
||||||
* @param caseStatus
|
* @param caseStatus 用例状态
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年4月22日
|
* @date 2019年4月22日
|
||||||
*/
|
*/
|
||||||
|
@ -66,9 +66,9 @@ public class PostServerApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改用例执行状态
|
* 修改用例执行状态
|
||||||
* @param taskId
|
* @param taskId 任务ID
|
||||||
* @param caseId
|
* @param caseId 用例ID
|
||||||
* @param caseStatus
|
* @param caseStatus 用例状态
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年4月22日
|
* @date 2019年4月22日
|
||||||
*/
|
*/
|
||||||
|
@ -83,12 +83,12 @@ public class PostServerApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插入用例执行明细到数据库
|
* 插入用例执行明细到数据库
|
||||||
* @param taskId
|
* @param taskId 任务ID
|
||||||
* @param caseId
|
* @param caseId 用例ID
|
||||||
* @param logDetail
|
* @param logDetail 日志明细
|
||||||
* @param logGrade
|
* @param logGrade 日志等级
|
||||||
* @param logStep
|
* @param logStep 日志对应步骤
|
||||||
* @param imgname
|
* @param imgname 截图名称
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年4月22日
|
* @date 2019年4月22日
|
||||||
*/
|
*/
|
||||||
|
@ -107,10 +107,10 @@ public class PostServerApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新任务执行数据
|
* 更新任务执行数据
|
||||||
* @param taskId
|
* @param taskId 任务ID
|
||||||
* @param caseCount
|
* @param caseCount 用例总数
|
||||||
* @param taskStatus
|
* @param taskStatus 任务状态
|
||||||
* @return
|
* @return 更新结果
|
||||||
*/
|
*/
|
||||||
public static String clientUpdateTaskExecuteData(Integer taskId, Integer caseCount, Integer taskStatus){
|
public static String clientUpdateTaskExecuteData(Integer taskId, Integer caseCount, Integer taskStatus){
|
||||||
String str = "{\"taskId\":"+taskId+",\"caseCount\":"+caseCount+",\"taskStatus\":"+taskStatus+"}";
|
String str = "{\"taskId\":"+taskId+",\"caseCount\":"+caseCount+",\"taskStatus\":"+taskStatus+"}";
|
||||||
|
@ -119,22 +119,21 @@ public class PostServerApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ¸üÐÂÈÎÎñÖ´ÐÐÊý¾Ý
|
* 删除用例执行日志
|
||||||
* @param taskId
|
* @param taskId 任务ID
|
||||||
* @param caseId
|
* @param caseId 用例ID
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static String clientDeleteTaskCaseLog(Integer taskId, Integer caseId){
|
public static void clientDeleteTaskCaseLog(Integer taskId, Integer caseId){
|
||||||
String str = "{\"taskId\":"+taskId+",\"caseId\":"+caseId+"}";
|
String str = "{\"taskId\":"+taskId+",\"caseId\":"+caseId+"}";
|
||||||
JSONObject jsonObject = JSON.parseObject(str);
|
JSONObject jsonObject = JSON.parseObject(str);
|
||||||
return HttpRequest.httpClientPostJson(PREFIX+"/clientDeleteTaskCaseLog", jsonObject.toJSONString());
|
HttpRequest.httpClientPostJson(PREFIX + "/clientDeleteTaskCaseLog", jsonObject.toJSONString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提取测试用例的详细日志以及结果
|
* 提取测试用例的详细日志以及结果
|
||||||
* @param taskName
|
* @param taskName 任务名称
|
||||||
* @param caseSign
|
* @param caseSign 用例编号
|
||||||
* @return
|
* @return 提取结果
|
||||||
*/
|
*/
|
||||||
public static String getLogDetailResult(String taskName, String caseSign){
|
public static String getLogDetailResult(String taskName, String caseSign){
|
||||||
String str = "{\"taskName\":\""+taskName+"\",\"caseSign\":\""+caseSign+"\"}";
|
String str = "{\"taskName\":\""+taskName+"\",\"caseSign\":\""+caseSign+"\"}";
|
||||||
|
|
|
@ -1,262 +1,262 @@
|
||||||
package luckyclient.remote.api;
|
package luckyclient.remote.api;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import luckyclient.remote.entity.TaskExecute;
|
import luckyclient.remote.entity.TaskExecute;
|
||||||
import luckyclient.remote.entity.TaskScheduling;
|
import luckyclient.remote.entity.TaskScheduling;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年4月23日
|
* @date 2019年4月23日
|
||||||
*/
|
*/
|
||||||
public class serverOperation {
|
public class serverOperation {
|
||||||
/**
|
/**
|
||||||
* 任务执行类型: 0 任务调度模式 1 控制台模式
|
* 任务执行类型: 0 任务调度模式 1 控制台模式
|
||||||
*/
|
*/
|
||||||
public static int exetype;
|
public static int exetype;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插入用例执行状态 0通过 1失败 2锁定 3执行中 4未执行
|
* 插入用例执行状态 0通过 1失败 2锁定 3执行中 4未执行
|
||||||
*/
|
*/
|
||||||
public void insertTaskCaseExecute(String taskIdStr, Integer projectId,Integer caseId, String caseSign,String caseName, Integer caseStatus) {
|
public void insertTaskCaseExecute(String taskIdStr, Integer projectId,Integer caseId, String caseSign,String caseName, Integer caseStatus) {
|
||||||
if (0 == exetype) {
|
if (0 == exetype) {
|
||||||
Integer taskId=Integer.valueOf(taskIdStr);
|
Integer taskId=Integer.valueOf(taskIdStr);
|
||||||
PostServerApi.clientPostInsertTaskCaseExecute(taskId, projectId, caseId, caseSign, caseName, caseStatus);
|
PostServerApi.clientPostInsertTaskCaseExecute(taskId, projectId, caseId, caseSign, caseName, caseStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新用例执行状态 0通过 1失败 2锁定 3执行中 4未执行
|
* 更新用例执行状态 0通过 1失败 2锁定 3执行中 4未执行
|
||||||
*/
|
*/
|
||||||
public void updateTaskCaseExecuteStatus(String taskIdStr, Integer caseId, Integer caseStatus) {
|
public void updateTaskCaseExecuteStatus(String taskIdStr, Integer caseId, Integer caseStatus) {
|
||||||
if (0 == exetype) {
|
if (0 == exetype) {
|
||||||
Integer taskId=Integer.valueOf(taskIdStr);
|
Integer taskId=Integer.valueOf(taskIdStr);
|
||||||
PostServerApi.clientUpdateTaskCaseExecuteStatus(taskId, caseId, caseStatus);
|
PostServerApi.clientUpdateTaskCaseExecuteStatus(taskId, caseId, caseStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插入用例执行日志
|
* 插入用例执行日志
|
||||||
*/
|
*/
|
||||||
public void insertTaskCaseLog(String taskIdStr, Integer caseId, String logDetail, String logGrade, String logStep,
|
public void insertTaskCaseLog(String taskIdStr, Integer caseId, String logDetail, String logGrade, String logStep,
|
||||||
String imgname) {
|
String imgname) {
|
||||||
if (0 == exetype) {
|
if (0 == exetype) {
|
||||||
if (logDetail.length()>5000) {
|
if (logDetail.length()>5000) {
|
||||||
LogUtil.APP.info("第{}步,日志级别{},日志明细【{}】...日志明细超过5000字符,无法进入数据库存储,进行日志明细打印...",logStep,logGrade,logDetail);
|
LogUtil.APP.info("第{}步,日志级别{},日志明细【{}】...日志明细超过5000字符,无法进入数据库存储,进行日志明细打印...",logStep,logGrade,logDetail);
|
||||||
logDetail="日志明细超过5000字符无法存入数据库,已在LOG4J日志中打印,请前往查看...";
|
logDetail="日志明细超过5000字符无法存入数据库,已在LOG4J日志中打印,请前往查看...";
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer taskId=Integer.valueOf(taskIdStr);
|
Integer taskId=Integer.valueOf(taskIdStr);
|
||||||
PostServerApi.clientPostInsertTaskCaseLog(taskId, caseId, logDetail, logGrade, logStep, imgname);
|
PostServerApi.clientPostInsertTaskCaseLog(taskId, caseId, logDetail, logGrade, logStep, imgname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新本次任务的执行统计情况
|
* 更新本次任务的执行统计情况
|
||||||
* 状态 0未执行 1执行中 2执行完成 3执行失败 4唤起客户端失败
|
* 状态 0未执行 1执行中 2执行完成 3执行失败 4唤起客户端失败
|
||||||
*/
|
*/
|
||||||
public static int[] updateTaskExecuteData(String taskIdStr, int caseCount, int taskStatus) {
|
public static int[] updateTaskExecuteData(String taskIdStr, int caseCount, int taskStatus) {
|
||||||
int[] taskcount = null;
|
int[] taskcount = null;
|
||||||
if (0 == exetype) {
|
if (0 == exetype) {
|
||||||
Integer taskId = Integer.parseInt(taskIdStr);
|
Integer taskId = Integer.parseInt(taskIdStr);
|
||||||
String str = PostServerApi.clientUpdateTaskExecuteData(taskId, caseCount,taskStatus);
|
String str = PostServerApi.clientUpdateTaskExecuteData(taskId, caseCount,taskStatus);
|
||||||
JSONObject jsonObject = JSONObject.parseObject(str);
|
JSONObject jsonObject = JSONObject.parseObject(str);
|
||||||
|
|
||||||
// 返回本次任务执行情况
|
// 返回本次任务执行情况
|
||||||
taskcount = new int[5];
|
taskcount = new int[5];
|
||||||
taskcount[0] = jsonObject.getInteger("caseCount");
|
taskcount[0] = jsonObject.getInteger("caseCount");
|
||||||
taskcount[1] = jsonObject.getInteger("caseSuc");
|
taskcount[1] = jsonObject.getInteger("caseSuc");
|
||||||
taskcount[2] = jsonObject.getInteger("caseFail");
|
taskcount[2] = jsonObject.getInteger("caseFail");
|
||||||
taskcount[3] = jsonObject.getInteger("caseLock");
|
taskcount[3] = jsonObject.getInteger("caseLock");
|
||||||
taskcount[4] = jsonObject.getInteger("caseNoExec");
|
taskcount[4] = jsonObject.getInteger("caseNoExec");
|
||||||
|
|
||||||
}
|
}
|
||||||
return taskcount;
|
return taskcount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新本次任务的执行状态
|
* 更新本次任务的执行状态
|
||||||
* 状态 0未执行 1执行中 2执行完成 3执行失败 4唤起客户端失败
|
* 状态 0未执行 1执行中 2执行完成 3执行失败 4唤起客户端失败
|
||||||
*/
|
*/
|
||||||
public static void updateTaskExecuteStatusIng(String taskIdStr, int caseCount) {
|
public static void updateTaskExecuteStatusIng(String taskIdStr, int caseCount) {
|
||||||
if (0 == exetype) {
|
if (0 == exetype) {
|
||||||
Integer taskId = Integer.parseInt(taskIdStr);
|
Integer taskId = Integer.parseInt(taskIdStr);
|
||||||
PostServerApi.clientUpdateTaskExecuteData(taskId, caseCount,1);
|
PostServerApi.clientUpdateTaskExecuteData(taskId, caseCount,1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除单次任务指定的用例日志明细
|
* 删除单次任务指定的用例日志明细
|
||||||
*/
|
*/
|
||||||
public static void deleteTaskCaseLog(Integer caseId, String taskIdStr) {
|
public static void deleteTaskCaseLog(Integer caseId, String taskIdStr) {
|
||||||
Integer taskId = Integer.parseInt(taskIdStr);
|
Integer taskId = Integer.parseInt(taskIdStr);
|
||||||
PostServerApi.clientDeleteTaskCaseLog(taskId, caseId);
|
PostServerApi.clientDeleteTaskCaseLog(taskId, caseId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取出指定任务ID中的不属于成功状态的用例ID
|
* 取出指定任务ID中的不属于成功状态的用例ID
|
||||||
*/
|
*/
|
||||||
public List<Integer> getCaseListForUnSucByTaskId(String taskIdStr) {
|
public List<Integer> getCaseListForUnSucByTaskId(String taskIdStr) {
|
||||||
int taskId = Integer.parseInt(taskIdStr);
|
int taskId = Integer.parseInt(taskIdStr);
|
||||||
return GetServerApi.clientGetCaseListForUnSucByTaskId(taskId);
|
return GetServerApi.clientGetCaseListForUnSucByTaskId(taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取出指定任务ID中所属的调度是否要发送邮件状态及收件人地址 发送邮件通知时的具体逻辑, -1-不通知 0-全部,1-成功,2-失败
|
* 取出指定任务ID中所属的调度是否要发送邮件状态及收件人地址 发送邮件通知时的具体逻辑, -1-不通知 0-全部,1-成功,2-失败
|
||||||
* 发送 eMailer varchar(100) ; --收件人
|
* 发送 eMailer varchar(100) ; --收件人
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static String[] getEmailAddress(String taskIdStr) {
|
public static String[] getEmailAddress(String taskIdStr) {
|
||||||
Integer taskId = Integer.parseInt(taskIdStr);
|
int taskId = Integer.parseInt(taskIdStr);
|
||||||
String[] address = null;
|
String[] address = null;
|
||||||
try {
|
try {
|
||||||
TaskScheduling taskScheduling = GetServerApi.cGetTaskSchedulingByTaskId(taskId);
|
TaskScheduling taskScheduling = GetServerApi.cGetTaskSchedulingByTaskId(taskId);
|
||||||
if (!taskScheduling.getEmailSendCondition().equals(-1)) {
|
if (!taskScheduling.getEmailSendCondition().equals(-1)) {
|
||||||
String temp = taskScheduling.getEmailAddress();
|
String temp = taskScheduling.getEmailAddress();
|
||||||
// 清除最后一个;
|
// 清除最后一个;
|
||||||
if (temp.indexOf(";") > -1 && temp.substring(temp.length() - 1, temp.length()).indexOf(";") > -1) {
|
if (temp.contains(";") && temp.substring(temp.length() - 1).contains(";")) {
|
||||||
temp = temp.substring(0, temp.length() - 1);
|
temp = temp.substring(0, temp.length() - 1);
|
||||||
}
|
}
|
||||||
// 多个地址
|
// 多个地址
|
||||||
if (temp.indexOf("null") <= -1 && temp.indexOf(";") > -1) {
|
if (!temp.contains("null") && temp.contains(";")) {
|
||||||
address = temp.split(";", -1);
|
address = temp.split(";", -1);
|
||||||
// 一个地址
|
// 一个地址
|
||||||
} else if (temp.indexOf("null") <= -1 && temp.indexOf(";") <= -1) {
|
} else if (!temp.contains("null") && !temp.contains(";")) {
|
||||||
address = new String[1];
|
address = new String[1];
|
||||||
address[0] = temp;
|
address[0] = temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
LogUtil.APP.error("获取邮件收件人地址出现异常,请检查!",e);
|
LogUtil.APP.error("获取邮件收件人地址出现异常,请检查!",e);
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取出指定任务ID中所属的调度是否要自动构建以及构建的项目名称 为空时不构建
|
* 取出指定任务ID中所属的调度是否要自动构建以及构建的项目名称 为空时不构建
|
||||||
*/
|
*/
|
||||||
public static String[] getBuildName(String taskIdStr) {
|
public static String[] getBuildName(String taskIdStr) {
|
||||||
Integer taskId = Integer.parseInt(taskIdStr);
|
int taskId = Integer.parseInt(taskIdStr);
|
||||||
String[] buildname = null;
|
String[] buildname = null;
|
||||||
try {
|
try {
|
||||||
TaskScheduling taskScheduling = GetServerApi.cGetTaskSchedulingByTaskId(taskId);
|
TaskScheduling taskScheduling = GetServerApi.cGetTaskSchedulingByTaskId(taskId);
|
||||||
if (StrUtil.isEmpty(taskScheduling.getBuildingLink())) {
|
if (StrUtil.isEmpty(taskScheduling.getBuildingLink())) {
|
||||||
return buildname;
|
return buildname;
|
||||||
}else{
|
}else{
|
||||||
String jobName = taskScheduling.getBuildingLink();
|
String jobName = taskScheduling.getBuildingLink();
|
||||||
// 清除最后一个;
|
// 清除最后一个;
|
||||||
if (jobName.indexOf(";") > -1 && jobName.substring(jobName.length() - 1, jobName.length()).indexOf(";") > -1) {
|
if (jobName.contains(";") && jobName.substring(jobName.length() - 1).contains(";")) {
|
||||||
jobName = jobName.substring(0, jobName.length() - 1);
|
jobName = jobName.substring(0, jobName.length() - 1);
|
||||||
}
|
}
|
||||||
// 多个名称
|
// 多个名称
|
||||||
if (jobName.indexOf("null") <= -1 && jobName.indexOf(";") > -1) {
|
if (!jobName.contains("null") && jobName.contains(";")) {
|
||||||
buildname = jobName.split(";", -1);
|
buildname = jobName.split(";", -1);
|
||||||
// 一个名称
|
// 一个名称
|
||||||
} else if (jobName.indexOf("null") <= -1 && jobName.indexOf(";") <= -1) {
|
} else if (!jobName.contains("null") && !jobName.contains(";")) {
|
||||||
buildname = new String[1];
|
buildname = new String[1];
|
||||||
buildname[0] = jobName;
|
buildname[0] = jobName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
LogUtil.APP.error("获取构建地址出现异常,请检查!",e);
|
LogUtil.APP.error("获取构建地址出现异常,请检查!",e);
|
||||||
return buildname;
|
return buildname;
|
||||||
}
|
}
|
||||||
return buildname;
|
return buildname;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取出指定任务ID中所属的调度是否要自动重启TOMCAT
|
* 取出指定任务ID中所属的调度是否要自动重启TOMCAT
|
||||||
* 自动重启 restartcomm varchar(200) ; -- 格式:服务器IP;服务器用户名;服务器密码;ssh端口;Shell命令;
|
* 自动重启 restartcomm varchar(200) ; -- 格式:服务器IP;服务器用户名;服务器密码;ssh端口;Shell命令;
|
||||||
* 例:192.168.222.22;pospsettle;pospsettle;22;cd
|
* 例:192.168.222.22;pospsettle;pospsettle;22;cd
|
||||||
* /home/pospsettle/tomcat-7.0-7080/bin&&./restart.sh;
|
* /home/pospsettle/tomcat-7.0-7080/bin&&./restart.sh;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static String[] getRestartComm(String taskIdStr) {
|
public static String[] getRestartComm(String taskIdStr) {
|
||||||
Integer taskId = Integer.parseInt(taskIdStr);
|
int taskId = Integer.parseInt(taskIdStr);
|
||||||
String[] command = null;
|
String[] command = null;
|
||||||
try {
|
try {
|
||||||
TaskScheduling taskScheduling = GetServerApi.cGetTaskSchedulingByTaskId(taskId);
|
TaskScheduling taskScheduling = GetServerApi.cGetTaskSchedulingByTaskId(taskId);
|
||||||
if (null == taskScheduling.getRemoteShell() || "".equals(taskScheduling.getRemoteShell())) {
|
if (null == taskScheduling.getRemoteShell() || "".equals(taskScheduling.getRemoteShell())) {
|
||||||
return command;
|
return command;
|
||||||
}else{
|
}else{
|
||||||
String temp = taskScheduling.getRemoteShell();
|
String temp = taskScheduling.getRemoteShell();
|
||||||
// 清除最后一个;
|
// 清除最后一个;
|
||||||
if (temp.indexOf(";") > -1 && temp.substring(temp.length() - 1, temp.length()).indexOf(";") > -1) {
|
if (temp.contains(";") && temp.substring(temp.length() - 1).contains(";")) {
|
||||||
temp = temp.substring(0, temp.length() - 1);
|
temp = temp.substring(0, temp.length() - 1);
|
||||||
}
|
}
|
||||||
// 多个名称
|
// 多个名称
|
||||||
if (temp.indexOf("null") <= -1 && temp.indexOf(";") > -1) {
|
if (!temp.contains("null") && temp.contains(";")) {
|
||||||
command = temp.split(";", -1);
|
command = temp.split(";", -1);
|
||||||
// 一个名称
|
// 一个名称
|
||||||
} else if (temp.indexOf("null") <= -1 && temp.indexOf(";") <= -1) {
|
} else if (!temp.contains("null") && !temp.contains(";")) {
|
||||||
command = new String[1];
|
command = new String[1];
|
||||||
command[0] = temp;
|
command[0] = temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
LogUtil.APP.error("获取远程shell地址出现异常,请检查!",e);
|
LogUtil.APP.error("获取远程shell地址出现异常,请检查!",e);
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
return command;
|
return command;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取任务测试时长
|
* 获取任务测试时长
|
||||||
*/
|
*/
|
||||||
public static String getTestTime(String taskIdStr) {
|
public static String getTestTime(String taskIdStr) {
|
||||||
Integer taskId = Integer.parseInt(taskIdStr);
|
int taskId = Integer.parseInt(taskIdStr);
|
||||||
String desTime = "计算测试时长出错!";
|
String desTime = "计算测试时长出错!";
|
||||||
try {
|
try {
|
||||||
TaskExecute taskExecute = GetServerApi.cgetTaskbyid(taskId);
|
TaskExecute taskExecute = GetServerApi.cgetTaskbyid(taskId);
|
||||||
Date start = taskExecute.getCreateTime();
|
Date start = taskExecute.getCreateTime();
|
||||||
if (null!= taskExecute.getFinishTime()) {
|
if (null!= taskExecute.getFinishTime()) {
|
||||||
Date finish = taskExecute.getFinishTime();
|
Date finish = taskExecute.getFinishTime();
|
||||||
long l = finish.getTime() - start.getTime();
|
long l = finish.getTime() - start.getTime();
|
||||||
long day = l / (24 * 60 * 60 * 1000);
|
long day = l / (24 * 60 * 60 * 1000);
|
||||||
long hour = (l / (60 * 60 * 1000) - day * 24);
|
long hour = (l / (60 * 60 * 1000) - day * 24);
|
||||||
long min = ((l / (60 * 1000)) - day * 24 * 60 - hour * 60);
|
long min = ((l / (60 * 1000)) - day * 24 * 60 - hour * 60);
|
||||||
long s = (l / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
|
long s = (l / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
|
||||||
desTime = "<font color='#2828FF'>" + hour + "</font>小时<font color='#2828FF'>" + min
|
desTime = "<font color='#2828FF'>" + hour + "</font>小时<font color='#2828FF'>" + min
|
||||||
+ "</font>分<font color='#2828FF'>" + s + "</font>秒";
|
+ "</font>分<font color='#2828FF'>" + s + "</font>秒";
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
LogUtil.APP.error("获取任务测试时长出现异常,请检查!",e);
|
LogUtil.APP.error("获取任务测试时长出现异常,请检查!",e);
|
||||||
return desTime;
|
return desTime;
|
||||||
}
|
}
|
||||||
return desTime;
|
return desTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询web执行,浏览器类型 UI自动化浏览器类型 0 IE 1 火狐 2 谷歌 3 Edge
|
* 查询web执行,浏览器类型 UI自动化浏览器类型 0 IE 1 火狐 2 谷歌 3 Edge
|
||||||
*/
|
*/
|
||||||
public static int querydrivertype(String taskIdStr) {
|
public static int querydrivertype(String taskIdStr) {
|
||||||
Integer taskId = Integer.parseInt(taskIdStr);
|
int taskId = Integer.parseInt(taskIdStr);
|
||||||
int driverType = 0;
|
int driverType = 0;
|
||||||
try {
|
try {
|
||||||
TaskScheduling taskScheduling = GetServerApi.cGetTaskSchedulingByTaskId(taskId);
|
TaskScheduling taskScheduling = GetServerApi.cGetTaskSchedulingByTaskId(taskId);
|
||||||
driverType = taskScheduling.getBrowserType();
|
driverType = taskScheduling.getBrowserType();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
LogUtil.APP.error("获取浏览器类型出现异常,请检查!",e);
|
LogUtil.APP.error("获取浏览器类型出现异常,请检查!",e);
|
||||||
return driverType;
|
return driverType;
|
||||||
}
|
}
|
||||||
return driverType;
|
return driverType;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,202 +1,197 @@
|
||||||
package luckyclient.remote.entity.monitor;
|
package luckyclient.remote.entity.monitor;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取IP方法
|
* 获取IP方法
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年5月5日
|
* @date 2019年5月5日
|
||||||
*/
|
*/
|
||||||
public class IpUtils
|
public class IpUtils
|
||||||
{
|
{
|
||||||
public static String getIpAddr(HttpServletRequest request)
|
public static String getIpAddr(HttpServletRequest request)
|
||||||
{
|
{
|
||||||
if (request == null)
|
if (request == null)
|
||||||
{
|
{
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
String ip = request.getHeader("x-forwarded-for");
|
String ip = request.getHeader("x-forwarded-for");
|
||||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
|
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
|
||||||
{
|
{
|
||||||
ip = request.getHeader("Proxy-Client-IP");
|
ip = request.getHeader("Proxy-Client-IP");
|
||||||
}
|
}
|
||||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
|
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
|
||||||
{
|
{
|
||||||
ip = request.getHeader("X-Forwarded-For");
|
ip = request.getHeader("X-Forwarded-For");
|
||||||
}
|
}
|
||||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
|
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
|
||||||
{
|
{
|
||||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||||
}
|
}
|
||||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
|
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
|
||||||
{
|
{
|
||||||
ip = request.getHeader("X-Real-IP");
|
ip = request.getHeader("X-Real-IP");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
|
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
|
||||||
{
|
{
|
||||||
ip = request.getRemoteAddr();
|
ip = request.getRemoteAddr();
|
||||||
}
|
}
|
||||||
|
|
||||||
return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip;
|
return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean internalIp(String ip)
|
public static boolean internalIp(String ip)
|
||||||
{
|
{
|
||||||
byte[] addr = textToNumericFormatV4(ip);
|
byte[] addr = textToNumericFormatV4(ip);
|
||||||
return internalIp(addr) || "127.0.0.1".equals(ip);
|
assert addr != null;
|
||||||
}
|
return internalIp(addr) || "127.0.0.1".equals(ip);
|
||||||
|
}
|
||||||
private static boolean internalIp(byte[] addr)
|
|
||||||
{
|
private static boolean internalIp(byte[] addr)
|
||||||
final byte b0 = addr[0];
|
{
|
||||||
final byte b1 = addr[1];
|
final byte b0 = addr[0];
|
||||||
// 10.x.x.x/8
|
final byte b1 = addr[1];
|
||||||
final byte section1 = 0x0A;
|
// 10.x.x.x/8
|
||||||
// 172.16.x.x/12
|
final byte section1 = 0x0A;
|
||||||
final byte section2 = (byte) 0xAC;
|
// 172.16.x.x/12
|
||||||
final byte section3 = (byte) 0x10;
|
final byte section2 = (byte) 0xAC;
|
||||||
final byte section4 = (byte) 0x1F;
|
final byte section3 = (byte) 0x10;
|
||||||
// 192.168.x.x/16
|
final byte section4 = (byte) 0x1F;
|
||||||
final byte section5 = (byte) 0xC0;
|
// 192.168.x.x/16
|
||||||
final byte section6 = (byte) 0xA8;
|
final byte section5 = (byte) 0xC0;
|
||||||
switch (b0)
|
final byte section6 = (byte) 0xA8;
|
||||||
{
|
switch (b0)
|
||||||
case section1:
|
{
|
||||||
return true;
|
case section1:
|
||||||
case section2:
|
return true;
|
||||||
if (b1 >= section3 && b1 <= section4)
|
case section2:
|
||||||
{
|
if (b1 >= section3 && b1 <= section4)
|
||||||
return true;
|
{
|
||||||
}
|
return true;
|
||||||
case section5:
|
}
|
||||||
switch (b1)
|
case section5:
|
||||||
{
|
return b1 == section6;
|
||||||
case section6:
|
default:
|
||||||
return true;
|
return false;
|
||||||
default:
|
}
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
default:
|
/**
|
||||||
return false;
|
* 将IPv4地址转换成字节
|
||||||
}
|
*
|
||||||
}
|
* @param text IPv4地址
|
||||||
|
* @return byte 字节
|
||||||
/**
|
*/
|
||||||
* 将IPv4地址转换成字节
|
public static byte[] textToNumericFormatV4(String text)
|
||||||
*
|
{
|
||||||
* @param text IPv4地址
|
if (text.length() == 0)
|
||||||
* @return byte 字节
|
{
|
||||||
*/
|
return null;
|
||||||
public static byte[] textToNumericFormatV4(String text)
|
}
|
||||||
{
|
|
||||||
if (text.length() == 0)
|
byte[] bytes = new byte[4];
|
||||||
{
|
String[] elements = text.split("\\.", -1);
|
||||||
return null;
|
try
|
||||||
}
|
{
|
||||||
|
long l;
|
||||||
byte[] bytes = new byte[4];
|
int i;
|
||||||
String[] elements = text.split("\\.", -1);
|
switch (elements.length)
|
||||||
try
|
{
|
||||||
{
|
case 1:
|
||||||
long l;
|
l = Long.parseLong(elements[0]);
|
||||||
int i;
|
if ((l < 0L) || (l > 4294967295L)){
|
||||||
switch (elements.length)
|
return null;
|
||||||
{
|
}
|
||||||
case 1:
|
|
||||||
l = Long.parseLong(elements[0]);
|
bytes[0] = (byte) (int) (l >> 24 & 0xFF);
|
||||||
if ((l < 0L) || (l > 4294967295L)){
|
bytes[1] = (byte) (int) ((l & 0xFFFFFF) >> 16 & 0xFF);
|
||||||
return null;
|
bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF);
|
||||||
}
|
bytes[3] = (byte) (int) (l & 0xFF);
|
||||||
|
break;
|
||||||
bytes[0] = (byte) (int) (l >> 24 & 0xFF);
|
case 2:
|
||||||
bytes[1] = (byte) (int) ((l & 0xFFFFFF) >> 16 & 0xFF);
|
l = Integer.parseInt(elements[0]);
|
||||||
bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF);
|
if ((l < 0L) || (l > 255L)){
|
||||||
bytes[3] = (byte) (int) (l & 0xFF);
|
return null;
|
||||||
break;
|
}
|
||||||
case 2:
|
|
||||||
l = Integer.parseInt(elements[0]);
|
bytes[0] = (byte) (int) (l & 0xFF);
|
||||||
if ((l < 0L) || (l > 255L)){
|
l = Integer.parseInt(elements[1]);
|
||||||
return null;
|
if ((l < 0L) || (l > 16777215L)){
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
bytes[0] = (byte) (int) (l & 0xFF);
|
|
||||||
l = Integer.parseInt(elements[1]);
|
bytes[1] = (byte) (int) (l >> 16 & 0xFF);
|
||||||
if ((l < 0L) || (l > 16777215L)){
|
bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF);
|
||||||
return null;
|
bytes[3] = (byte) (int) (l & 0xFF);
|
||||||
}
|
break;
|
||||||
|
case 3:
|
||||||
bytes[1] = (byte) (int) (l >> 16 & 0xFF);
|
for (i = 0; i < 2; ++i)
|
||||||
bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF);
|
{
|
||||||
bytes[3] = (byte) (int) (l & 0xFF);
|
l = Integer.parseInt(elements[i]);
|
||||||
break;
|
if ((l < 0L) || (l > 255L)){
|
||||||
case 3:
|
return null;
|
||||||
for (i = 0; i < 2; ++i)
|
}
|
||||||
{
|
|
||||||
l = Integer.parseInt(elements[i]);
|
bytes[i] = (byte) (int) (l & 0xFF);
|
||||||
if ((l < 0L) || (l > 255L)){
|
}
|
||||||
return null;
|
l = Integer.parseInt(elements[2]);
|
||||||
}
|
if ((l < 0L) || (l > 65535L)){
|
||||||
|
return null;
|
||||||
bytes[i] = (byte) (int) (l & 0xFF);
|
}
|
||||||
}
|
|
||||||
l = Integer.parseInt(elements[2]);
|
bytes[2] = (byte) (int) (l >> 8 & 0xFF);
|
||||||
if ((l < 0L) || (l > 65535L)){
|
bytes[3] = (byte) (int) (l & 0xFF);
|
||||||
return null;
|
break;
|
||||||
}
|
case 4:
|
||||||
|
for (i = 0; i < 4; ++i)
|
||||||
bytes[2] = (byte) (int) (l >> 8 & 0xFF);
|
{
|
||||||
bytes[3] = (byte) (int) (l & 0xFF);
|
l = Integer.parseInt(elements[i]);
|
||||||
break;
|
if ((l < 0L) || (l > 255L)){
|
||||||
case 4:
|
return null;
|
||||||
for (i = 0; i < 4; ++i)
|
}
|
||||||
{
|
|
||||||
l = Integer.parseInt(elements[i]);
|
bytes[i] = (byte) (int) (l & 0xFF);
|
||||||
if ((l < 0L) || (l > 255L)){
|
}
|
||||||
return null;
|
break;
|
||||||
}
|
default:
|
||||||
|
return null;
|
||||||
bytes[i] = (byte) (int) (l & 0xFF);
|
}
|
||||||
}
|
}
|
||||||
break;
|
catch (NumberFormatException e)
|
||||||
default:
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
return bytes;
|
||||||
catch (NumberFormatException e)
|
}
|
||||||
{
|
|
||||||
return null;
|
public static String getHostIp()
|
||||||
}
|
{
|
||||||
return bytes;
|
try
|
||||||
}
|
{
|
||||||
|
return InetAddress.getLocalHost().getHostAddress();
|
||||||
public static String getHostIp()
|
}
|
||||||
{
|
catch (UnknownHostException ignored)
|
||||||
try
|
{
|
||||||
{
|
}
|
||||||
return InetAddress.getLocalHost().getHostAddress();
|
return "127.0.0.1";
|
||||||
}
|
}
|
||||||
catch (UnknownHostException e)
|
|
||||||
{
|
public static String getHostName()
|
||||||
}
|
{
|
||||||
return "127.0.0.1";
|
try
|
||||||
}
|
{
|
||||||
|
return InetAddress.getLocalHost().getHostName();
|
||||||
public static String getHostName()
|
}
|
||||||
{
|
catch (UnknownHostException ignored)
|
||||||
try
|
{
|
||||||
{
|
}
|
||||||
return InetAddress.getLocalHost().getHostName();
|
return "未知";
|
||||||
}
|
}
|
||||||
catch (UnknownHostException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
return "未知";
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,238 +1,236 @@
|
||||||
package luckyclient.remote.entity.monitor;
|
package luckyclient.remote.entity.monitor;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import oshi.SystemInfo;
|
import oshi.SystemInfo;
|
||||||
import oshi.hardware.CentralProcessor;
|
import oshi.hardware.CentralProcessor;
|
||||||
import oshi.hardware.CentralProcessor.TickType;
|
import oshi.hardware.CentralProcessor.TickType;
|
||||||
import oshi.hardware.GlobalMemory;
|
import oshi.hardware.GlobalMemory;
|
||||||
import oshi.hardware.HardwareAbstractionLayer;
|
import oshi.hardware.HardwareAbstractionLayer;
|
||||||
import oshi.software.os.FileSystem;
|
import oshi.software.os.FileSystem;
|
||||||
import oshi.software.os.OSFileStore;
|
import oshi.software.os.OSFileStore;
|
||||||
import oshi.software.os.OperatingSystem;
|
import oshi.software.os.OperatingSystem;
|
||||||
import oshi.util.Util;
|
import oshi.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务器相关信息
|
* 服务器相关信息
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年5月5日
|
* @date 2019年5月5日
|
||||||
*/
|
*/
|
||||||
public class Server
|
public class Server
|
||||||
{
|
{
|
||||||
private static final int OSHI_WAIT_SECOND = 1000;
|
private static final int OSHI_WAIT_SECOND = 1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CPU相关信息
|
* CPU相关信息
|
||||||
*/
|
*/
|
||||||
private Cpu cpu = new Cpu();
|
private Cpu cpu = new Cpu();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 內存相关信息
|
* 內存相关信息
|
||||||
*/
|
*/
|
||||||
private Mem mem = new Mem();
|
private Mem mem = new Mem();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JVM相关信息
|
* JVM相关信息
|
||||||
*/
|
*/
|
||||||
private Jvm jvm = new Jvm();
|
private Jvm jvm = new Jvm();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务器相关信息
|
* 服务器相关信息
|
||||||
*/
|
*/
|
||||||
private Sys sys = new Sys();
|
private Sys sys = new Sys();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 磁盘相关信息
|
* 磁盘相关信息
|
||||||
*/
|
*/
|
||||||
private List<SysFile> sysFiles = new LinkedList<SysFile>();
|
private List<SysFile> sysFiles = new LinkedList<>();
|
||||||
|
|
||||||
public Cpu getCpu()
|
public Cpu getCpu()
|
||||||
{
|
{
|
||||||
return cpu;
|
return cpu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCpu(Cpu cpu)
|
public void setCpu(Cpu cpu)
|
||||||
{
|
{
|
||||||
this.cpu = cpu;
|
this.cpu = cpu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mem getMem()
|
public Mem getMem()
|
||||||
{
|
{
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMem(Mem mem)
|
public void setMem(Mem mem)
|
||||||
{
|
{
|
||||||
this.mem = mem;
|
this.mem = mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Jvm getJvm()
|
public Jvm getJvm()
|
||||||
{
|
{
|
||||||
return jvm;
|
return jvm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setJvm(Jvm jvm)
|
public void setJvm(Jvm jvm)
|
||||||
{
|
{
|
||||||
this.jvm = jvm;
|
this.jvm = jvm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sys getSys()
|
public Sys getSys()
|
||||||
{
|
{
|
||||||
return sys;
|
return sys;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSys(Sys sys)
|
public void setSys(Sys sys)
|
||||||
{
|
{
|
||||||
this.sys = sys;
|
this.sys = sys;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SysFile> getSysFiles()
|
public List<SysFile> getSysFiles()
|
||||||
{
|
{
|
||||||
return sysFiles;
|
return sysFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSysFiles(List<SysFile> sysFiles)
|
public void setSysFiles(List<SysFile> sysFiles)
|
||||||
{
|
{
|
||||||
this.sysFiles = sysFiles;
|
this.sysFiles = sysFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copyTo() throws Exception
|
public void copyTo() {
|
||||||
{
|
SystemInfo si = new SystemInfo();
|
||||||
SystemInfo si = new SystemInfo();
|
HardwareAbstractionLayer hal = si.getHardware();
|
||||||
HardwareAbstractionLayer hal = si.getHardware();
|
|
||||||
|
setCpuInfo(hal.getProcessor());
|
||||||
setCpuInfo(hal.getProcessor());
|
|
||||||
|
setMemInfo(hal.getMemory());
|
||||||
setMemInfo(hal.getMemory());
|
|
||||||
|
setSysInfo();
|
||||||
setSysInfo();
|
|
||||||
|
setJvmInfo();
|
||||||
setJvmInfo();
|
|
||||||
|
setSysFiles(si.getOperatingSystem());
|
||||||
setSysFiles(si.getOperatingSystem());
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* 设置CPU信息
|
||||||
* 设置CPU信息
|
*/
|
||||||
*/
|
private void setCpuInfo(CentralProcessor processor)
|
||||||
private void setCpuInfo(CentralProcessor processor)
|
{
|
||||||
{
|
// CPU信息
|
||||||
// CPU信息
|
long[] prevTicks = processor.getSystemCpuLoadTicks();
|
||||||
long[] prevTicks = processor.getSystemCpuLoadTicks();
|
Util.sleep(OSHI_WAIT_SECOND);
|
||||||
Util.sleep(OSHI_WAIT_SECOND);
|
long[] ticks = processor.getSystemCpuLoadTicks();
|
||||||
long[] ticks = processor.getSystemCpuLoadTicks();
|
long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
|
||||||
long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
|
long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()];
|
||||||
long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()];
|
long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()];
|
||||||
long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()];
|
long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()];
|
||||||
long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()];
|
long cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
|
||||||
long cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
|
long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
|
||||||
long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
|
long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()];
|
||||||
long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()];
|
long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
|
||||||
long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
|
long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;
|
||||||
long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;
|
cpu.setCpuNum(processor.getLogicalProcessorCount());
|
||||||
cpu.setCpuNum(processor.getLogicalProcessorCount());
|
cpu.setTotal(totalCpu);
|
||||||
cpu.setTotal(totalCpu);
|
cpu.setSys(cSys);
|
||||||
cpu.setSys(cSys);
|
cpu.setUsed(user);
|
||||||
cpu.setUsed(user);
|
cpu.setWait(iowait);
|
||||||
cpu.setWait(iowait);
|
cpu.setFree(idle);
|
||||||
cpu.setFree(idle);
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* 设置内存信息
|
||||||
* 设置内存信息
|
*/
|
||||||
*/
|
private void setMemInfo(GlobalMemory memory)
|
||||||
private void setMemInfo(GlobalMemory memory)
|
{
|
||||||
{
|
mem.setTotal(memory.getTotal());
|
||||||
mem.setTotal(memory.getTotal());
|
mem.setUsed(memory.getTotal() - memory.getAvailable());
|
||||||
mem.setUsed(memory.getTotal() - memory.getAvailable());
|
mem.setFree(memory.getAvailable());
|
||||||
mem.setFree(memory.getAvailable());
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* 设置服务器信息
|
||||||
* 设置服务器信息
|
*/
|
||||||
*/
|
private void setSysInfo()
|
||||||
private void setSysInfo()
|
{
|
||||||
{
|
Properties props = System.getProperties();
|
||||||
Properties props = System.getProperties();
|
sys.setComputerName(IpUtils.getHostName());
|
||||||
sys.setComputerName(IpUtils.getHostName());
|
sys.setComputerIp(IpUtils.getHostIp());
|
||||||
sys.setComputerIp(IpUtils.getHostIp());
|
sys.setOsName(props.getProperty("os.name"));
|
||||||
sys.setOsName(props.getProperty("os.name"));
|
sys.setOsArch(props.getProperty("os.arch"));
|
||||||
sys.setOsArch(props.getProperty("os.arch"));
|
sys.setUserDir(props.getProperty("user.dir"));
|
||||||
sys.setUserDir(props.getProperty("user.dir"));
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* 设置Java虚拟机
|
||||||
* 设置Java虚拟机
|
*/
|
||||||
*/
|
private void setJvmInfo() {
|
||||||
private void setJvmInfo() throws UnknownHostException
|
Properties props = System.getProperties();
|
||||||
{
|
jvm.setTotal(Runtime.getRuntime().totalMemory());
|
||||||
Properties props = System.getProperties();
|
jvm.setMax(Runtime.getRuntime().maxMemory());
|
||||||
jvm.setTotal(Runtime.getRuntime().totalMemory());
|
jvm.setFree(Runtime.getRuntime().freeMemory());
|
||||||
jvm.setMax(Runtime.getRuntime().maxMemory());
|
jvm.setVersion(props.getProperty("java.version"));
|
||||||
jvm.setFree(Runtime.getRuntime().freeMemory());
|
jvm.setHome(props.getProperty("java.home"));
|
||||||
jvm.setVersion(props.getProperty("java.version"));
|
}
|
||||||
jvm.setHome(props.getProperty("java.home"));
|
|
||||||
}
|
/**
|
||||||
|
* 设置磁盘信息
|
||||||
/**
|
*/
|
||||||
* 设置磁盘信息
|
private void setSysFiles(OperatingSystem os)
|
||||||
*/
|
{
|
||||||
private void setSysFiles(OperatingSystem os)
|
FileSystem fileSystem = os.getFileSystem();
|
||||||
{
|
OSFileStore[] fsArray = fileSystem.getFileStores();
|
||||||
FileSystem fileSystem = os.getFileSystem();
|
for (OSFileStore fs : fsArray)
|
||||||
OSFileStore[] fsArray = fileSystem.getFileStores();
|
{
|
||||||
for (OSFileStore fs : fsArray)
|
long free = fs.getUsableSpace();
|
||||||
{
|
long total = fs.getTotalSpace();
|
||||||
long free = fs.getUsableSpace();
|
long used = total - free;
|
||||||
long total = fs.getTotalSpace();
|
SysFile sysFile = new SysFile();
|
||||||
long used = total - free;
|
sysFile.setDirName(fs.getMount());
|
||||||
SysFile sysFile = new SysFile();
|
sysFile.setSysTypeName(fs.getType());
|
||||||
sysFile.setDirName(fs.getMount());
|
sysFile.setTypeName(fs.getName());
|
||||||
sysFile.setSysTypeName(fs.getType());
|
sysFile.setTotal(convertFileSize(total));
|
||||||
sysFile.setTypeName(fs.getName());
|
sysFile.setFree(convertFileSize(free));
|
||||||
sysFile.setTotal(convertFileSize(total));
|
sysFile.setUsed(convertFileSize(used));
|
||||||
sysFile.setFree(convertFileSize(free));
|
sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
|
||||||
sysFile.setUsed(convertFileSize(used));
|
sysFiles.add(sysFile);
|
||||||
sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
|
}
|
||||||
sysFiles.add(sysFile);
|
}
|
||||||
}
|
|
||||||
}
|
/**
|
||||||
|
* 字节转换
|
||||||
/**
|
*
|
||||||
* 字节转换
|
* @param size 字节大小
|
||||||
*
|
* @return 转换后值
|
||||||
* @param size 字节大小
|
*/
|
||||||
* @return 转换后值
|
public String convertFileSize(long size)
|
||||||
*/
|
{
|
||||||
public String convertFileSize(long size)
|
long kb = 1024;
|
||||||
{
|
long mb = kb * 1024;
|
||||||
long kb = 1024;
|
long gb = mb * 1024;
|
||||||
long mb = kb * 1024;
|
if (size >= gb)
|
||||||
long gb = mb * 1024;
|
{
|
||||||
if (size >= gb)
|
return String.format("%.1f GB", (float) size / gb);
|
||||||
{
|
}
|
||||||
return String.format("%.1f GB", (float) size / gb);
|
else if (size >= mb)
|
||||||
}
|
{
|
||||||
else if (size >= mb)
|
float f = (float) size / mb;
|
||||||
{
|
return String.format(f > 100 ? "%.0f MB" : "%.1f MB", f);
|
||||||
float f = (float) size / mb;
|
}
|
||||||
return String.format(f > 100 ? "%.0f MB" : "%.1f MB", f);
|
else if (size >= kb)
|
||||||
}
|
{
|
||||||
else if (size >= kb)
|
float f = (float) size / kb;
|
||||||
{
|
return String.format(f > 100 ? "%.0f KB" : "%.1f KB", f);
|
||||||
float f = (float) size / kb;
|
}
|
||||||
return String.format(f > 100 ? "%.0f KB" : "%.1f KB", f);
|
else
|
||||||
}
|
{
|
||||||
else
|
return String.format("%d B", size);
|
||||||
{
|
}
|
||||||
return String.format("%d B", size);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,73 +1,73 @@
|
||||||
package luckyclient.tool.jenkins;
|
package luckyclient.tool.jenkins;
|
||||||
|
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import com.offbytwo.jenkins.model.BuildResult;
|
import com.offbytwo.jenkins.model.BuildResult;
|
||||||
|
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
*
|
*
|
||||||
* @date 2017年12月1日 上午9:29:40
|
* @date 2017年12月1日 上午9:29:40
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class BuildingInitialization {
|
public class BuildingInitialization {
|
||||||
|
|
||||||
protected static int THREAD_COUNT = 0;
|
protected static int THREAD_COUNT = 0;
|
||||||
protected static int THREAD_SUCCOUNT = 0;
|
protected static int THREAD_SUCCOUNT = 0;
|
||||||
|
|
||||||
public static BuildResult buildingRun(String tastid) throws InterruptedException {
|
public static BuildResult buildingRun(String tastid) {
|
||||||
try {
|
try {
|
||||||
String[] jobName = serverOperation.getBuildName(tastid);
|
String[] jobName = serverOperation.getBuildName(tastid);
|
||||||
|
|
||||||
if (jobName != null) {
|
if (jobName != null) {
|
||||||
ThreadPoolExecutor threadExecute = new ThreadPoolExecutor(jobName.length, 10, 3, TimeUnit.SECONDS,
|
ThreadPoolExecutor threadExecute = new ThreadPoolExecutor(jobName.length, 10, 3, TimeUnit.SECONDS,
|
||||||
new ArrayBlockingQueue<Runnable>(1000),
|
new ArrayBlockingQueue<>(1000),
|
||||||
new ThreadPoolExecutor.CallerRunsPolicy());
|
new ThreadPoolExecutor.CallerRunsPolicy());
|
||||||
|
|
||||||
LogUtil.APP.info("准备将配置的测试项目进行构建!请稍等。。。。");
|
LogUtil.APP.info("准备将配置的测试项目进行构建!请稍等。。。。");
|
||||||
for (int i = 0; i < jobName.length; i++) {
|
for (String s : jobName) {
|
||||||
BuildingInitialization.THREAD_COUNT++; //多线程计数++,用于检测线程是否全部执行完
|
BuildingInitialization.THREAD_COUNT++; //多线程计数++,用于检测线程是否全部执行完
|
||||||
threadExecute.execute(new ThreadForBuildJob(jobName[i]));
|
threadExecute.execute(new ThreadForBuildJob(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
//多线程计数,用于检测线程是否全部执行完
|
//多线程计数,用于检测线程是否全部执行完
|
||||||
int k=0;
|
int k=0;
|
||||||
while(BuildingInitialization.THREAD_COUNT!=0){
|
while(BuildingInitialization.THREAD_COUNT!=0){
|
||||||
k++;
|
k++;
|
||||||
//最长等待构建时间45分钟
|
//最长等待构建时间45分钟
|
||||||
if(k>2700){
|
if(k>2700){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
threadExecute.shutdown();
|
threadExecute.shutdown();
|
||||||
|
|
||||||
if(jobName.length!=THREAD_SUCCOUNT){
|
if(jobName.length!=THREAD_SUCCOUNT){
|
||||||
LogUtil.APP.info("待构建项目{}个,构建成功的项目{}个,有构建任务异常或失败状态,详情请查看构建日志...",jobName.length,THREAD_SUCCOUNT);
|
LogUtil.APP.info("待构建项目{}个,构建成功的项目{}个,有构建任务异常或失败状态,详情请查看构建日志...",jobName.length,THREAD_SUCCOUNT);
|
||||||
return BuildResult.FAILURE;
|
return BuildResult.FAILURE;
|
||||||
}else{
|
}else{
|
||||||
LogUtil.APP.info("总共构建成功的项目{}个,全部构建成功,详情请查看构建日志...",THREAD_SUCCOUNT);
|
LogUtil.APP.info("总共构建成功的项目{}个,全部构建成功,详情请查看构建日志...",THREAD_SUCCOUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LogUtil.APP.info("当前任务没有找到需要构建的项目!");
|
LogUtil.APP.info("当前任务没有找到需要构建的项目!");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.APP.error("项目构建过程中出现异常", e);
|
LogUtil.APP.error("项目构建过程中出现异常", e);
|
||||||
return BuildResult.UNSTABLE;
|
return BuildResult.UNSTABLE;
|
||||||
}
|
}
|
||||||
return BuildResult.SUCCESS;
|
return BuildResult.SUCCESS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,70 +1,68 @@
|
||||||
package luckyclient.tool.jenkins;
|
package luckyclient.tool.jenkins;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import com.offbytwo.jenkins.JenkinsServer;
|
import com.offbytwo.jenkins.JenkinsServer;
|
||||||
import com.offbytwo.jenkins.client.JenkinsHttpClient;
|
import com.offbytwo.jenkins.client.JenkinsHttpClient;
|
||||||
|
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
import luckyclient.utils.config.SysConfig;
|
import luckyclient.utils.config.SysConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Jenkins链接
|
* Jenkins链接
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年10月29日
|
* @date 2019年10月29日
|
||||||
*/
|
*/
|
||||||
public class JenkinsConnect {
|
public class JenkinsConnect {
|
||||||
|
|
||||||
private String JENKINS_URL;
|
private String JENKINS_URL;
|
||||||
private String JENKINS_USERNAME;
|
private String JENKINS_USERNAME;
|
||||||
private String JENKINS_PASSWORD;
|
private String JENKINS_PASSWORD;
|
||||||
|
|
||||||
JenkinsConnect() {
|
JenkinsConnect() {
|
||||||
Properties properties = SysConfig.getConfiguration();
|
Properties properties = SysConfig.getConfiguration();
|
||||||
this.JENKINS_URL=properties.getProperty("jenkins.url");
|
this.JENKINS_URL=properties.getProperty("jenkins.url");
|
||||||
this.JENKINS_USERNAME=properties.getProperty("jenkins.username");
|
this.JENKINS_USERNAME=properties.getProperty("jenkins.username");
|
||||||
this.JENKINS_PASSWORD=properties.getProperty("jenkins.password");
|
this.JENKINS_PASSWORD=properties.getProperty("jenkins.password");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 如果有些 API 该Jar工具包未提供,可以用此Http客户端操作远程接口,执行命令
|
* 如果有些 API 该Jar工具包未提供,可以用此Http客户端操作远程接口,执行命令
|
||||||
* @return
|
* @return 返回jenkins客户端对象
|
||||||
* @author Seagull
|
*/
|
||||||
* @date 2019年10月29日
|
public JenkinsHttpClient getClient() {
|
||||||
*/
|
JenkinsHttpClient jenkinsHttpClient = null;
|
||||||
public JenkinsHttpClient getClient() {
|
try {
|
||||||
JenkinsHttpClient jenkinsHttpClient = null;
|
jenkinsHttpClient = new JenkinsHttpClient(new URI(JENKINS_URL), JENKINS_USERNAME, JENKINS_PASSWORD);
|
||||||
try {
|
} catch (URISyntaxException e) {
|
||||||
jenkinsHttpClient = new JenkinsHttpClient(new URI(JENKINS_URL), JENKINS_USERNAME, JENKINS_PASSWORD);
|
e.printStackTrace();
|
||||||
} catch (URISyntaxException e) {
|
}
|
||||||
e.printStackTrace();
|
return jenkinsHttpClient;
|
||||||
}
|
}
|
||||||
return jenkinsHttpClient;
|
|
||||||
}
|
/**
|
||||||
|
* Jenkins API链接
|
||||||
/**
|
* @return 返回jenkins服务对象
|
||||||
* Jenkins API链接
|
* @author Seagull
|
||||||
* @return
|
* @date 2019年10月29日
|
||||||
* @author Seagull
|
*/
|
||||||
* @date 2019年10月29日
|
public JenkinsServer connection() {
|
||||||
*/
|
JenkinsServer jenkinsServer = null;
|
||||||
public JenkinsServer connection() {
|
try {
|
||||||
JenkinsServer jenkinsServer = null;
|
LogUtil.APP.info("准备连接Jenkins...URL:{} 用户名:{} 密码:{}",JENKINS_URL,JENKINS_USERNAME,JENKINS_PASSWORD);
|
||||||
try {
|
jenkinsServer = new JenkinsServer(new URI(JENKINS_URL), JENKINS_USERNAME, JENKINS_PASSWORD);
|
||||||
LogUtil.APP.info("准备连接Jenkins...URL:{} 用户名:{} 密码:{}",JENKINS_URL,JENKINS_USERNAME,JENKINS_PASSWORD);
|
LogUtil.APP.info("连接Jenkins成功!");
|
||||||
jenkinsServer = new JenkinsServer(new URI(JENKINS_URL), JENKINS_USERNAME, JENKINS_PASSWORD);
|
LogUtil.APP.info("Jenkins版本:{}",jenkinsServer.getVersion());
|
||||||
LogUtil.APP.info("连接Jenkins成功!");
|
} catch (URISyntaxException e) {
|
||||||
LogUtil.APP.info("Jenkins版本:{}",jenkinsServer.getVersion());
|
LogUtil.APP.error("连接Jenkins出现异常",e);
|
||||||
} catch (URISyntaxException e) {
|
}
|
||||||
LogUtil.APP.error("连接Jenkins出现异常",e);
|
return jenkinsServer;
|
||||||
}
|
}
|
||||||
return jenkinsServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,94 +1,94 @@
|
||||||
package luckyclient.tool.jenkins;
|
package luckyclient.tool.jenkins;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.offbytwo.jenkins.JenkinsServer;
|
import com.offbytwo.jenkins.JenkinsServer;
|
||||||
import com.offbytwo.jenkins.model.BuildResult;
|
import com.offbytwo.jenkins.model.BuildResult;
|
||||||
import com.offbytwo.jenkins.model.BuildWithDetails;
|
import com.offbytwo.jenkins.model.BuildWithDetails;
|
||||||
import com.offbytwo.jenkins.model.ConsoleLog;
|
import com.offbytwo.jenkins.model.ConsoleLog;
|
||||||
import com.offbytwo.jenkins.model.JobWithDetails;
|
import com.offbytwo.jenkins.model.JobWithDetails;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * Job Build(任务构建) 相关操作 例如对任务 Build 相关的信息进行获取操作、例如获取构建日志
|
* * Job Build(任务构建) 相关操作 例如对任务 Build 相关的信息进行获取操作、例如获取构建日志
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年10月30日
|
* @date 2019年10月30日
|
||||||
*/
|
*/
|
||||||
public class JobBuildApi {
|
public class JobBuildApi {
|
||||||
|
|
||||||
// Jenkins 对象
|
// Jenkins 对象
|
||||||
private JenkinsServer jenkinsServer;
|
private JenkinsServer jenkinsServer;
|
||||||
// http 客户端对象
|
// http 客户端对象
|
||||||
//private JenkinsHttpClient jenkinsHttpClient;
|
//private JenkinsHttpClient jenkinsHttpClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造方法中调用连接 Jenkins 方法
|
* 构造方法中调用连接 Jenkins 方法
|
||||||
*
|
*
|
||||||
* 2019年10月30日
|
* 2019年10月30日
|
||||||
*/
|
*/
|
||||||
JobBuildApi() {
|
JobBuildApi() {
|
||||||
JenkinsConnect jenkinsConnect = new JenkinsConnect();
|
JenkinsConnect jenkinsConnect = new JenkinsConnect();
|
||||||
// 连接 Jenkins
|
// 连接 Jenkins
|
||||||
jenkinsServer = jenkinsConnect.connection();
|
jenkinsServer = jenkinsConnect.connection();
|
||||||
// 设置客户端连接 Jenkins
|
// 设置客户端连接 Jenkins
|
||||||
//jenkinsHttpClient = jenkinsConnect.getClient();
|
//jenkinsHttpClient = jenkinsConnect.getClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过job名称触发构建并获取构建结果
|
* 通过job名称触发构建并获取构建结果
|
||||||
* @param jobName
|
* @param jobName 任务名称
|
||||||
* @return
|
* @return 返回构建结果
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年11月29日
|
* @date 2019年11月29日
|
||||||
*/
|
*/
|
||||||
public BuildResult buildAndGetResultForJobName(String jobName) {
|
public BuildResult buildAndGetResultForJobName(String jobName) {
|
||||||
BuildResult buildResult = null;
|
BuildResult buildResult = null;
|
||||||
try {
|
try {
|
||||||
//触发构建
|
//触发构建
|
||||||
jenkinsServer.getJob(jobName).build(false);
|
jenkinsServer.getJob(jobName).build(false);
|
||||||
// 获取 Job 信息
|
// 获取 Job 信息
|
||||||
JobWithDetails job = jenkinsServer.getJob(jobName);
|
JobWithDetails job = jenkinsServer.getJob(jobName);
|
||||||
// 这里用最后一次编译来示例
|
// 这里用最后一次编译来示例
|
||||||
BuildWithDetails build = job.getLastBuild().details();
|
BuildWithDetails build = job.getLastBuild().details();
|
||||||
// 获取构建的显示名称
|
// 获取构建的显示名称
|
||||||
LogUtil.APP.info("构建项目:{}, 构建名称:{}", jobName,build.getDisplayName());
|
LogUtil.APP.info("构建项目:{}, 构建名称:{}", jobName,build.getDisplayName());
|
||||||
// 获取构建的参数信息
|
// 获取构建的参数信息
|
||||||
LogUtil.APP.info("构建项目:{}, 构建参数:{}", jobName,build.getParameters());
|
LogUtil.APP.info("构建项目:{}, 构建参数:{}", jobName,build.getParameters());
|
||||||
// 获取构建编号
|
// 获取构建编号
|
||||||
LogUtil.APP.info("构建项目:{}, 构建编号:{}", jobName,build.getNumber());
|
LogUtil.APP.info("构建项目:{}, 构建编号:{}", jobName,build.getNumber());
|
||||||
// 获取执行构建的活动信息
|
// 获取执行构建的活动信息
|
||||||
LogUtil.APP.info("构建项目:{}, 构建活动信息:{}", jobName,build.getActions());
|
LogUtil.APP.info("构建项目:{}, 构建活动信息:{}", jobName,build.getActions());
|
||||||
// 获取构建开始时间戳
|
// 获取构建开始时间戳
|
||||||
LogUtil.APP.info("构建项目:{}, 构建时间:{}", jobName,DateUtil.format(DateUtil.date(build.getTimestamp()), "yyyy-MM-dd HH:mm:ss"));
|
LogUtil.APP.info("构建项目:{}, 构建时间:{}", jobName,DateUtil.format(DateUtil.date(build.getTimestamp()), "yyyy-MM-dd HH:mm:ss"));
|
||||||
// 当前日志
|
// 当前日志
|
||||||
ConsoleLog currentLog = build.getConsoleOutputText(0);
|
ConsoleLog currentLog = build.getConsoleOutputText(0);
|
||||||
// 输出当前获取日志信息
|
// 输出当前获取日志信息
|
||||||
//LogUtil.APP.info(currentLog.getConsoleLog());
|
//LogUtil.APP.info(currentLog.getConsoleLog());
|
||||||
// 检测是否还有更多日志,如果是则继续循环获取
|
// 检测是否还有更多日志,如果是则继续循环获取
|
||||||
while (currentLog.getHasMoreData()) {
|
while (currentLog.getHasMoreData()) {
|
||||||
// 获取最新日志信息
|
// 获取最新日志信息
|
||||||
ConsoleLog newLog = build.getConsoleOutputText(currentLog.getCurrentBufferSize());
|
ConsoleLog newLog = build.getConsoleOutputText(currentLog.getCurrentBufferSize());
|
||||||
// 输出最新日志
|
// 输出最新日志
|
||||||
if(!StrUtil.isBlank(newLog.getConsoleLog())){
|
if(!StrUtil.isBlank(newLog.getConsoleLog())){
|
||||||
LogUtil.APP.info("构建项目:{}, 构建日志:{}",jobName,newLog.getConsoleLog());
|
LogUtil.APP.info("构建项目:{}, 构建日志:{}",jobName,newLog.getConsoleLog());
|
||||||
}
|
}
|
||||||
currentLog = newLog;
|
currentLog = newLog;
|
||||||
|
|
||||||
}
|
}
|
||||||
buildResult = job.getBuildByNumber(build.getNumber()).details().getResult();
|
buildResult = job.getBuildByNumber(build.getNumber()).details().getResult();
|
||||||
LogUtil.APP.info("构建项目:{}, 构建结果:>>>>>>>>>{}",jobName,buildResult.toString());
|
LogUtil.APP.info("构建项目:{}, 构建结果:>>>>>>>>>{}",jobName,buildResult.toString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogUtil.APP.error("获取执行任务状态出现异常", e);
|
LogUtil.APP.error("获取执行任务状态出现异常", e);
|
||||||
}
|
}
|
||||||
return buildResult;
|
return buildResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,45 +1,45 @@
|
||||||
package luckyclient.tool.shell;
|
package luckyclient.tool.shell;
|
||||||
|
|
||||||
import luckyclient.remote.api.serverOperation;
|
import luckyclient.remote.api.serverOperation;
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
||||||
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
* @date 2017年12月1日 上午9:29:40
|
* @date 2017年12月1日 上午9:29:40
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RestartServerInitialization {
|
public class RestartServerInitialization {
|
||||||
|
|
||||||
public static String restartServerRun(String tastid){
|
public static String restartServerRun(String tastid){
|
||||||
String result = "Status:true"+" 重启命令执行成功!";
|
String result;
|
||||||
try{
|
try{
|
||||||
String[] command = serverOperation.getRestartComm(tastid);
|
String[] command = serverOperation.getRestartComm(tastid);
|
||||||
if(command!=null){
|
if(command!=null){
|
||||||
LogUtil.APP.info("准备重启指定的TOMCAT!请稍等。。。参数个数:{}",command.length);
|
LogUtil.APP.info("准备重启指定的TOMCAT!请稍等。。。参数个数:{}",command.length);
|
||||||
if(command.length==5){
|
if(command.length==5){
|
||||||
LogUtil.APP.info("开始调用重启TOMCAT方法。。。参数0:{} 参数1:{} 参数2:{} 参数3:{} 参数4:{}",command[0],command[1],command[2],command[3],command[4]);
|
LogUtil.APP.info("开始调用重启TOMCAT方法。。。参数0:{} 参数1:{} 参数2:{} 参数3:{} 参数4:{}",command[0],command[1],command[2],command[3],command[4]);
|
||||||
result = RmtShellExecutor.sshShell(command[0], command[1], command[2], Integer.valueOf(command[3]), command[4]);
|
result = RmtShellExecutor.sshShell(command[0], command[1], command[2], Integer.parseInt(command[3]), command[4]);
|
||||||
}else{
|
}else{
|
||||||
LogUtil.APP.warn("重启TOMCAT命令行参数出现异常,请检查配置信息!");
|
LogUtil.APP.warn("重启TOMCAT命令行参数出现异常,请检查配置信息!");
|
||||||
result = "重启TOMCAT命令行参数出现异常,请检查配置信息!";
|
result = "重启TOMCAT命令行参数出现异常,请检查配置信息!";
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
result = "Status:true"+" 当前任务没有找到需要重启的TOMCAT命令!";
|
result = "Status:true"+" 当前任务没有找到需要重启的TOMCAT命令!";
|
||||||
LogUtil.APP.info("当前任务没有指定需要重启TOMCAT!");
|
LogUtil.APP.info("当前任务没有指定需要重启TOMCAT!");
|
||||||
}
|
}
|
||||||
}catch(Throwable e){
|
}catch(Throwable e){
|
||||||
LogUtil.APP.error("重启TOMCAT过程中出现异常",e);
|
LogUtil.APP.error("重启TOMCAT过程中出现异常",e);
|
||||||
result = "重启TOMCAT过程中出现异常";
|
result = "重启TOMCAT过程中出现异常";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
package luckyclient.tool.shell;
|
package luckyclient.tool.shell;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
@ -10,110 +11,95 @@ import luckyclient.utils.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 远程执行shell脚本类
|
* 远程执行shell脚本类
|
||||||
|
*
|
||||||
* @author l
|
* @author l
|
||||||
*/
|
*/
|
||||||
public class RmtShellExecutor {
|
public class RmtShellExecutor {
|
||||||
/**
|
/**
|
||||||
* 利用JSch包实现远程主机SHELL命令执行
|
* 利用JSch包实现远程主机SHELL命令执行
|
||||||
* @param ip 主机IP
|
*
|
||||||
* @param user 主机登陆用户名
|
* @param ip 主机IP
|
||||||
* @param psw 主机登陆密码
|
* @param user 主机登陆用户名
|
||||||
* @param port 主机ssh2登陆端口,如果取默认值,传-1
|
* @param psw 主机登陆密码
|
||||||
* @param command Shell命令 cd /home/pospsettle/tomcat-7.0-7080/bin&&./restart.sh
|
* @param port 主机ssh2登陆端口,如果取默认值,传-1
|
||||||
*/
|
* @param command Shell命令 cd /home/pospsettle/tomcat-7.0-7080/bin&&./restart.sh
|
||||||
public static String sshShell(String ip, String user, String psw
|
*/
|
||||||
,int port,String command) throws Exception{
|
public static String sshShell(String ip, String user, String psw
|
||||||
|
, int port, String command) {
|
||||||
Session session = null;
|
|
||||||
Channel channel = null;
|
|
||||||
String privateKey = "";
|
|
||||||
String passphrase = "";
|
|
||||||
String result = "Status:true"+" 重启命令执行成功!";
|
|
||||||
try {
|
|
||||||
JSch jsch = new JSch();
|
|
||||||
LogUtil.APP.info("进入到重启TOMCAT方法...");
|
|
||||||
//设置密钥和密码
|
|
||||||
if (privateKey != null && !"".equals(privateKey)) {
|
|
||||||
if (passphrase != null && "".equals(passphrase)) {
|
|
||||||
//设置带口令的密钥
|
|
||||||
jsch.addIdentity(privateKey, passphrase);
|
|
||||||
} else {
|
|
||||||
//设置不带口令的密钥
|
|
||||||
jsch.addIdentity(privateKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(port <=0){
|
|
||||||
//连接服务器,采用默认端口
|
|
||||||
LogUtil.APP.info("设置重启TOMCAT服务器IP及默认端口...");
|
|
||||||
session = jsch.getSession(user, ip);
|
|
||||||
}else{
|
|
||||||
//采用指定的端口连接服务器
|
|
||||||
LogUtil.APP.info("设置重启TOMCAT服务器IP及端口...");
|
|
||||||
session = jsch.getSession(user, ip ,port);
|
|
||||||
LogUtil.APP.info("设置重启TOMCAT服务器IP及端口完成!");
|
|
||||||
}
|
|
||||||
|
|
||||||
//如果服务器连接不上,则抛出异常
|
|
||||||
if (session == null) {
|
|
||||||
LogUtil.APP.warn("重启TOMCAT过程中,链接服务器session is null");
|
|
||||||
result = "重启TOMCAT过程中,链接服务器session is null";
|
|
||||||
throw new Exception("session is null");
|
|
||||||
}
|
|
||||||
//设置登陆主机的密码
|
|
||||||
session.setPassword(psw);
|
|
||||||
//设置第一次登陆的时候提示,可选值:(ask | yes | no)
|
|
||||||
session.setConfig("StrictHostKeyChecking", "no");
|
|
||||||
//设置登陆超时时间
|
|
||||||
session.connect(30000);
|
|
||||||
|
|
||||||
//创建sftp通信通道
|
|
||||||
channel = (Channel) session.openChannel("shell");
|
|
||||||
channel.connect(1000);
|
|
||||||
|
|
||||||
//获取输入流和输出流
|
|
||||||
InputStream instream = channel.getInputStream();
|
|
||||||
OutputStream outstream = channel.getOutputStream();
|
|
||||||
|
|
||||||
//发送需要执行的SHELL命令,需要用\n结尾,表示回车
|
|
||||||
LogUtil.APP.info("准备往重启TOMCAT服务器发送命令!");
|
|
||||||
String shellCommand = command+" \n";
|
|
||||||
outstream.write(shellCommand.getBytes());
|
|
||||||
outstream.flush();
|
|
||||||
|
|
||||||
Thread.sleep(10000);
|
Session session = null;
|
||||||
//获取命令执行的结果
|
Channel channel = null;
|
||||||
if (instream.available() > 0) {
|
String result = "Status:true" + " 重启命令执行成功!";
|
||||||
byte[] data = new byte[instream.available()];
|
try {
|
||||||
int nLen = instream.read(data);
|
JSch jsch = new JSch();
|
||||||
if (nLen < 0) {
|
LogUtil.APP.info("进入到重启TOMCAT方法...");
|
||||||
LogUtil.APP.warn("重启TOMCAT过程中,获取命令执行结果出现异常!");
|
|
||||||
result = "重启TOMCAT过程中,获取命令执行结果出现异常!";
|
|
||||||
throw new Exception("network error.");
|
|
||||||
}
|
|
||||||
|
|
||||||
//转换输出结果并打印出来
|
|
||||||
String temp = new String(data, 0, nLen,"iso8859-1");
|
|
||||||
LogUtil.APP.info("开始打印重启TOMCAT命令执行结果...",temp);
|
|
||||||
}
|
|
||||||
outstream.close();
|
|
||||||
instream.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
result = "重启TOMCAT过程中,出现异常!";
|
|
||||||
LogUtil.APP.error("重启TOMCAT过程中,出现异常!", e);
|
|
||||||
return result;
|
|
||||||
} finally {
|
|
||||||
if(null!=session){
|
|
||||||
session.disconnect();
|
|
||||||
}
|
|
||||||
if(null!=channel){
|
|
||||||
channel.disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
if (port <= 0) {
|
||||||
return result;
|
//连接服务器,采用默认端口
|
||||||
}
|
LogUtil.APP.info("设置重启TOMCAT服务器IP及默认端口...");
|
||||||
|
session = jsch.getSession(user, ip);
|
||||||
|
} else {
|
||||||
|
//采用指定的端口连接服务器
|
||||||
|
LogUtil.APP.info("设置重启TOMCAT服务器IP及端口...");
|
||||||
|
session = jsch.getSession(user, ip, port);
|
||||||
|
LogUtil.APP.info("设置重启TOMCAT服务器IP及端口完成!");
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
//如果服务器连接不上,则抛出异常
|
||||||
|
if (session == null) {
|
||||||
|
LogUtil.APP.warn("重启TOMCAT过程中,链接服务器session is null");
|
||||||
|
throw new Exception("session is null");
|
||||||
|
}
|
||||||
|
//设置登陆主机的密码
|
||||||
|
session.setPassword(psw);
|
||||||
|
//设置第一次登陆的时候提示,可选值:(ask | yes | no)
|
||||||
|
session.setConfig("StrictHostKeyChecking", "no");
|
||||||
|
//设置登陆超时时间
|
||||||
|
session.connect(30000);
|
||||||
|
|
||||||
|
//创建sftp通信通道
|
||||||
|
channel = session.openChannel("shell");
|
||||||
|
channel.connect(1000);
|
||||||
|
|
||||||
|
//获取输入流和输出流
|
||||||
|
InputStream instream = channel.getInputStream();
|
||||||
|
OutputStream outstream = channel.getOutputStream();
|
||||||
|
|
||||||
|
//发送需要执行的SHELL命令,需要用\n结尾,表示回车
|
||||||
|
LogUtil.APP.info("准备往重启TOMCAT服务器发送命令!");
|
||||||
|
String shellCommand = command + " \n";
|
||||||
|
outstream.write(shellCommand.getBytes());
|
||||||
|
outstream.flush();
|
||||||
|
|
||||||
|
Thread.sleep(10000);
|
||||||
|
//获取命令执行的结果
|
||||||
|
if (instream.available() > 0) {
|
||||||
|
byte[] data = new byte[instream.available()];
|
||||||
|
int nLen = instream.read(data);
|
||||||
|
if (nLen < 0) {
|
||||||
|
LogUtil.APP.warn("重启TOMCAT过程中,获取命令执行结果出现异常!");
|
||||||
|
}
|
||||||
|
|
||||||
|
//转换输出结果并打印出来
|
||||||
|
String temp = new String(data, 0, nLen, "iso8859-1");
|
||||||
|
LogUtil.APP.info("开始打印重启TOMCAT命令执行结果...{}", temp);
|
||||||
|
}
|
||||||
|
outstream.close();
|
||||||
|
instream.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
result = "重启TOMCAT过程中,出现异常!";
|
||||||
|
LogUtil.APP.error("重启TOMCAT过程中,出现异常!", e);
|
||||||
|
return result;
|
||||||
|
} finally {
|
||||||
|
if (null != session) {
|
||||||
|
session.disconnect();
|
||||||
|
}
|
||||||
|
if (null != channel) {
|
||||||
|
channel.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,163 +1,160 @@
|
||||||
package luckyclient.utils;
|
package luckyclient.utils;
|
||||||
|
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 时间工具类
|
* 时间工具类
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年5月5日
|
* @date 2019年5月5日
|
||||||
*/
|
*/
|
||||||
public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||||
{
|
{
|
||||||
public static String YYYY = "yyyy";
|
|
||||||
|
public static String YYYY_MM_DD = "yyyy-MM-dd";
|
||||||
public static String YYYY_MM = "yyyy-MM";
|
|
||||||
|
public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
|
||||||
public static String YYYY_MM_DD = "yyyy-MM-dd";
|
|
||||||
|
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
||||||
public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
|
|
||||||
|
private static String[] parsePatterns = {
|
||||||
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
|
||||||
|
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
|
||||||
private static String[] parsePatterns = {
|
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
|
||||||
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
|
|
||||||
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
|
/**
|
||||||
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
|
* 获取当前Date型日期
|
||||||
|
*
|
||||||
/**
|
* @return Date() 当前日期
|
||||||
* 获取当前Date型日期
|
*/
|
||||||
*
|
public static Date getNowDate()
|
||||||
* @return Date() 当前日期
|
{
|
||||||
*/
|
return new Date();
|
||||||
public static Date getNowDate()
|
}
|
||||||
{
|
|
||||||
return new Date();
|
/**
|
||||||
}
|
* 获取当前日期, 默认格式为yyyy-MM-dd
|
||||||
|
*
|
||||||
/**
|
* @return String
|
||||||
* 获取当前日期, 默认格式为yyyy-MM-dd
|
*/
|
||||||
*
|
public static String getDate()
|
||||||
* @return String
|
{
|
||||||
*/
|
return dateTimeNow(YYYY_MM_DD);
|
||||||
public static String getDate()
|
}
|
||||||
{
|
|
||||||
return dateTimeNow(YYYY_MM_DD);
|
public static String getTime()
|
||||||
}
|
{
|
||||||
|
return dateTimeNow(YYYY_MM_DD_HH_MM_SS);
|
||||||
public static final String getTime()
|
}
|
||||||
{
|
|
||||||
return dateTimeNow(YYYY_MM_DD_HH_MM_SS);
|
public static String dateTimeNow()
|
||||||
}
|
{
|
||||||
|
return dateTimeNow(YYYYMMDDHHMMSS);
|
||||||
public static final String dateTimeNow()
|
}
|
||||||
{
|
|
||||||
return dateTimeNow(YYYYMMDDHHMMSS);
|
public static String dateTimeNow(final String format)
|
||||||
}
|
{
|
||||||
|
return parseDateToStr(format, new Date());
|
||||||
public static final String dateTimeNow(final String format)
|
}
|
||||||
{
|
|
||||||
return parseDateToStr(format, new Date());
|
public static String dateTime(final Date date)
|
||||||
}
|
{
|
||||||
|
return parseDateToStr(YYYY_MM_DD, date);
|
||||||
public static final String dateTime(final Date date)
|
}
|
||||||
{
|
|
||||||
return parseDateToStr(YYYY_MM_DD, date);
|
public static String parseDateToStr(final String format, final Date date)
|
||||||
}
|
{
|
||||||
|
return new SimpleDateFormat(format).format(date);
|
||||||
public static final String parseDateToStr(final String format, final Date date)
|
}
|
||||||
{
|
|
||||||
return new SimpleDateFormat(format).format(date);
|
public static Date dateTime(final String format, final String ts)
|
||||||
}
|
{
|
||||||
|
try
|
||||||
public static final Date dateTime(final String format, final String ts)
|
{
|
||||||
{
|
return new SimpleDateFormat(format).parse(ts);
|
||||||
try
|
}
|
||||||
{
|
catch (ParseException e)
|
||||||
return new SimpleDateFormat(format).parse(ts);
|
{
|
||||||
}
|
throw new RuntimeException(e);
|
||||||
catch (ParseException e)
|
}
|
||||||
{
|
}
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
/**
|
||||||
}
|
* 日期路径 即年/月/日 如2018/08/08
|
||||||
|
*/
|
||||||
/**
|
public static String datePath()
|
||||||
* 日期路径 即年/月/日 如2018/08/08
|
{
|
||||||
*/
|
Date now = new Date();
|
||||||
public static final String datePath()
|
return DateFormatUtils.format(now, "yyyy/MM/dd");
|
||||||
{
|
}
|
||||||
Date now = new Date();
|
|
||||||
return DateFormatUtils.format(now, "yyyy/MM/dd");
|
/**
|
||||||
}
|
* 日期路径 即年/月/日 如20180808
|
||||||
|
*/
|
||||||
/**
|
public static String dateTime()
|
||||||
* 日期路径 即年/月/日 如20180808
|
{
|
||||||
*/
|
Date now = new Date();
|
||||||
public static final String dateTime()
|
return DateFormatUtils.format(now, "yyyyMMdd");
|
||||||
{
|
}
|
||||||
Date now = new Date();
|
|
||||||
return DateFormatUtils.format(now, "yyyyMMdd");
|
/**
|
||||||
}
|
* 日期型字符串转化为日期 格式
|
||||||
|
*/
|
||||||
/**
|
public static Date parseDate(Object str)
|
||||||
* 日期型字符串转化为日期 格式
|
{
|
||||||
*/
|
if (str == null)
|
||||||
public static Date parseDate(Object str)
|
{
|
||||||
{
|
return null;
|
||||||
if (str == null)
|
}
|
||||||
{
|
try
|
||||||
return null;
|
{
|
||||||
}
|
return parseDate(str.toString(), parsePatterns);
|
||||||
try
|
}
|
||||||
{
|
catch (ParseException e)
|
||||||
return parseDate(str.toString(), parsePatterns);
|
{
|
||||||
}
|
return null;
|
||||||
catch (ParseException e)
|
}
|
||||||
{
|
}
|
||||||
return null;
|
|
||||||
}
|
/**
|
||||||
}
|
* 获取服务器启动时间
|
||||||
|
*/
|
||||||
/**
|
public static Date getServerStartDate()
|
||||||
* 获取服务器启动时间
|
{
|
||||||
*/
|
long time = ManagementFactory.getRuntimeMXBean().getStartTime();
|
||||||
public static Date getServerStartDate()
|
return new Date(time);
|
||||||
{
|
}
|
||||||
long time = ManagementFactory.getRuntimeMXBean().getStartTime();
|
|
||||||
return new Date(time);
|
/**
|
||||||
}
|
* 计算两个时间差
|
||||||
|
*/
|
||||||
/**
|
public static String getDatePoor(Date endDate, Date nowDate)
|
||||||
* 计算两个时间差
|
{
|
||||||
*/
|
if(null==nowDate){
|
||||||
public static String getDatePoor(Date endDate, Date nowDate)
|
return 0 + "天" + 0 + "小时" + 0 + "分钟";
|
||||||
{
|
}
|
||||||
if(null==nowDate){
|
|
||||||
return 0 + "天" + 0 + "小时" + 0 + "分钟";
|
long nd = 1000 * 24 * 60 * 60;
|
||||||
}
|
long nh = 1000 * 60 * 60;
|
||||||
|
long nm = 1000 * 60;
|
||||||
long nd = 1000 * 24 * 60 * 60;
|
// long ns = 1000;
|
||||||
long nh = 1000 * 60 * 60;
|
// 获得两个时间的毫秒时间差异
|
||||||
long nm = 1000 * 60;
|
long diff = endDate.getTime() - nowDate.getTime();
|
||||||
// long ns = 1000;
|
// 计算差多少天
|
||||||
// 获得两个时间的毫秒时间差异
|
long day = diff / nd;
|
||||||
long diff = endDate.getTime() - nowDate.getTime();
|
// 计算差多少小时
|
||||||
// 计算差多少天
|
long hour = diff % nd / nh;
|
||||||
long day = diff / nd;
|
// 计算差多少分钟
|
||||||
// 计算差多少小时
|
long min = diff % nd % nh / nm;
|
||||||
long hour = diff % nd / nh;
|
// 计算差多少秒//输出结果
|
||||||
// 计算差多少分钟
|
// long sec = diff % nd % nh % nm / ns;
|
||||||
long min = diff % nd % nh / nm;
|
return day + "天" + hour + "小时" + min + "分钟";
|
||||||
// 计算差多少秒//输出结果
|
}
|
||||||
// long sec = diff % nd % nh % nm / ns;
|
}
|
||||||
return day + "天" + hour + "小时" + min + "分钟";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,148 +4,140 @@ import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.ResultSetMetaData;
|
import java.sql.ResultSetMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
||||||
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* @ClassName: DBOperation
|
*
|
||||||
|
* @ClassName: DBOperation
|
||||||
* @Description: 封装自动化过程中,对数据库的部分操作
|
* @Description: 封装自动化过程中,对数据库的部分操作
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
* @date 2014年8月24日 上午9:29:40
|
* @date 2014年8月24日 上午9:29:40
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class DbOperation {
|
public class DbOperation {
|
||||||
|
|
||||||
DbToolkit dbt =null;
|
DbToolkit dbt;
|
||||||
/**
|
|
||||||
* 创建链接池,注意此方法不能new多次,会导致多次创建链接池,最好放在任务启动方法中
|
/**
|
||||||
*/
|
* 创建链接池,注意此方法不能new多次,会导致多次创建链接池,最好放在任务启动方法中
|
||||||
public DbOperation(String urlBase,String usernameBase,String passwordBase) {
|
*/
|
||||||
dbt = new DbToolkit(urlBase,usernameBase,passwordBase);
|
public DbOperation(String urlBase, String usernameBase, String passwordBase) {
|
||||||
}
|
dbt = new DbToolkit(urlBase, usernameBase, passwordBase);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行SQL
|
/**
|
||||||
* @param sql
|
* 执行SQL
|
||||||
* @throws Exception
|
*
|
||||||
*/
|
* @param sql 执行SQL语句
|
||||||
public String executeSql(String sql) throws Exception{
|
*/
|
||||||
Connection conn = null;
|
public String executeSql(String sql) {
|
||||||
String result;
|
Connection conn = null;
|
||||||
try{
|
String result;
|
||||||
conn = dbt.getBaseConnection();
|
try {
|
||||||
int resultnum = DbToolkit.executeSQL(conn, sql);
|
conn = dbt.getBaseConnection();
|
||||||
if(resultnum>0){
|
int resultnum = DbToolkit.executeSQL(conn, sql);
|
||||||
result= "成功执行SQL,更新数据"+resultnum+"行!";
|
if (resultnum > 0) {
|
||||||
}else{
|
result = "成功执行SQL,更新数据" + resultnum + "行!";
|
||||||
result= "成功执行SQL,没有更新到数据!";
|
} else {
|
||||||
}
|
result = "成功执行SQL,没有更新到数据!";
|
||||||
return result;
|
}
|
||||||
}catch(Exception e){
|
return result;
|
||||||
return e.toString();
|
} catch (Exception e) {
|
||||||
}finally{
|
return e.toString();
|
||||||
DbToolkit.closeConnection(conn);
|
} finally {
|
||||||
}
|
DbToolkit.closeConnection(conn);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
* 执行SQL流水查询
|
/**
|
||||||
* @param sql
|
* 执行SQL流水查询
|
||||||
* @throws SQLException
|
*
|
||||||
*/
|
* @param sql 查询SQL语句
|
||||||
public String executeQuery(String sql) throws Exception{
|
*/
|
||||||
Connection conn = null;
|
public String executeQuery(String sql) throws Exception {
|
||||||
ResultSet rs=null;
|
Connection conn = null;
|
||||||
try{
|
ResultSet rs = null;
|
||||||
conn = dbt.getBaseConnection();
|
try {
|
||||||
StringBuffer sb = new StringBuffer();
|
conn = dbt.getBaseConnection();
|
||||||
rs = DbToolkit.executeQuery(conn, sql);
|
StringBuilder sb = new StringBuilder();
|
||||||
ResultSetMetaData metaData = rs.getMetaData();
|
rs = DbToolkit.executeQuery(conn, sql);
|
||||||
int colum = metaData.getColumnCount();
|
ResultSetMetaData metaData = rs.getMetaData();
|
||||||
int count=0;
|
int colum = metaData.getColumnCount();
|
||||||
//行数
|
int count = 0;
|
||||||
while(rs.next()){
|
//行数
|
||||||
count++;
|
while (rs.next()) {
|
||||||
if (count > 1){
|
count++;
|
||||||
sb.append("#");
|
if (count > 1) {
|
||||||
}
|
sb.append("#");
|
||||||
//列数
|
}
|
||||||
for (int i = 1; i <= colum; i++){
|
//列数
|
||||||
if(rs.getObject(metaData.getColumnName(i))== null){
|
for (int i = 1; i <= colum; i++) {
|
||||||
sb.append("null").append("%");
|
if (rs.getObject(metaData.getColumnName(i)) == null) {
|
||||||
continue;
|
sb.append("null").append("%");
|
||||||
}
|
continue;
|
||||||
sb.append(rs.getObject(metaData.getColumnName(i)).toString()).append("%");
|
}
|
||||||
}
|
sb.append(rs.getObject(metaData.getColumnName(i)).toString()).append("%");
|
||||||
|
}
|
||||||
/* if(DbOperation.sumString(sb.toString(), "%")>500){
|
/* if(DbOperation.sumString(sb.toString(), "%")>500){
|
||||||
sb.delete(0,sb.length());
|
sb.delete(0,sb.length());
|
||||||
sb.append("查询出来的数据太多啦(超过100项)!我显示不过来哦。。。。");
|
sb.append("查询出来的数据太多啦(超过100项)!我显示不过来哦。。。。");
|
||||||
break;
|
break;
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}catch(Exception e){
|
} finally {
|
||||||
throw e;
|
if (rs != null) {
|
||||||
}finally{
|
rs.close();
|
||||||
if(rs!=null){
|
}
|
||||||
rs.close();
|
DbToolkit.closeConnection(conn);
|
||||||
}
|
}
|
||||||
DbToolkit.closeConnection(conn);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* 截取字符串
|
||||||
* @Title: subString
|
*
|
||||||
|
* @return String
|
||||||
* @Description: 截取字符串
|
* @Description: 截取字符串
|
||||||
* @return String
|
|
||||||
* @throws
|
|
||||||
*/
|
*/
|
||||||
public String subString(String str,String begin,String end){
|
public String subString(String str, String begin, String end) {
|
||||||
try{
|
try {
|
||||||
return str.substring(str.indexOf(begin)+begin.length(), str.lastIndexOf(end));
|
return str.substring(str.indexOf(begin) + begin.length(), str.lastIndexOf(end));
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @Title: sumString
|
|
||||||
* @Description: 统计字符在字符串中出现的次数
|
|
||||||
* @return int
|
|
||||||
* @throws
|
|
||||||
*/
|
|
||||||
public static int sumString(String str,String a){
|
|
||||||
char chs[]=a.toCharArray();
|
|
||||||
int num = 0;
|
|
||||||
char[] chars = str.toCharArray();
|
|
||||||
for(int i = 0; i < chars.length; i++){
|
|
||||||
if(chs[0] == chars[i])
|
|
||||||
{
|
|
||||||
num++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return num;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws InterruptedException
|
/**
|
||||||
*
|
* 统计字符在字符串中出现的次数
|
||||||
* @Title: Wait
|
*
|
||||||
* @Description: 等待时间
|
|
||||||
* @return int
|
* @return int
|
||||||
* @throws
|
|
||||||
*/
|
*/
|
||||||
public static void stepWait(String s) throws InterruptedException{
|
public static int sumString(String str, String a) {
|
||||||
int second = Integer.parseInt(s);
|
char[] chs = a.toCharArray();
|
||||||
Thread.sleep(second*1000);
|
int num = 0;
|
||||||
}
|
char[] chars = str.toCharArray();
|
||||||
|
for (char aChar : chars) {
|
||||||
|
if (chs[0] == aChar) {
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wait等待时间
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static void stepWait(String s) throws InterruptedException {
|
||||||
|
int second = Integer.parseInt(s);
|
||||||
|
Thread.sleep(second * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class DbToolkit {
|
||||||
/**
|
/**
|
||||||
* 建立数据库链接池
|
* 建立数据库链接池
|
||||||
*/
|
*/
|
||||||
public ComboPooledDataSource cpds=null;
|
public ComboPooledDataSource cpds;
|
||||||
private static final String DRIVERCLASS = DrivenConfig.getConfiguration().getProperty("db.ComboPooledDataSource.DriverClass");
|
private static final String DRIVERCLASS = DrivenConfig.getConfiguration().getProperty("db.ComboPooledDataSource.DriverClass");
|
||||||
|
|
||||||
public DbToolkit(String urlBase,String usernameBase,String passwordBase){
|
public DbToolkit(String urlBase,String usernameBase,String passwordBase){
|
||||||
|
@ -57,8 +57,7 @@ public class DbToolkit {
|
||||||
|
|
||||||
public Connection getBaseConnection() throws SQLException{
|
public Connection getBaseConnection() throws SQLException{
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
Connection conn = cpds.getConnection();
|
return cpds.getConnection();
|
||||||
return conn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,25 +65,22 @@ public class DbToolkit {
|
||||||
*
|
*
|
||||||
* @param conn 数据库连接
|
* @param conn 数据库连接
|
||||||
* @param staticSql 静态SQL语句字符串
|
* @param staticSql 静态SQL语句字符串
|
||||||
* @return 返回查询结果集ResultSet对象
|
* @return 返回查询结果集ResultSet对象
|
||||||
* @throws SQLException
|
|
||||||
*/
|
*/
|
||||||
public static ResultSet executeQuery(Connection conn, String staticSql) throws SQLException {
|
public static ResultSet executeQuery(Connection conn, String staticSql) throws SQLException {
|
||||||
//创建执行SQL的对象
|
//创建执行SQL的对象
|
||||||
Statement stmt = conn.createStatement();
|
Statement stmt = conn.createStatement();
|
||||||
|
|
||||||
//执行SQL,并获取返回结果
|
//执行SQL,并获取返回结果
|
||||||
ResultSet rs = stmt.executeQuery(staticSql);
|
// stmt.close();
|
||||||
// stmt.close();
|
return stmt.executeQuery(staticSql);
|
||||||
return rs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在一个数据库连接上执行一个静态SQL语句
|
* 在一个数据库连接上执行一个静态SQL语句
|
||||||
*
|
*
|
||||||
* @param conn 数据库连接
|
* @param conn 数据库连接
|
||||||
* @param staticSql 静态SQL语句字符串
|
* @param staticSql 静态SQL语句字符串
|
||||||
* @throws SQLException
|
|
||||||
*/
|
*/
|
||||||
public static int executeSQL(Connection conn, String staticSql) throws SQLException {
|
public static int executeSQL(Connection conn, String staticSql) throws SQLException {
|
||||||
//创建执行SQL的对象
|
//创建执行SQL的对象
|
||||||
|
|
|
@ -1,79 +1,80 @@
|
||||||
package luckyclient.utils;
|
package luckyclient.utils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改
|
||||||
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
* 有任何疑问欢迎联系作者讨论。 QQ:1573584944 seagull1985
|
||||||
* =================================================================
|
* =================================================================
|
||||||
*
|
*
|
||||||
* @author: seagull
|
* @author: seagull
|
||||||
* @date 2017年12月1日 上午9:29:40
|
* @date 2017年12月1日 上午9:29:40
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class JarClassFind {
|
public class JarClassFind {
|
||||||
|
|
||||||
private static void findClassInLocalSystem(String path,String classname) {
|
private static void findClassInLocalSystem(String path,String classname) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
//String path = "D:\\web_task\\TestFrame\\lib\\"; //指定查找路径
|
//String path = "D:\\web_task\\TestFrame\\lib\\"; //指定查找路径
|
||||||
classname = classname.replace('.', '/') + ".class";
|
classname = classname.replace('.', '/') + ".class";
|
||||||
|
|
||||||
//JavaBaseTest.LogUtil.APP.info("即将去服务器路径【" + path + "】下查找类【" + classname + "】 !");
|
//JavaBaseTest.LogUtil.APP.info("即将去服务器路径【" + path + "】下查找类【" + classname + "】 !");
|
||||||
System.out.println("即将去服务器路径【" + path + "】下查找类【" + classname + "】 !");
|
System.out.println("即将去服务器路径【" + path + "】下查找类【" + classname + "】 !");
|
||||||
if (path.charAt(path.length() - 1) != '\\') {
|
if (path.charAt(path.length() - 1) != '\\') {
|
||||||
path += '\\';
|
path += '\\';
|
||||||
}
|
}
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
//JavaBaseTest.LogUtil.ERROR.error("找不到本地指定包查找路径!");
|
//JavaBaseTest.LogUtil.ERROR.error("找不到本地指定包查找路径!");
|
||||||
System.out.println("找不到本地指定包查找路径!");
|
System.out.println("找不到本地指定包查找路径!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] filelist = file.list();
|
String[] filelist = file.list();
|
||||||
for (int i = 0; i < filelist.length; i++) {
|
assert filelist != null;
|
||||||
File temp = new File(path + filelist[i]);
|
for (String s : filelist) {
|
||||||
if ((temp.isDirectory() && !temp.isHidden() && temp.exists())&&filelist[i].equals(classname)) {
|
File temp = new File(path + s);
|
||||||
count++;
|
if ((temp.isDirectory() && !temp.isHidden() && temp.exists()) && s.equals(classname)) {
|
||||||
System.out.println("【"+path + filelist[i]+"】查找到第"+count+"个JAR包存在指定类!");
|
count++;
|
||||||
} else {
|
System.out.println("【" + path + s + "】查找到第" + count + "个JAR包存在指定类!");
|
||||||
if (filelist[i].endsWith("jar")) {
|
} else {
|
||||||
try {
|
if (s.endsWith("jar")) {
|
||||||
JarFile jarfile = new java.util.jar.JarFile(path + filelist[i]);
|
try {
|
||||||
for (Enumeration<JarEntry> e = jarfile.entries(); e.hasMoreElements();) {
|
JarFile jarfile = new JarFile(path + s);
|
||||||
String name = e.nextElement().toString();
|
for (Enumeration<JarEntry> e = jarfile.entries(); e.hasMoreElements(); ) {
|
||||||
if (name.equals(classname) || name.indexOf(classname) > -1) {
|
String name = e.nextElement().toString();
|
||||||
count++;
|
if (name.equals(classname) || name.contains(classname)) {
|
||||||
//JavaBaseTest.LogUtil.APP.info("【"+path + filelist[i]+"】查找到第"+count+"个JAR包存在指定类!");
|
count++;
|
||||||
System.out.println("【"+path + filelist[i]+"】查找到第"+count+"个JAR包存在指定类!");
|
//JavaBaseTest.LogUtil.APP.info("【"+path + filelist[i]+"】查找到第"+count+"个JAR包存在指定类!");
|
||||||
}
|
System.out.println("【" + path + s + "】查找到第" + count + "个JAR包存在指定类!");
|
||||||
}
|
}
|
||||||
jarfile.close();
|
}
|
||||||
} catch (Exception e) {
|
jarfile.close();
|
||||||
|
} catch (Exception ignored) {
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(count==0){
|
|
||||||
//JavaBaseTest.LogUtil.APP.info("没有在当前路径下找到指定类");
|
if(count==0){
|
||||||
System.out.println("没有在当前路径下找到指定类");
|
//JavaBaseTest.LogUtil.APP.info("没有在当前路径下找到指定类");
|
||||||
}else if(count==1){
|
System.out.println("没有在当前路径下找到指定类");
|
||||||
//JavaBaseTest.LogUtil.APP.info("在当前路径下只找到一个存在的指定类,不存在类冲突情况!");
|
}else if(count==1){
|
||||||
System.out.println("在当前路径下只找到一个存在的指定类,不存在类冲突情况!");
|
//JavaBaseTest.LogUtil.APP.info("在当前路径下只找到一个存在的指定类,不存在类冲突情况!");
|
||||||
}
|
System.out.println("在当前路径下只找到一个存在的指定类,不存在类冲突情况!");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
static public void main(String[] args) {
|
|
||||||
String path = args[0];
|
static public void main(String[] args) {
|
||||||
String classname = args[1];
|
String path = args[0];
|
||||||
findClassInLocalSystem(path,classname);
|
String classname = args[1];
|
||||||
}
|
findClassInLocalSystem(path,classname);
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,57 +1,54 @@
|
||||||
package luckyclient.utils;
|
package luckyclient.utils;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统日志记录
|
* 系统日志记录
|
||||||
* @author Seagull
|
*
|
||||||
*
|
* @author Seagull
|
||||||
*/
|
*/
|
||||||
public class LogUtil {
|
public class LogUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主要使用三种日志级别,info,warn,error
|
* 主要使用三种日志级别,info,warn,error
|
||||||
* info 记录客户端系统日志,监控客户端运行情况
|
* info 记录客户端系统日志,监控客户端运行情况
|
||||||
* warn 记录客户端业务上的告警日志
|
* warn 记录客户端业务上的告警日志
|
||||||
* error 记录客户端在执行过程中抛出的异常以及严重错误
|
* error 记录客户端在执行过程中抛出的异常以及严重错误
|
||||||
*/
|
*/
|
||||||
public static final Logger APP = LoggerFactory.getLogger("info");
|
public static final Logger APP = LoggerFactory.getLogger("info");
|
||||||
|
|
||||||
public static StringBuffer getFieldValue(Object bean){
|
public static StringBuffer getFieldValue(Object bean) {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
try{
|
try {
|
||||||
if(bean==null){
|
if (bean == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Field[] fieldArray = bean.getClass().getDeclaredFields();
|
Field[] fieldArray = bean.getClass().getDeclaredFields();
|
||||||
if(fieldArray != null){
|
int indexId = 0;
|
||||||
int indexId = 0;
|
Object obj;
|
||||||
Object obj = null;
|
for (Field field : fieldArray) {
|
||||||
for(Field field:fieldArray){
|
field.setAccessible(true);
|
||||||
field.setAccessible(true);
|
obj = field.get(bean);
|
||||||
obj = field.get(bean);
|
if (!(obj instanceof List) && !"serialVersionUID".equals(field.getName())) {
|
||||||
if(!(obj instanceof List) && !"serialVersionUID".equals(field.getName())){
|
if (indexId > 0) {
|
||||||
if(indexId>0){
|
sb.append(",");
|
||||||
sb.append(",");
|
}
|
||||||
}
|
if (obj != null) {
|
||||||
if(obj != null){
|
sb.append(field.getName()).append("=").append(obj.toString());
|
||||||
sb.append(field.getName()).append("=").append( obj.toString());
|
} else {
|
||||||
}else{
|
sb.append(field.getName()).append("=");
|
||||||
sb.append(field.getName()).append("=");
|
}
|
||||||
}
|
indexId += 1;
|
||||||
indexId += 1;
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception ex) {
|
||||||
}
|
LogUtil.APP.error("日志异常", ex);
|
||||||
}
|
}
|
||||||
catch(Exception ex){
|
return sb;
|
||||||
LogUtil.APP.error("日志异常",ex);
|
}
|
||||||
}
|
}
|
||||||
return sb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,31 +1,32 @@
|
||||||
package luckyclient.utils.config;
|
package luckyclient.utils.config;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.Properties;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Properties;
|
||||||
import luckyclient.utils.LogUtil;
|
|
||||||
|
import luckyclient.utils.LogUtil;
|
||||||
/**
|
|
||||||
* 初始化Appium配置参数
|
/**
|
||||||
* @author seagull
|
* 初始化Appium配置参数
|
||||||
*
|
* @author seagull
|
||||||
*/
|
*
|
||||||
public class AppiumConfig {
|
*/
|
||||||
private static final Properties SYS_CONFIG = new Properties();
|
public class AppiumConfig {
|
||||||
private static final String SYS_CONFIG_FILE = "/appium_config.properties";
|
private static final Properties SYS_CONFIG = new Properties();
|
||||||
static{
|
private static final String SYS_CONFIG_FILE = "/appium_config.properties";
|
||||||
try {
|
static{
|
||||||
InputStream in = new BufferedInputStream(AppiumConfig.class.getResourceAsStream(SYS_CONFIG_FILE));
|
try {
|
||||||
SYS_CONFIG.load(new InputStreamReader(in, "UTF-8"));
|
InputStream in = new BufferedInputStream(AppiumConfig.class.getResourceAsStream(SYS_CONFIG_FILE));
|
||||||
} catch (IOException e) {
|
SYS_CONFIG.load(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||||
LogUtil.APP.error("读取移动端appium_config.properties配置文件出现异常,请检查!", e);
|
} catch (IOException e) {
|
||||||
}
|
LogUtil.APP.error("读取移动端appium_config.properties配置文件出现异常,请检查!", e);
|
||||||
}
|
}
|
||||||
private AppiumConfig(){}
|
}
|
||||||
public static Properties getConfiguration(){
|
private AppiumConfig(){}
|
||||||
return SYS_CONFIG;
|
public static Properties getConfiguration(){
|
||||||
}
|
return SYS_CONFIG;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,35 +1,36 @@
|
||||||
package luckyclient.utils.config;
|
package luckyclient.utils.config;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.Properties;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Properties;
|
||||||
import luckyclient.utils.LogUtil;
|
|
||||||
|
import luckyclient.utils.LogUtil;
|
||||||
/**
|
|
||||||
* 初始化数据库驱动配置
|
/**
|
||||||
* =================================================================
|
* 初始化数据库驱动配置
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* =================================================================
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* =================================================================
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
||||||
* @author Seagull
|
* =================================================================
|
||||||
* @date 2020年2月17日
|
* @author Seagull
|
||||||
*/
|
* @date 2020年2月17日
|
||||||
public class DrivenConfig {
|
*/
|
||||||
private static final Properties SYS_CONFIG = new Properties();
|
public class DrivenConfig {
|
||||||
private static final String SYS_CONFIG_FILE = "/TestDriven/driven_config.properties";
|
private static final Properties SYS_CONFIG = new Properties();
|
||||||
static{
|
private static final String SYS_CONFIG_FILE = "/TestDriven/driven_config.properties";
|
||||||
try {
|
static{
|
||||||
InputStream in = new BufferedInputStream(DrivenConfig.class.getResourceAsStream(SYS_CONFIG_FILE));
|
try {
|
||||||
SYS_CONFIG.load(new InputStreamReader(in, "UTF-8"));
|
InputStream in = new BufferedInputStream(DrivenConfig.class.getResourceAsStream(SYS_CONFIG_FILE));
|
||||||
} catch (IOException e) {
|
SYS_CONFIG.load(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||||
LogUtil.APP.error("读取测试驱动driven_config.properties配置文件出现异常,请检查!", e);
|
} catch (IOException e) {
|
||||||
}
|
LogUtil.APP.error("读取测试驱动driven_config.properties配置文件出现异常,请检查!", e);
|
||||||
}
|
}
|
||||||
private DrivenConfig(){}
|
}
|
||||||
public static Properties getConfiguration(){
|
private DrivenConfig(){}
|
||||||
return SYS_CONFIG;
|
public static Properties getConfiguration(){
|
||||||
}
|
return SYS_CONFIG;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,16 +1,7 @@
|
||||||
package luckyclient.utils.httputils;
|
package luckyclient.utils.httputils;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import luckyclient.utils.LogUtil;
|
||||||
import java.io.IOException;
|
import luckyclient.utils.config.SysConfig;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.security.KeyManagementException;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.client.config.RequestConfig;
|
import org.apache.http.client.config.RequestConfig;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
|
@ -20,8 +11,11 @@ import org.apache.http.entity.StringEntity;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
|
||||||
import luckyclient.utils.LogUtil;
|
import java.io.*;
|
||||||
import luckyclient.utils.config.SysConfig;
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
|
@ -41,12 +35,12 @@ public class HttpRequest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字符串参数
|
* 字符串参数
|
||||||
* @param repath
|
* @param repath 请求路径
|
||||||
* @return
|
* @return 返回请求结果
|
||||||
*/
|
*/
|
||||||
public static String loadJSON(String repath) {
|
public static String loadJSON(String repath) {
|
||||||
String charset="GBK";
|
String charset="GBK";
|
||||||
StringBuffer resultBuffer = null;
|
StringBuffer resultBuffer;
|
||||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
// 构建请求参数
|
// 构建请求参数
|
||||||
|
@ -69,8 +63,6 @@ public class HttpRequest {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogUtil.APP.error("loadJSON发送请求后关闭br流出现异常,请检查!", e);
|
LogUtil.APP.error("loadJSON发送请求后关闭br流出现异常,请检查!", e);
|
||||||
br = null;
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,7 +78,7 @@ public class HttpRequest {
|
||||||
public static String sendPost(String repath, String param) {
|
public static String sendPost(String repath, String param) {
|
||||||
PrintWriter out = null;
|
PrintWriter out = null;
|
||||||
BufferedReader in = null;
|
BufferedReader in = null;
|
||||||
String result = "";
|
StringBuilder result = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
URL realUrl = new URL(WEB_URL+repath);
|
URL realUrl = new URL(WEB_URL+repath);
|
||||||
// 打开和URL之间的连接
|
// 打开和URL之间的连接
|
||||||
|
@ -109,7 +101,7 @@ public class HttpRequest {
|
||||||
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "GBK"));
|
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "GBK"));
|
||||||
String line;
|
String line;
|
||||||
while ((line = in.readLine()) != null) {
|
while ((line = in.readLine()) != null) {
|
||||||
result += line;
|
result.append(line);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.APP.error("向指定URL发送POST方法的请求出现异常,请检查!", e);
|
LogUtil.APP.error("向指定URL发送POST方法的请求出现异常,请检查!", e);
|
||||||
|
@ -128,17 +120,17 @@ public class HttpRequest {
|
||||||
LogUtil.APP.error("向指定URL发送POST方法的请求后关闭流出现异常,请检查!", ex);
|
LogUtil.APP.error("向指定URL发送POST方法的请求后关闭流出现异常,请检查!", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用HttpClient以JSON格式发送post请求
|
* 使用HttpClient以JSON格式发送post请求
|
||||||
* @param urlParam
|
* @param urlParam 请求路径
|
||||||
* @param params
|
* @param params 请求参数
|
||||||
* @return
|
* @return 返回请求结果
|
||||||
*/
|
*/
|
||||||
public static String httpClientPostJson(String urlParam, String params){
|
public static String httpClientPostJson(String urlParam, String params){
|
||||||
StringBuffer resultBuffer = null;
|
StringBuffer resultBuffer;
|
||||||
CloseableHttpClient httpclient=HttpClients.createDefault();
|
CloseableHttpClient httpclient=HttpClients.createDefault();
|
||||||
HttpPost httpPost = new HttpPost(WEB_URL+urlParam);
|
HttpPost httpPost = new HttpPost(WEB_URL+urlParam);
|
||||||
httpPost.setHeader("Content-Type", "application/json");
|
httpPost.setHeader("Content-Type", "application/json");
|
||||||
|
@ -159,7 +151,7 @@ public class HttpRequest {
|
||||||
// 读取服务器响应数据
|
// 读取服务器响应数据
|
||||||
resultBuffer = new StringBuffer();
|
resultBuffer = new StringBuffer();
|
||||||
if(null!=response.getEntity()){
|
if(null!=response.getEntity()){
|
||||||
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "utf-8"));
|
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8));
|
||||||
String temp;
|
String temp;
|
||||||
while ((temp = br.readLine()) != null) {
|
while ((temp = br.readLine()) != null) {
|
||||||
resultBuffer.append(temp);
|
resultBuffer.append(temp);
|
||||||
|
@ -173,9 +165,7 @@ public class HttpRequest {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
br = null;
|
|
||||||
LogUtil.APP.error("使用HttpClient以JSON格式发送post请求后关闭br流出现异常,请检查!", e);
|
LogUtil.APP.error("使用HttpClient以JSON格式发送post请求后关闭br流出现异常,请检查!", e);
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +1,34 @@
|
||||||
package luckyclient.utils.httputils;
|
package luckyclient.utils.httputils;
|
||||||
|
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
|
|
||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
* 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。
|
||||||
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
* 为了尊重作者的劳动成果,LuckyFrame关键版权信息严禁篡改 有任何疑问欢迎联系作者讨论。 QQ:1573584944 Seagull
|
||||||
* =================================================================
|
* =================================================================
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年8月8日
|
* @date 2019年8月8日
|
||||||
*/
|
*/
|
||||||
public class MyX509TrustManager implements X509TrustManager
|
public class MyX509TrustManager implements X509TrustManager
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void checkClientTrusted(X509Certificate ax509certificate[], String s) throws CertificateException
|
public void checkClientTrusted(X509Certificate[] ax509certificate, String s) {
|
||||||
{
|
//TODO nothing
|
||||||
//TODO nothing
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public void checkServerTrusted(X509Certificate[] ax509certificate, String s) {
|
||||||
public void checkServerTrusted(X509Certificate ax509certificate[], String s) throws CertificateException
|
//TODO nothing
|
||||||
{
|
}
|
||||||
//TODO nothing
|
|
||||||
}
|
@Override
|
||||||
|
public X509Certificate[] getAcceptedIssuers()
|
||||||
@Override
|
{
|
||||||
public X509Certificate[] getAcceptedIssuers()
|
return new X509Certificate[]{};
|
||||||
{
|
}
|
||||||
return new X509Certificate[]{};
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -9,14 +9,11 @@ import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.rmi.RemoteException;
|
import java.util.Objects;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import javax.servlet.http.HttpSession;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -51,14 +48,14 @@ public class HttpImpl {
|
||||||
private static final String OS=System.getProperty("os.name").toLowerCase();
|
private static final String OS=System.getProperty("os.name").toLowerCase();
|
||||||
/**
|
/**
|
||||||
* 运行自动化任务
|
* 运行自动化任务
|
||||||
* @param req
|
* @param req HTTP请求
|
||||||
* @return
|
* @return 返回运行任务结果
|
||||||
* @throws RemoteException
|
|
||||||
*/
|
*/
|
||||||
@PostMapping("/runTask")
|
@PostMapping("/runTask")
|
||||||
private String runTask(HttpServletRequest req) throws RemoteException {
|
private String runTask(HttpServletRequest req) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
try (BufferedReader reader = req.getReader();) {
|
try {
|
||||||
|
BufferedReader reader = req.getReader();
|
||||||
char[] buff = new char[1024];
|
char[] buff = new char[1024];
|
||||||
int len;
|
int len;
|
||||||
while ((len = reader.read(buff)) != -1) {
|
while ((len = reader.read(buff)) != -1) {
|
||||||
|
@ -81,7 +78,7 @@ public class HttpImpl {
|
||||||
}
|
}
|
||||||
log.info("初始化Runtime...");
|
log.info("初始化Runtime...");
|
||||||
Runtime run = Runtime.getRuntime();
|
Runtime run = Runtime.getRuntime();
|
||||||
StringBuffer sbf=new StringBuffer();
|
StringBuilder sbf=new StringBuilder();
|
||||||
sbf.append(runTaskEntity.getTaskId()).append(" ");
|
sbf.append(runTaskEntity.getTaskId()).append(" ");
|
||||||
sbf.append(runTaskEntity.getLoadPath());
|
sbf.append(runTaskEntity.getLoadPath());
|
||||||
log.info("启动任务模式测试程序...调度名称:【{}】 任务ID:【{}】",runTaskEntity.getSchedulingName(),runTaskEntity.getTaskId());
|
log.info("启动任务模式测试程序...调度名称:【{}】 任务ID:【{}】",runTaskEntity.getSchedulingName(),runTaskEntity.getTaskId());
|
||||||
|
@ -104,14 +101,14 @@ public class HttpImpl {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量运行用例
|
* 批量运行用例
|
||||||
* @param req
|
* @param req HTTP请求
|
||||||
* @return
|
* @return 返回批量运行用例结果
|
||||||
* @throws RemoteException
|
|
||||||
*/
|
*/
|
||||||
@PostMapping("/runBatchCase")
|
@PostMapping("/runBatchCase")
|
||||||
private String runBatchCase(HttpServletRequest req) throws RemoteException {
|
private String runBatchCase(HttpServletRequest req) {
|
||||||
StringBuilder sbd = new StringBuilder();
|
StringBuilder sbd = new StringBuilder();
|
||||||
try (BufferedReader reader = req.getReader();) {
|
try {
|
||||||
|
BufferedReader reader = req.getReader();
|
||||||
char[] buff = new char[1024];
|
char[] buff = new char[1024];
|
||||||
int len;
|
int len;
|
||||||
while ((len = reader.read(buff)) != -1) {
|
while ((len = reader.read(buff)) != -1) {
|
||||||
|
@ -139,7 +136,7 @@ public class HttpImpl {
|
||||||
}
|
}
|
||||||
log.info("初始化Runtime...");
|
log.info("初始化Runtime...");
|
||||||
Runtime run = Runtime.getRuntime();
|
Runtime run = Runtime.getRuntime();
|
||||||
StringBuffer sb=new StringBuffer();
|
StringBuilder sb=new StringBuilder();
|
||||||
sb.append(taskId).append(" ");
|
sb.append(taskId).append(" ");
|
||||||
sb.append(batchCase).append(" ");
|
sb.append(batchCase).append(" ");
|
||||||
sb.append(loadPath);
|
sb.append(loadPath);
|
||||||
|
@ -164,14 +161,14 @@ public class HttpImpl {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* web界面调度接口
|
* web界面调度接口
|
||||||
* @param req
|
* @param req HTTP请求
|
||||||
* @return
|
* @return 返回调试用例运行结果
|
||||||
* @throws RemoteException
|
|
||||||
*/
|
*/
|
||||||
@PostMapping("/webDebugCase")
|
@PostMapping("/webDebugCase")
|
||||||
private String webDebugCase(HttpServletRequest req) throws RemoteException {
|
private String webDebugCase(HttpServletRequest req) {
|
||||||
StringBuilder sbd = new StringBuilder();
|
StringBuilder sbd = new StringBuilder();
|
||||||
try (BufferedReader reader = req.getReader();) {
|
try {
|
||||||
|
BufferedReader reader = req.getReader();
|
||||||
char[] buff = new char[1024];
|
char[] buff = new char[1024];
|
||||||
int len;
|
int len;
|
||||||
while ((len = reader.read(buff)) != -1) {
|
while ((len = reader.read(buff)) != -1) {
|
||||||
|
@ -190,7 +187,7 @@ public class HttpImpl {
|
||||||
return "客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"】";
|
return "客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"】";
|
||||||
}
|
}
|
||||||
Runtime run = Runtime.getRuntime();
|
Runtime run = Runtime.getRuntime();
|
||||||
StringBuffer sb=new StringBuffer();
|
StringBuilder sb=new StringBuilder();
|
||||||
sb.append(webDebugCaseEntity.getCaseId()).append(" ");
|
sb.append(webDebugCaseEntity.getCaseId()).append(" ");
|
||||||
sb.append(webDebugCaseEntity.getUserId()).append(" ");
|
sb.append(webDebugCaseEntity.getUserId()).append(" ");
|
||||||
sb.append(webDebugCaseEntity.getLoadpath());
|
sb.append(webDebugCaseEntity.getLoadpath());
|
||||||
|
@ -210,23 +207,19 @@ public class HttpImpl {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取客户端本地日志
|
* 获取客户端本地日志
|
||||||
* @param req
|
* @param req HTTP请求
|
||||||
* @return
|
* @return 返回日志全部信息
|
||||||
* @throws RemoteException
|
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getLogdDetail")
|
@GetMapping("/getLogdDetail")
|
||||||
private String getLogdDetail(HttpServletRequest req) throws RemoteException{
|
private String getLogdDetail(HttpServletRequest req) {
|
||||||
String fileName=req.getParameter("filename");
|
String fileName=req.getParameter("filename");
|
||||||
String ctxPath = System.getProperty("user.dir")+File.separator+"log";
|
String ctxPath = System.getProperty("user.dir")+File.separator+"log";
|
||||||
String downLoadPath = ctxPath +File.separator+ fileName;
|
String downLoadPath = ctxPath +File.separator+ fileName;
|
||||||
|
|
||||||
String str = "";
|
String str;
|
||||||
InputStreamReader isr=null;
|
InputStreamReader isr;
|
||||||
try {
|
try {
|
||||||
isr = new InputStreamReader(new FileInputStream(downLoadPath), "UTF-8");
|
isr = new InputStreamReader(new FileInputStream(downLoadPath), StandardCharsets.UTF_8);
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -234,7 +227,7 @@ public class HttpImpl {
|
||||||
return "读取日志路径错误,请检查客户端日志路径是否存在!downLoadPath: "+downLoadPath;
|
return "读取日志路径错误,请检查客户端日志路径是否存在!downLoadPath: "+downLoadPath;
|
||||||
}
|
}
|
||||||
BufferedReader bos = new BufferedReader(isr);
|
BufferedReader bos = new BufferedReader(isr);
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuilder sb = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
while ((str = bos.readLine()) != null)
|
while ((str = bos.readLine()) != null)
|
||||||
{
|
{
|
||||||
|
@ -253,12 +246,11 @@ public class HttpImpl {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取错误截图
|
* 获取错误截图
|
||||||
* @param req
|
* @param req HTTP请求
|
||||||
* @return
|
* @return 返回图片字节
|
||||||
* @throws RemoteException
|
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getLogImg")
|
@GetMapping("/getLogImg")
|
||||||
private byte[] getLogImg(HttpServletRequest req,HttpServletResponse res) throws RemoteException{
|
private byte[] getLogImg(HttpServletRequest req) {
|
||||||
String imgName=req.getParameter("imgName");
|
String imgName=req.getParameter("imgName");
|
||||||
String ctxPath = System.getProperty("user.dir")+File.separator+"log"+File.separator+"ScreenShot";
|
String ctxPath = System.getProperty("user.dir")+File.separator+"log"+File.separator+"ScreenShot";
|
||||||
String downLoadPath = ctxPath+File.separator+imgName;
|
String downLoadPath = ctxPath+File.separator+imgName;
|
||||||
|
@ -267,7 +259,7 @@ public class HttpImpl {
|
||||||
File file = new File(downLoadPath);
|
File file = new File(downLoadPath);
|
||||||
b = new byte[(int) file.length()];
|
b = new byte[(int) file.length()];
|
||||||
BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
|
BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
|
||||||
is.read(b);
|
//is.read(b);
|
||||||
is.close();
|
is.close();
|
||||||
log.info("服务端获取本地图片:{}",downLoadPath);
|
log.info("服务端获取本地图片:{}",downLoadPath);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
|
@ -285,9 +277,9 @@ public class HttpImpl {
|
||||||
* 上传驱动文件到客户端
|
* 上传驱动文件到客户端
|
||||||
*/
|
*/
|
||||||
@PostMapping("/uploadJar")
|
@PostMapping("/uploadJar")
|
||||||
private String uploadJar(HttpServletRequest req,HttpServletResponse res, HttpSession session,@RequestParam("jarfile") MultipartFile jarfile) throws IOException, ServletException{
|
private String uploadJar(HttpServletRequest req, @RequestParam("jarfile") MultipartFile jarfile) {
|
||||||
if (!jarfile.isEmpty()){
|
if (!jarfile.isEmpty()){
|
||||||
if (!jarfile.getOriginalFilename().endsWith(".jar")&&!jarfile.getOriginalFilename().endsWith(".py")) {
|
if (!Objects.requireNonNull(jarfile.getOriginalFilename()).endsWith(".jar")&&!jarfile.getOriginalFilename().endsWith(".py")) {
|
||||||
log.warn("文件格式后缀不是.jar或.py,上传失败");
|
log.warn("文件格式后缀不是.jar或.py,上传失败");
|
||||||
return "文件格式后缀不是.jar或.py,上传失败";
|
return "文件格式后缀不是.jar或.py,上传失败";
|
||||||
}
|
}
|
||||||
|
@ -311,14 +303,19 @@ public class HttpImpl {
|
||||||
if (file.exists()){
|
if (file.exists()){
|
||||||
file.deleteOnExit();
|
file.deleteOnExit();
|
||||||
}
|
}
|
||||||
file.createNewFile();
|
boolean newFile = file.createNewFile();
|
||||||
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(file));
|
if(newFile){
|
||||||
byte[] jarfileByte = jarfile.getBytes();
|
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(file));
|
||||||
os.write(jarfileByte);
|
byte[] jarfileByte = jarfile.getBytes();
|
||||||
os.flush();
|
os.write(jarfileByte);
|
||||||
os.close();
|
os.flush();
|
||||||
log.info("上传驱动包【{}】到客户端驱动目录【{}】成功!",name,file.getAbsolutePath());
|
os.close();
|
||||||
return "上传驱动包【"+name+"】到客户端驱动目录【"+file.getAbsolutePath()+"】成功!";
|
log.info("上传驱动包【{}】到客户端驱动目录【{}】成功!",name,file.getAbsolutePath());
|
||||||
|
return "上传驱动包【"+name+"】到客户端驱动目录【"+file.getAbsolutePath()+"】成功!";
|
||||||
|
}else{
|
||||||
|
log.error("上传驱动包【{}】到客户端驱动目录【{}】失败!",name,file.getAbsolutePath());
|
||||||
|
return "上传驱动包【"+name+"】到客户端驱动目录【"+file.getAbsolutePath()+"】失败!";
|
||||||
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
log.error("客户端未找到正确路径或文件,上传失败!文件路径名称:{}",pathName,e);
|
log.error("客户端未找到正确路径或文件,上传失败!文件路径名称:{}",pathName,e);
|
||||||
|
@ -332,12 +329,10 @@ public class HttpImpl {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查客户端心跳
|
* 检查客户端心跳
|
||||||
* @param req
|
* @return 返回心跳结果
|
||||||
* @return
|
|
||||||
* @throws RemoteException
|
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getClientStatus")
|
@GetMapping("/getClientStatus")
|
||||||
private String getClientStatus(HttpServletRequest req) throws RemoteException{
|
private String getClientStatus() {
|
||||||
Properties properties = SysConfig.getConfiguration();
|
Properties properties = SysConfig.getConfiguration();
|
||||||
String verison=properties.getProperty("client.verison");
|
String verison=properties.getProperty("client.verison");
|
||||||
return "{\"status\":\"success\",\"version\":\""+verison+"\"}";
|
return "{\"status\":\"success\",\"version\":\""+verison+"\"}";
|
||||||
|
@ -345,14 +340,12 @@ public class HttpImpl {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取客户端资源监控情况
|
* 获取客户端资源监控情况
|
||||||
* @param req
|
* @return 返回客户端资源情况
|
||||||
* @return
|
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @throws Exception
|
|
||||||
* @date 2019年5月5日
|
* @date 2019年5月5日
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getClientMonitorData")
|
@GetMapping("/getClientMonitorData")
|
||||||
private String getClientMonitorData(HttpServletRequest req) throws Exception{
|
private String getClientMonitorData() {
|
||||||
Server server = new Server();
|
Server server = new Server();
|
||||||
server.copyTo();
|
server.copyTo();
|
||||||
return JSON.toJSONString(server);
|
return JSON.toJSONString(server);
|
||||||
|
@ -360,11 +353,10 @@ public class HttpImpl {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查客户端中的配置
|
* 检查客户端中的配置
|
||||||
* @return
|
|
||||||
* @author Seagull
|
* @author Seagull
|
||||||
* @date 2019年5月6日
|
* @date 2019年5月6日
|
||||||
*/
|
*/
|
||||||
public static boolean checkHostNet() {
|
public static void checkHostNet() {
|
||||||
log.info("检查客户端配置中,请稍后......");
|
log.info("检查客户端配置中,请稍后......");
|
||||||
Properties properties = SysConfig.getConfiguration();
|
Properties properties = SysConfig.getConfiguration();
|
||||||
String version="Version "+properties.getProperty("client.verison");
|
String version="Version "+properties.getProperty("client.verison");
|
||||||
|
@ -384,9 +376,7 @@ public class HttpImpl {
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("客户端配置检测异常,请确认您项目根目录下的客户端配置文件(sys_config.properties)是否已经正确配置。",e);
|
log.error("客户端配置检测异常,请确认您项目根目录下的客户端配置文件(sys_config.properties)是否已经正确配置。",e);
|
||||||
return false;
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue