增加jaonpath断言功能,断言是通过对except的list与jsonpath拿到的目标list做对比,list内的对象全部转换为String类型,转换后,为严格判断两个list是否相等
This commit is contained in:
parent
5c11719d20
commit
94314188d2
26
.classpath
26
.classpath
|
@ -1,26 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
23
.project
23
.project
|
@ -1,23 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>LuckyFrame</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
7
pom.xml
7
pom.xml
|
@ -298,5 +298,12 @@
|
|||
<artifactId>reflections</artifactId>
|
||||
<version>0.9.11</version>
|
||||
</dependency>
|
||||
|
||||
<!-- jsonpath依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.jayway.jsonpath</groupId>
|
||||
<artifactId>json-path</artifactId>
|
||||
<version>2.4.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
package luckyclient.caserun.exinterface;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jayway.jsonpath.Configuration;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
|
||||
import io.appium.java_client.android.AndroidDriver;
|
||||
|
@ -44,6 +50,7 @@ public class TestCaseExecution {
|
|||
protected static final String FUZZY_MATCHING_SIGN = "%=";
|
||||
protected static final String REGULAR_MATCHING_SIGN = "~=";
|
||||
protected static final String ASSIGNMENT_GLOBALSIGN = "$A=";
|
||||
protected static final String JSONPATH_SIGN = "$J=";
|
||||
private static Map<String, String> VARIABLE = new HashMap<String, String>(0);
|
||||
|
||||
/**
|
||||
|
@ -281,6 +288,26 @@ public class TestCaseExecution {
|
|||
break; // 某一步骤失败后,此条用例置为失败退出
|
||||
}
|
||||
}
|
||||
//jsonpath断言
|
||||
else if (expectedresults.length() > JSONPATH_SIGN.length() && expectedresults.startsWith(JSONPATH_SIGN)) {
|
||||
expectedresults = expectedresults.substring(JSONPATH_SIGN.length());
|
||||
String jsonpath = expectedresults.split("=")[0];
|
||||
String exceptResult = expectedresults.split("=")[1];
|
||||
List<String> exceptResults = Arrays.asList(exceptResult.split(","));
|
||||
Configuration conf = Configuration.defaultConfiguration();
|
||||
JSONArray datasArray = JSON.parseArray(JSON.toJSONString(JsonPath.using(conf).parse(testnote).read(jsonpath)));
|
||||
List<String> result = JSONObject.parseArray(datasArray.toJSONString(), String.class);
|
||||
if (exceptResults.equals(result)) {
|
||||
setresult = 0;
|
||||
LogUtil.APP.info("用例:{} 第{}步,jsonpath断言预期结果成功!预期结果:{} 测试结果: {} 执行结果:true",testcase.getCaseSign(),(i+1),exceptResults,result);
|
||||
} else {
|
||||
setresult = 1;
|
||||
LogUtil.APP.warn("用例:{} 第{}步,jsonpath断言预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),(i+1),expectedresults.substring(REGULAR_MATCHING_SIGN.length()),testnote);
|
||||
testnote = "用例第" + (i + 1) + "步,jsonpath断言预期结果失败!";
|
||||
// 某一步骤失败后,此条用例置为失败退出
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 完全相等
|
||||
else {
|
||||
if (expectedresults.equals(testnote)) {
|
||||
|
@ -505,6 +532,26 @@ public class TestCaseExecution {
|
|||
testnote = "用例第" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!";
|
||||
}
|
||||
}
|
||||
//jsonpath断言
|
||||
else if (expectedresults.length() > JSONPATH_SIGN.length() && expectedresults.startsWith(JSONPATH_SIGN)) {
|
||||
expectedresults = expectedresults.substring(JSONPATH_SIGN.length());
|
||||
String jsonpath = expectedresults.split("=")[0];
|
||||
String exceptResult = expectedresults.split("=")[1];
|
||||
List<String> exceptResults = Arrays.asList(exceptResult.split(","));
|
||||
Configuration conf = Configuration.defaultConfiguration();
|
||||
JSONArray datasArray = JSON.parseArray(JSON.toJSONString(JsonPath.using(conf).parse(testnote).read(jsonpath)));
|
||||
List<String> result = JSONObject.parseArray(datasArray.toJSONString(), String.class);
|
||||
if (exceptResults.equals(result)) {
|
||||
setresult = 0;
|
||||
LogUtil.APP.info("用例:{} 第{}步,jsonpath断言预期结果成功!预期结果:{} 测试结果: {} 执行结果:true",testcase.getCaseSign(),step.getStepSerialNumber(),exceptResults,result);
|
||||
} else {
|
||||
setresult = 1;
|
||||
LogUtil.APP.warn("用例:{} 第{}步,jsonpath断言预期结果失败!预期结果:{},测试结果:{}" + expectedresults + ",测试结果:" + result.toString(), "error", String.valueOf(step.getStepSerialNumber()), "");
|
||||
testnote = "用例第" + step.getStepSerialNumber() + "步,jsonpath断言预期结果失败!";
|
||||
// 某一步骤失败后,此条用例置为失败退出
|
||||
}
|
||||
|
||||
}
|
||||
// 完全相等
|
||||
else {
|
||||
if (expectedresults.equals(testnote)) {
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
package luckyclient.caserun.exinterface;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jayway.jsonpath.Configuration;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import luckyclient.caserun.exinterface.analyticsteps.InterfaceAnalyticCase;
|
||||
import luckyclient.caserun.publicdispose.ActionManageForSteps;
|
||||
import luckyclient.caserun.publicdispose.ParamsManageForSteps;
|
||||
|
@ -33,6 +39,7 @@ public class ThreadForExecuteCase extends Thread {
|
|||
private static final String ASSIGNMENT_GLOBALSIGN = "$A=";
|
||||
private static final String FUZZY_MATCHING_SIGN = "%=";
|
||||
private static final String REGULAR_MATCHING_SIGN = "~=";
|
||||
private static final String JSONPATH_SIGN = "$J=";
|
||||
|
||||
private Integer caseId;
|
||||
private String caseSign;
|
||||
|
@ -169,6 +176,35 @@ public class ThreadForExecuteCase extends Thread {
|
|||
}
|
||||
}
|
||||
}
|
||||
//jsonpath断言
|
||||
else if (expectedresults.length() > JSONPATH_SIGN.length() && expectedresults.startsWith(JSONPATH_SIGN)) {
|
||||
expectedresults = expectedresults.substring(JSONPATH_SIGN.length());
|
||||
String jsonpath = expectedresults.split("=")[0];
|
||||
String exceptResult = expectedresults.split("=")[1];
|
||||
List<String> exceptResults = Arrays.asList(exceptResult.split(","));
|
||||
Configuration conf = Configuration.defaultConfiguration();
|
||||
JSONArray datasArray = JSON.parseArray(JSON.toJSONString(JsonPath.using(conf).parse(testnote).read(jsonpath)));
|
||||
List<String> result = JSONObject.parseArray(datasArray.toJSONString(), String.class);
|
||||
if (exceptResults.equals(result)) {
|
||||
setcaseresult = 0;
|
||||
LogUtil.APP.info("用例【{}】 第【{}】步,jsonpath断言预期结果成功!预期结果:{} 测试结果: {} 执行结果:true",testcase.getCaseSign(),(i+1),exceptResults,result);
|
||||
caselog.insertTaskCaseLog(taskid, caseId, "jsonpath断言预期结果成功!预期结果:"+ expectedresults + "测试结果:" + result + "执行结果:true","info", String.valueOf(i + 1), "");
|
||||
} else {
|
||||
setcaseresult = 1;
|
||||
LogUtil.APP.warn("用例:{} 第{}步,jsonpath断言预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),(i+1),expectedresults,result);
|
||||
caselog.insertTaskCaseLog(taskid, caseId, "第" + (i + 1) + "步,正则匹配预期结果失败!预期结果:" + exceptResults + ",测试结果:" + result, "error", String.valueOf(i + 1), "");
|
||||
testnote = "用例第" + (i + 1) + "步,jsonpath断言预期结果失败!";
|
||||
if (testcase.getFailcontinue() == 0) {
|
||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
||||
break;
|
||||
} else {
|
||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
||||
}
|
||||
|
||||
// 某一步骤失败后,此条用例置为失败退出
|
||||
break;
|
||||
}
|
||||
}
|
||||
// ÍêÈ«ÏàµÈ
|
||||
else {
|
||||
if (expectedresults.equals(testnote)) {
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
package luckyclient.caserun.exinterface;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jayway.jsonpath.Configuration;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import luckyclient.caserun.exinterface.analyticsteps.InterfaceAnalyticCase;
|
||||
import luckyclient.caserun.publicdispose.ActionManageForSteps;
|
||||
import luckyclient.publicclass.InvokeMethod;
|
||||
|
@ -32,6 +38,7 @@ public class WebTestCaseDebug {
|
|||
private static final String ASSIGNMENT_SIGN = "$=";
|
||||
private static final String FUZZY_MATCHING_SIGN = "%=";
|
||||
private static final String REGULAR_MATCHING_SIGN = "~=";
|
||||
protected static final String JSONPATH_SIGN = "$J=";
|
||||
|
||||
/**
|
||||
* @param executor
|
||||
|
@ -139,6 +146,30 @@ public class WebTestCaseDebug {
|
|||
}
|
||||
}
|
||||
}
|
||||
//jsonpath断言
|
||||
else if (expectedresults.length() > JSONPATH_SIGN.length() && expectedresults.startsWith(JSONPATH_SIGN)) {
|
||||
expectedresults = expectedresults.substring(JSONPATH_SIGN.length());
|
||||
String jsonpath = expectedresults.split("=")[0];
|
||||
String exceptResult = expectedresults.split("=")[1];
|
||||
List<String> exceptResults = Arrays.asList(exceptResult.split(","));
|
||||
Configuration conf = Configuration.defaultConfiguration();
|
||||
JSONArray datasArray = JSON.parseArray(JSON.toJSONString(JsonPath.using(conf).parse(testnote).read(jsonpath)));
|
||||
List<String> result = JSONObject.parseArray(datasArray.toJSONString(), String.class);
|
||||
if (exceptResults.equals(result)) {
|
||||
setcaseresult = 0;
|
||||
PostServerAPI.cPostDebugLog(userId, caseId, "INFO", "jsonpath断言预期结果成功!预期结果:" + expectedresults + " 测试结果: " + result.toString() + "校验结果: true", 0);
|
||||
} else {
|
||||
setcaseresult = 1;
|
||||
PostServerAPI.cPostDebugLog(userId, caseId, "ERROR", "第" + (i + 1) + "步,jsonpath断言预期结果失败!预期结果:" + expectedresults + ",测试结果:" + result.toString(),0);
|
||||
testnote = "用例第" + (i + 1) + "步,jsonpath断言预期结果失败!";
|
||||
if (testcase.getFailcontinue() == 0) {
|
||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),(i+1));
|
||||
break;
|
||||
} else {
|
||||
LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),(i+1));
|
||||
}
|
||||
}
|
||||
}
|
||||
// ÍêÈ«ÏàµÈ
|
||||
else {
|
||||
if (expectedresults.equals(testnote)) {
|
||||
|
|
Loading…
Reference in New Issue