对接口、WEB UI以及移动端的自动化增加步骤失败判断跳转关键字

This commit is contained in:
seagull 2021-03-22 20:24:31 +08:00
parent ff0e4223bb
commit 6d0b9950ab
8 changed files with 305 additions and 50 deletions

View File

@ -46,9 +46,24 @@ public class AndroidCaseExecution{
variable.putAll(ParamsManageForSteps.GLOBAL_VARIABLE);
// 0通过 1失败 2锁定 3执行中 4未执行
int setcaseresult = 0;
for (ProjectCaseSteps step : steps) {
//步骤跳转标识
int stepJumpNo=0;
for (int i = 0; i < steps.size(); i++) {
Map<String, String> params;
String result;
ProjectCaseSteps step = steps.get(i);
//处理步骤跳转语法
if(stepJumpNo!=0){
if(stepJumpNo==i+1){
LogUtil.APP.info("跳转至当前用例第{}步",i+1);
}else if(stepJumpNo>i+1){
LogUtil.APP.info("当前用例第{}步,跳过执行...",i+1);
continue;
}else{
LogUtil.APP.info("跳转步骤【{}】小于当前步骤【{}】,直接向下继续执行...",stepJumpNo,i+1);
}
}
// 根据步骤类型来分析步骤参数
if (3 == step.getStepType()){
@ -74,7 +89,9 @@ public class AndroidCaseExecution{
expectedResults=ChangString.changparams(expectedResults, variable,"预期结果");
// 判断结果
int stepresult = judgeResult(testcase, step, params, appium, taskid, expectedResults, result, caselog);
Map<String,Integer> judgeResult = judgeResult(testcase, step, params, appium, taskid, expectedResults, result, caselog);
Integer stepresult = judgeResult.get("setResult");
stepJumpNo = judgeResult.get("stepJumpNo");
// 失败并且不在继续,直接终止
if (0 != stepresult) {
setcaseresult = stepresult;
@ -223,8 +240,10 @@ public class AndroidCaseExecution{
}
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;
public static Map<String,Integer> judgeResult(ProjectCase testcase, ProjectCaseSteps step, Map<String, String> params, AndroidDriver<AndroidElement> appium, String taskid, String expect, String result, serverOperation caselog) {
Map<String,Integer> judgeResult=new HashMap<>();
judgeResult.put("setResult",0);
judgeResult.put("stepJumpNo",0);
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
String imagname = timeformat.format(new Date());
@ -232,6 +251,23 @@ public class AndroidCaseExecution{
if (null != result && !result.contains("步骤执行失败:")) {
// 有预期结果
if (null != expect && !expect.isEmpty()) {
//处理步骤跳转
if (expect.length() > Constants.IFFAIL_JUMP.length() && expect.startsWith(Constants.IFFAIL_JUMP)) {
LogUtil.APP.info("预期结果中存在判断条件跳转步骤,处理前原始字符串:{}",expect);
String expectedTemp = expect.substring(Constants.IFFAIL_JUMP.length());
if(expectedTemp.contains(Constants.SYMLINK)){
expect = expectedTemp.substring(expectedTemp.indexOf(Constants.SYMLINK)+1);
try{
Integer stepJumpNo = Integer.getInteger(expectedTemp.substring(0,expectedTemp.indexOf(Constants.SYMLINK)));
judgeResult.put("stepJumpNo",stepJumpNo);
}catch (NumberFormatException nfe){
LogUtil.APP.error("步骤跳转语法解析失败,步骤编号不是数字,请确认:{}",expectedTemp.substring(0,expectedTemp.indexOf(Constants.SYMLINK)));
}
}else{
LogUtil.APP.warn("处理预期结果条件判断失败,请确认预期结果语法结构:【"+Constants.IFFAIL_JUMP+">>预期结果】,原始预期结果值:{}",expect);
}
}
LogUtil.APP.info("期望结果为【{}】",expect);
// 赋值传参模式
@ -258,7 +294,7 @@ public class AndroidCaseExecution{
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中找到预期结果中对象。当前步骤执行成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。执行失败!";
setresult = 1;
judgeResult.put("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);
@ -273,7 +309,7 @@ public class AndroidCaseExecution{
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果成功!执行结果:" + result, "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!";
setresult = 1;
judgeResult.put("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);
@ -288,7 +324,7 @@ public class AndroidCaseExecution{
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!";
setresult = 1;
judgeResult.put("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);
@ -305,7 +341,7 @@ public class AndroidCaseExecution{
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!";
setresult = 1;
judgeResult.put("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);
@ -315,13 +351,13 @@ public class AndroidCaseExecution{
}
} else {
casenote = (null != result) ? result : "";
setresult = 2;
judgeResult.put("setResult",2);
AndroidBaseAppium.screenShot(appium, imagname);
LogUtil.APP.warn("用例:{} 第{}步,执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),casenote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "当前步骤在执行过程中解析|定位元素|操作对象失败!" + casenote, "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
return setresult;
return judgeResult;
}
}

View File

@ -48,9 +48,24 @@ public class IosCaseExecution{
// 0:成功 1:失败 2:锁定 其他锁定
int setcaseresult = 0;
for (ProjectCaseSteps step : steps) {
//步骤跳转标识
int stepJumpNo=0;
for (int i = 0; i < steps.size(); i++) {
Map<String, String> params;
String result;
ProjectCaseSteps step = steps.get(i);
//处理步骤跳转语法
if(stepJumpNo!=0){
if(stepJumpNo==i+1){
LogUtil.APP.info("跳转至当前用例第{}步",i+1);
}else if(stepJumpNo>i+1){
LogUtil.APP.info("当前用例第{}步,跳过执行...",i+1);
continue;
}else{
LogUtil.APP.info("跳转步骤【{}】小于当前步骤【{}】,直接向下继续执行...",stepJumpNo,i+1);
}
}
// 根据步骤类型来分析步骤参数
if (3 == step.getStepType()){
@ -76,7 +91,9 @@ public class IosCaseExecution{
expectedResults=ChangString.changparams(expectedResults, variable,"预期结果");
// 判断结果
int stepresult = judgeResult(testcase, step, params, appium, taskid, expectedResults, result, caselog);
Map<String,Integer> judgeResult = judgeResult(testcase, step, params, appium, taskid, expectedResults, result, caselog);
Integer stepresult = judgeResult.get("setResult");
stepJumpNo = judgeResult.get("stepJumpNo");
// 失败并且不在继续,直接终止
if (0 != stepresult) {
setcaseresult = stepresult;
@ -236,8 +253,10 @@ public class IosCaseExecution{
}
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 Map<String,Integer> judgeResult(ProjectCase testcase, ProjectCaseSteps step, Map<String, String> params, IOSDriver<IOSElement> appium, String taskid, String expect, String result, serverOperation caselog) {
Map<String,Integer> judgeResult=new HashMap<>();
judgeResult.put("setResult",0);
judgeResult.put("stepJumpNo",0);
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
String imagname = timeformat.format(new Date());
@ -245,6 +264,23 @@ public class IosCaseExecution{
if (null != result && !result.contains("步骤执行失败:")) {
// 有预期结果
if (null != expect && !expect.isEmpty()) {
//处理步骤跳转
if (expect.length() > Constants.IFFAIL_JUMP.length() && expect.startsWith(Constants.IFFAIL_JUMP)) {
LogUtil.APP.info("预期结果中存在判断条件跳转步骤,处理前原始字符串:{}",expect);
String expectedTemp = expect.substring(Constants.IFFAIL_JUMP.length());
if(expectedTemp.contains(Constants.SYMLINK)){
expect = expectedTemp.substring(expectedTemp.indexOf(Constants.SYMLINK)+1);
try{
Integer stepJumpNo = Integer.getInteger(expectedTemp.substring(0,expectedTemp.indexOf(Constants.SYMLINK)));
judgeResult.put("stepJumpNo",stepJumpNo);
}catch (NumberFormatException nfe){
LogUtil.APP.error("步骤跳转语法解析失败,步骤编号不是数字,请确认:{}",expectedTemp.substring(0,expectedTemp.indexOf(Constants.SYMLINK)));
}
}else{
LogUtil.APP.warn("处理预期结果条件判断失败,请确认预期结果语法结构:【"+Constants.IFFAIL_JUMP+">>预期结果】,原始预期结果值:{}",expect);
}
}
LogUtil.APP.info("期望结果为【{}】",expect);
// 赋值传参模式
@ -271,7 +307,7 @@ public class IosCaseExecution{
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中找到预期结果中对象。当前步骤执行成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。执行失败!";
setresult = 1;
judgeResult.put("setResult",1);
IosBaseAppium.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);
@ -286,7 +322,7 @@ public class IosCaseExecution{
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果成功!执行结果:" + result, "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!";
setresult = 1;
judgeResult.put("setResult",1);
IosBaseAppium.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);
@ -301,7 +337,7 @@ public class IosCaseExecution{
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!";
setresult = 1;
judgeResult.put("setResult",1);
IosBaseAppium.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);
@ -318,7 +354,7 @@ public class IosCaseExecution{
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!";
setresult = 1;
judgeResult.put("setResult",1);
IosBaseAppium.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);
@ -328,13 +364,13 @@ public class IosCaseExecution{
}
} else {
casenote = (null != result) ? result : "";
setresult = 2;
judgeResult.put("setResult",2);
IosBaseAppium.screenShot(appium, imagname);
LogUtil.APP.warn("用例:{} 第{}步,执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),casenote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "当前步骤在执行过程中解析|定位元素|操作对象失败!" + casenote, "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
return setresult;
return judgeResult;
}
}

View File

@ -14,6 +14,7 @@ import luckyclient.remote.api.serverOperation;
import luckyclient.remote.entity.ProjectCase;
import luckyclient.remote.entity.ProjectCaseParams;
import luckyclient.remote.entity.ProjectCaseSteps;
import luckyclient.utils.Constants;
import luckyclient.utils.InvokeMethod;
import luckyclient.utils.LogUtil;
import luckyclient.utils.httputils.HttpRequest;
@ -48,6 +49,7 @@ public class ApiTestCaseDebug {
String functionname;
String expectedresults;
int setcaseresult = 0;
int stepJumpNo=0;
Object[] getParameterValues;
String testnote = "初始化测试结果";
int k = 0;
@ -65,6 +67,18 @@ public class ApiTestCaseDebug {
}
// 进入循环解析用例所有步骤
for (int i = 0; i < steps.size(); i++) {
//处理步骤跳转语法
if(stepJumpNo!=0){
if(stepJumpNo==i+1){
LogUtil.APP.info("跳转至当前用例第{}步",i+1);
}else if(stepJumpNo>i+1){
LogUtil.APP.info("当前用例第{}步,跳过执行...",i+1);
continue;
}else{
LogUtil.APP.info("跳转步骤【{}】小于当前步骤【{}】,直接向下继续执行...",stepJumpNo,i+1);
}
}
Map<String, String> casescript = InterfaceAnalyticCase.analyticCaseStep(testcase, steps.get(i), "888888",
caselog,variable);
try {
@ -109,6 +123,22 @@ public class ApiTestCaseDebug {
}
testnote = ActionManageForSteps.actionManage(casescript.get("Action"), testnote);
if (null != expectedresults && !expectedresults.isEmpty()) {
//处理步骤跳转
if (expectedresults.length() > Constants.IFFAIL_JUMP.length() && expectedresults.startsWith(Constants.IFFAIL_JUMP)) {
LogUtil.APP.info("预期结果中存在判断条件跳转步骤,处理前原始字符串:{}",expectedresults);
String expectedTemp = expectedresults.substring(Constants.IFFAIL_JUMP.length());
if(expectedTemp.contains(Constants.SYMLINK)){
expectedresults = expectedTemp.substring(expectedTemp.indexOf(Constants.SYMLINK)+1);
try{
stepJumpNo = Integer.getInteger(expectedTemp.substring(0,expectedTemp.indexOf(Constants.SYMLINK)));
}catch (NumberFormatException nfe){
LogUtil.APP.error("步骤跳转语法解析失败,步骤编号不是数字,请确认:{}",expectedTemp.substring(0,expectedTemp.indexOf(Constants.SYMLINK)));
}
}else{
LogUtil.APP.warn("处理预期结果条件判断失败,请确认预期结果语法结构:【"+Constants.IFFAIL_JUMP+">>预期结果】,原始预期结果值:{}",expectedresults);
}
}
LogUtil.APP.info("expectedResults=【{}】",expectedresults);
// 赋值传参
if (expectedresults.length() > ASSIGNMENT_SIGN.length()

View File

@ -59,6 +59,7 @@ public class TestCaseExecution {
Object[] getParameterValues;
String testnote = "初始化测试结果";
int k = 0;
int stepJumpNo=0;
ProjectCase testcase = GetServerApi.cGetCaseByCaseId(caseId);
//更新用例状态
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), 3);
@ -81,6 +82,18 @@ public class TestCaseExecution {
}
// 进入循环解析用例所有步骤
for (int i = 0; i < steps.size(); i++) {
//处理步骤跳转语法
if(stepJumpNo!=0){
if(stepJumpNo==i+1){
LogUtil.APP.info("跳转至当前用例第{}步",i+1);
}else if(stepJumpNo>i+1){
LogUtil.APP.info("当前用例第{}步,跳过执行...",i+1);
continue;
}else{
LogUtil.APP.info("跳转步骤【{}】小于当前步骤【{}】,直接向下继续执行...",stepJumpNo,i+1);
}
}
Map<String, String> casescript = InterfaceAnalyticCase.analyticCaseStep(testcase, steps.get(i), taskid, caselog,RUNCASE_VARIABLE);
try {
packagename = casescript.get("PackageName");
@ -127,7 +140,9 @@ public class TestCaseExecution {
}
testnote = ActionManageForSteps.actionManage(casescript.get("Action"), testnote);
// 判断结果
int stepresult = interfaceJudgeResult(testcase, steps.get(i), taskid, expectedresults, testnote, caselog);
Map<String,Integer> judgeResult = interfaceJudgeResult(testcase, steps.get(i), taskid, expectedresults, testnote, caselog);
Integer stepresult = judgeResult.get("setResult");
stepJumpNo = judgeResult.get("stepJumpNo");
// 失败并且不在继续,直接终止
if (0 != stepresult) {
setcaseresult = stepresult;
@ -188,6 +203,7 @@ public class TestCaseExecution {
public String oneCaseExecuteForCase(String testCaseExternalId, String taskid, Map<String, String> outVariable, serverOperation caselog, Object driver) {
String expectedresults;
int setresult = 1;
int stepJumpNo=0;
String testnote = "初始化测试结果";
ProjectCase testcase = GetServerApi.cgetCaseBysign(testCaseExternalId);
List<ProjectCaseParams> pcplist = GetServerApi.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
@ -213,8 +229,20 @@ public class TestCaseExecution {
}
// 进入循环解析用例所有步骤
for (ProjectCaseSteps step : steps) {
for (int i = 0; i < steps.size(); i++) {
Map<String, String> params;
ProjectCaseSteps step = steps.get(i);
//处理步骤跳转语法
if(stepJumpNo!=0){
if(stepJumpNo==i+1){
LogUtil.APP.info("跳转至当前用例第{}步",i+1);
}else if(stepJumpNo>i+1){
LogUtil.APP.info("当前用例第{}步,跳过执行...",i+1);
continue;
}else{
LogUtil.APP.info("跳转步骤【{}】小于当前步骤【{}】,直接向下继续执行...",stepJumpNo,i+1);
}
}
// 根据步骤类型来分析步骤参数
if (1 == step.getStepType()){
@ -232,34 +260,42 @@ public class TestCaseExecution {
}
expectedresults = params.get("ExpectedResults");
Map<String,Integer> judgeResult=new HashMap<>();
// 根据步骤类型来执行步骤
if (1 == step.getStepType()){
WebDriver wd=(WebDriver)driver;
testnote = WebCaseExecution.runWebStep(params, wd, taskid, testcase.getCaseId(), step.getStepSerialNumber(), caselog);
testnote = ActionManageForSteps.actionManage(params.get("Action"), testnote);
// 判断结果
setresult = WebCaseExecution.judgeResult(testcase, step, params, wd, taskid, expectedresults, testnote, caselog);
judgeResult = WebCaseExecution.judgeResult(testcase, step, params, wd, taskid, expectedresults, testnote, caselog);
setresult = judgeResult.get("setResult");
stepJumpNo = judgeResult.get("stepJumpNo");
}else if (3 == step.getStepType()){
if (driver instanceof AndroidDriver){
AndroidDriver<AndroidElement> ad=(AndroidDriver<AndroidElement>)driver;
testnote = AndroidCaseExecution.androidRunStep(params, ad, taskid, testcase.getCaseId(), step.getStepSerialNumber(), caselog);
testnote = ActionManageForSteps.actionManage(params.get("Action"), testnote);
// 判断结果
setresult = AndroidCaseExecution.judgeResult(testcase, step, params, ad, taskid, expectedresults, testnote, caselog);
judgeResult = AndroidCaseExecution.judgeResult(testcase, step, params, ad, taskid, expectedresults, testnote, caselog);
setresult = judgeResult.get("setResult");
stepJumpNo = judgeResult.get("stepJumpNo");
}else{
IOSDriver<IOSElement> ios=(IOSDriver<IOSElement>)driver;
testnote = IosCaseExecution.iosRunStep(params, RUNCASE_VARIABLE, ios, taskid, testcase.getCaseId(), step.getStepSerialNumber(), caselog);
testnote = ActionManageForSteps.actionManage(params.get("Action"), testnote);
// 判断结果
setresult = IosCaseExecution.judgeResult(testcase, step, params, ios, taskid, expectedresults, testnote, caselog);
judgeResult = IosCaseExecution.judgeResult(testcase, step, params, ios, taskid, expectedresults, testnote, caselog);
setresult = judgeResult.get("setResult");
stepJumpNo = judgeResult.get("stepJumpNo");
}
} else{
testnote = runStep(params, taskid, testcase.getCaseSign(), step, caselog);
testnote = ActionManageForSteps.actionManage(params.get("Action"), testnote);
// ÅÐϽá¹û
setresult = interfaceJudgeResult(testcase, step, taskid, expectedresults, testnote, caselog);
// 判断结果
judgeResult = interfaceJudgeResult(testcase, step, taskid, expectedresults, testnote, caselog);
setresult = judgeResult.get("setResult");
stepJumpNo = judgeResult.get("stepJumpNo");
}
if (0 != setresult){
@ -342,10 +378,29 @@ public class TestCaseExecution {
return result;
}
private int interfaceJudgeResult(ProjectCase testcase, ProjectCaseSteps step, String taskid, String expectedresults, String testnote, serverOperation caselog){
int setresult = 0;
private Map<String,Integer> interfaceJudgeResult(ProjectCase testcase, ProjectCaseSteps step, String taskid, String expectedresults, String testnote, serverOperation caselog){
Map<String,Integer> judgeResult=new HashMap<>();
judgeResult.put("setResult",0);
judgeResult.put("stepJumpNo",0);
try{
if (null != expectedresults && !expectedresults.isEmpty()) {
//处理步骤跳转
if (expectedresults.length() > Constants.IFFAIL_JUMP.length() && expectedresults.startsWith(Constants.IFFAIL_JUMP)) {
LogUtil.APP.info("预期结果中存在判断条件跳转步骤,处理前原始字符串:{}",expectedresults);
String expectedTemp = expectedresults.substring(Constants.IFFAIL_JUMP.length());
if(expectedTemp.contains(Constants.SYMLINK)){
expectedresults = expectedTemp.substring(expectedTemp.indexOf(Constants.SYMLINK)+1);
try{
Integer stepJumpNo = Integer.getInteger(expectedTemp.substring(0,expectedTemp.indexOf(Constants.SYMLINK)));
judgeResult.put("stepJumpNo",stepJumpNo);
}catch (NumberFormatException nfe){
LogUtil.APP.error("步骤跳转语法解析失败,步骤编号不是数字,请确认:{}",expectedTemp.substring(0,expectedTemp.indexOf(Constants.SYMLINK)));
}
}else{
LogUtil.APP.warn("处理预期结果条件判断失败,请确认预期结果语法结构:【"+Constants.IFFAIL_JUMP+">>预期结果】,原始预期结果值:{}",expectedresults);
}
}
LogUtil.APP.info("expectedResults=【{}】",expectedresults);
// 赋值传参
if (expectedresults.length() > Constants.ASSIGNMENT_SIGN.length() && expectedresults.startsWith(Constants.ASSIGNMENT_SIGN)) {
@ -366,7 +421,7 @@ public class TestCaseExecution {
LogUtil.APP.info("用例:{} 第{}步,模糊匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),testnote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
setresult = 1;
judgeResult.put("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()), "");
}
@ -379,7 +434,7 @@ public class TestCaseExecution {
LogUtil.APP.info("用例:{} 第{}步,正则匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),testnote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
setresult = 1;
judgeResult.put("setResult",1);
LogUtil.APP.warn("用例:{} 第{}步,正则匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expectedresults.substring(Constants.REGULAR_MATCHING_SIGN.length()),testnote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果失败!预期结果:" + expectedresults.substring(Constants.REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + testnote, "error", String.valueOf(step.getStepSerialNumber()), "");
}
@ -393,10 +448,10 @@ public class TestCaseExecution {
String result = SubString.jsonPathGetParams(expression, testnote);
if (exceptResult.equals(result)) {
setresult = 0;
judgeResult.put("setResult",0);
LogUtil.APP.info("用例:{} 第{}步jsonpath断言预期结果成功预期结果:{} 测试结果: {} 执行结果:true",testcase.getCaseSign(),step.getStepSerialNumber(),exceptResult,result);
} else {
setresult = 1;
judgeResult.put("setResult",1);
LogUtil.APP.warn("用例:{} 第{}步jsonpath断言预期结果失败预期结果:{},测试结果:{}" + expectedresults + ",测试结果:" + result, "error", step.getStepSerialNumber(), "");
// 某一步骤失败后此条用例置为失败退出
}
@ -412,7 +467,7 @@ public class TestCaseExecution {
LogUtil.APP.info("用例:{} 第{}步,精确匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),testnote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果成功!执行结果:" + testnote, "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
setresult = 1;
judgeResult.put("setResult",1);
LogUtil.APP.warn("用例:{} 第{}步,精确匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expectedresults,testnote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果失败!预期结果:" + expectedresults + ",测试结果:" + testnote, "error", String.valueOf(step.getStepSerialNumber()), "");
}
@ -420,10 +475,10 @@ public class TestCaseExecution {
}
}catch(Exception e){
LogUtil.APP.error("匹配接口预期结果出现异常!",e);
setresult = 2;
return setresult;
judgeResult.put("setResult",2);
return judgeResult;
}
return setresult;
return judgeResult;
}

View File

@ -68,10 +68,23 @@ public class ThreadForExecuteCase extends Thread {
Object[] getParameterValues;
String testnote = "初始化测试结果";
int k = 0;
int stepJumpNo=0;
// 进入循环解析单个用例所有步骤
// 插入开始执行的用例
caselog.insertTaskCaseExecute(taskid, projectId, caseId, caseSign, testcase.getCaseName(), 3);
for (int i = 0; i < steps.size(); i++) {
//处理步骤跳转语法
if(stepJumpNo!=0){
if(stepJumpNo==i+1){
LogUtil.APP.info("跳转至当前用例第{}步",i+1);
}else if(stepJumpNo>i+1){
LogUtil.APP.info("当前用例第{}步,跳过执行...",i+1);
continue;
}else{
LogUtil.APP.info("跳转步骤【{}】小于当前步骤【{}】,直接向下继续执行...",stepJumpNo,i+1);
}
}
// 解析单个步骤中的脚本
Map<String, String> casescript = InterfaceAnalyticCase.analyticCaseStep(testcase, steps.get(i), taskid, caselog,variable);
try {
@ -120,6 +133,21 @@ public class ThreadForExecuteCase extends Thread {
testnote = ActionManageForSteps.actionManage(casescript.get("Action"), testnote);
if (null != expectedresults && !expectedresults.isEmpty()) {
//处理步骤跳转
if (expectedresults.length() > Constants.IFFAIL_JUMP.length() && expectedresults.startsWith(Constants.IFFAIL_JUMP)) {
LogUtil.APP.info("预期结果中存在判断条件跳转步骤,处理前原始字符串:{}",expectedresults);
String expectedTemp = expectedresults.substring(Constants.IFFAIL_JUMP.length());
if(expectedTemp.contains(Constants.SYMLINK)){
expectedresults = expectedTemp.substring(expectedTemp.indexOf(Constants.SYMLINK)+1);
try{
stepJumpNo = Integer.getInteger(expectedTemp.substring(0,expectedTemp.indexOf(Constants.SYMLINK)));
}catch (NumberFormatException nfe){
LogUtil.APP.error("步骤跳转语法解析失败,步骤编号不是数字,请确认:{}",expectedTemp.substring(0,expectedTemp.indexOf(Constants.SYMLINK)));
}
}else{
LogUtil.APP.warn("处理预期结果条件判断失败,请确认预期结果语法结构:【"+Constants.IFFAIL_JUMP+">>预期结果】,原始预期结果值:{}",expectedresults);
}
}
LogUtil.APP.info("expectedResults=【{}】",expectedresults);
// 赋值传参
if (expectedresults.length() > Constants.ASSIGNMENT_SIGN.length() && expectedresults.startsWith(Constants.ASSIGNMENT_SIGN)) {
@ -267,5 +295,4 @@ public class ThreadForExecuteCase extends Thread {
TestControl.THREAD_COUNT--; // 多线程计数--用于检测线程是否全部执行完
}
}
}

View File

@ -46,6 +46,7 @@ public class WebTestCaseDebug {
String functionname;
String expectedresults;
int setcaseresult = 0;
int stepJumpNo=0;
Object[] getParameterValues;
String testnote = "初始化测试结果";
int k = 0;
@ -64,6 +65,18 @@ public class WebTestCaseDebug {
List<ProjectCaseSteps> steps = GetServerApi.getStepsbycaseid(testcase.getCaseId());
//进入循环解析用例所有步骤
for (int i = 0; i < steps.size(); i++) {
//处理步骤跳转语法
if(stepJumpNo!=0){
if(stepJumpNo==i+1){
LogUtil.APP.info("跳转至当前用例第{}步",i+1);
}else if(stepJumpNo>i+1){
LogUtil.APP.info("当前用例第{}步,跳过执行...",i+1);
continue;
}else{
LogUtil.APP.info("跳转步骤【{}】小于当前步骤【{}】,直接向下继续执行...",stepJumpNo,i+1);
}
}
Map<String, String> casescript = InterfaceAnalyticCase.analyticCaseStep(testcase, steps.get(i), "888888", null,variable);
try {
packagename = casescript.get("PackageName");
@ -110,6 +123,21 @@ public class WebTestCaseDebug {
testnote = ActionManageForSteps.actionManage(casescript.get("Action"), testnote);
if (null != expectedresults && !expectedresults.isEmpty()) {
//处理步骤跳转
if (expectedresults.length() > Constants.IFFAIL_JUMP.length() && expectedresults.startsWith(Constants.IFFAIL_JUMP)) {
LogUtil.APP.info("预期结果中存在判断条件跳转步骤,处理前原始字符串:{}",expectedresults);
String expectedTemp = expectedresults.substring(Constants.IFFAIL_JUMP.length());
if(expectedTemp.contains(Constants.SYMLINK)){
expectedresults = expectedTemp.substring(expectedTemp.indexOf(Constants.SYMLINK)+1);
try{
stepJumpNo = Integer.getInteger(expectedTemp.substring(0,expectedTemp.indexOf(Constants.SYMLINK)));
}catch (NumberFormatException nfe){
LogUtil.APP.error("步骤跳转语法解析失败,步骤编号不是数字,请确认:{}",expectedTemp.substring(0,expectedTemp.indexOf(Constants.SYMLINK)));
}
}else{
LogUtil.APP.warn("处理预期结果条件判断失败,请确认预期结果语法结构:【"+Constants.IFFAIL_JUMP+">>预期结果】,原始预期结果值:{}",expectedresults);
}
}
// 赋值传参
if (expectedresults.length() > Constants.ASSIGNMENT_SIGN.length() && expectedresults.startsWith(Constants.ASSIGNMENT_SIGN)) {
variable.put(expectedresults.substring(Constants.ASSIGNMENT_SIGN.length()), testnote);

View File

@ -49,9 +49,24 @@ public class WebCaseExecution{
variable.putAll(ParamsManageForSteps.GLOBAL_VARIABLE);
// 0:成功 1:失败 2:锁定 其他锁定
int setcaseresult = 0;
for (ProjectCaseSteps step : steps) {
//步骤跳转标识
int stepJumpNo=0;
for (int i = 0; i < steps.size(); i++) {
Map<String, String> params;
String result;
ProjectCaseSteps step = steps.get(i);
//处理步骤跳转语法
if(stepJumpNo!=0){
if(stepJumpNo==i+1){
LogUtil.APP.info("跳转至当前用例第{}步",i+1);
}else if(stepJumpNo>i+1){
LogUtil.APP.info("当前用例第{}步,跳过执行...",i+1);
continue;
}else{
LogUtil.APP.info("跳转步骤【{}】小于当前步骤【{}】,直接向下继续执行...",stepJumpNo,i+1);
}
}
// 根据步骤类型来分析步骤参数
if (1 == step.getStepType()){
@ -77,7 +92,9 @@ public class WebCaseExecution{
String expectedResults = params.get("ExpectedResults");
// 判断结果
int stepresult = judgeResult(testcase, step, params, wd, taskid, expectedResults, result, caselog);
Map<String,Integer> judgeResult = judgeResult(testcase, step, params, wd, taskid, expectedResults, result, caselog);
Integer stepresult = judgeResult.get("setResult");
stepJumpNo = judgeResult.get("stepJumpNo");
// 失败并且不在继续,直接终止
if (0 != stepresult) {
setcaseresult = stepresult;
@ -240,8 +257,10 @@ public class WebCaseExecution{
}
public static int judgeResult(ProjectCase testcase, ProjectCaseSteps step, Map<String, String> params, WebDriver driver, String taskid, String expect, String result, serverOperation caselog) {
int setresult = 0;
public static Map<String,Integer> judgeResult(ProjectCase testcase, ProjectCaseSteps step, Map<String, String> params, WebDriver driver, String taskid, String expect, String result, serverOperation caselog) {
Map<String,Integer> judgeResult=new HashMap<>();
judgeResult.put("setResult",0);
judgeResult.put("stepJumpNo",0);
java.text.DateFormat timeformat = new java.text.SimpleDateFormat("MMdd-hhmmss");
String imagname = timeformat.format(new Date());
@ -249,6 +268,23 @@ public class WebCaseExecution{
if (null != result && !result.contains("步骤执行失败:")) {
// 有预期结果
if (null != expect && !expect.isEmpty()) {
//处理步骤跳转
if (expect.length() > Constants.IFFAIL_JUMP.length() && expect.startsWith(Constants.IFFAIL_JUMP)) {
LogUtil.APP.info("预期结果中存在判断条件跳转步骤,处理前原始字符串:{}",expect);
String expectedTemp = expect.substring(Constants.IFFAIL_JUMP.length());
if(expectedTemp.contains(Constants.SYMLINK)){
expect = expectedTemp.substring(expectedTemp.indexOf(Constants.SYMLINK)+1);
try{
Integer stepJumpNo = Integer.getInteger(expectedTemp.substring(0,expectedTemp.indexOf(Constants.SYMLINK)));
judgeResult.put("stepJumpNo",stepJumpNo);
}catch (NumberFormatException nfe){
LogUtil.APP.error("步骤跳转语法解析失败,步骤编号不是数字,请确认:{}",expectedTemp.substring(0,expectedTemp.indexOf(Constants.SYMLINK)));
}
}else{
LogUtil.APP.warn("处理预期结果条件判断失败,请确认预期结果语法结构:【"+Constants.IFFAIL_JUMP+">>预期结果】,原始预期结果值:{}",expect);
}
}
LogUtil.APP.info("期望结果为【{}】",expect);
// 赋值传参模式
if (expect.length() > Constants.ASSIGNMENT_SIGN.length() && expect.startsWith(Constants.ASSIGNMENT_SIGN)) {
@ -274,7 +310,7 @@ public class WebCaseExecution{
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中找到预期结果中对象。当前步骤执行成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。执行失败!";
setresult = 1;
judgeResult.put("setResult",1);
BaseWebDrive.webScreenShot(driver, imagname);
LogUtil.APP.warn("用例:{} 第{}步,没有在当前页面中找到预期结果中对象。当前步骤执行失败!",testcase.getCaseSign(),step.getStepSerialNumber());
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中没有找到预期结果中对象。当前步骤执行失败!" + "checkproperty【" + checkproperty + "】 checkproperty_value【" + checkPropertyValue + "", "error", String.valueOf(step.getStepSerialNumber()), imagname);
@ -289,7 +325,7 @@ public class WebCaseExecution{
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果成功!执行结果:" + result, "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!";
setresult = 1;
judgeResult.put("setResult",1);
BaseWebDrive.webScreenShot(driver, 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);
@ -304,7 +340,7 @@ public class WebCaseExecution{
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!";
setresult = 1;
judgeResult.put("setResult",1);
BaseWebDrive.webScreenShot(driver, 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);
@ -321,7 +357,7 @@ public class WebCaseExecution{
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!";
setresult = 1;
judgeResult.put("setResult",1);
BaseWebDrive.webScreenShot(driver, imagname);
LogUtil.APP.warn("用例:{} 第{}步,精确匹配预期结果失败!预期结果是:【{}】 执行结果:【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),expect,result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果失败!预期结果是:【"+expect+"】 执行结果:【"+ result+"", "error", String.valueOf(step.getStepSerialNumber()), imagname);
@ -331,13 +367,13 @@ public class WebCaseExecution{
}
} else {
casenote = (null != result) ? result : "";
setresult = 2;
judgeResult.put("setResult",2);
BaseWebDrive.webScreenShot(driver, imagname);
LogUtil.APP.warn("用例:{} 第{}步,执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),casenote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "当前步骤在执行过程中解析|定位元素|操作对象失败!" + casenote, "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
return setresult;
return judgeResult;
}
}

View File

@ -30,7 +30,14 @@ public class Constants {
* 预期结果匹配符---json匹配
*/
public static final String JSONPATH_SIGN = "$JP#";
/**
* 语法链接符
*/
public static final String SYMLINK = ">>";
/**
* 匹配预期结果失败跳转处理
*/
public static final String IFFAIL_JUMP = "fail"+SYMLINK;
/************************HTTP 返回结果头域 响应码分隔符定义***************************
* HTTP测试返回结果 是否接收头域