Merge remote-tracking branch 'origin/master'

This commit is contained in:
wenyann 2021-03-23 11:24:24 +08:00
commit 6be8af57a3
8 changed files with 56 additions and 14 deletions

View File

@ -17,6 +17,8 @@ import org.apache.jmeter.control.LoopController;
import org.apache.jmeter.control.RunTime; import org.apache.jmeter.control.RunTime;
import org.apache.jmeter.control.WhileController; import org.apache.jmeter.control.WhileController;
import org.apache.jmeter.modifiers.CounterConfig; import org.apache.jmeter.modifiers.CounterConfig;
import org.apache.jmeter.modifiers.JSR223PreProcessor;
import org.apache.jmeter.protocol.java.sampler.JSR223Sampler;
import org.apache.jmeter.reporters.ResultAction; import org.apache.jmeter.reporters.ResultAction;
import org.apache.jmeter.save.SaveService; import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.testelement.TestElement; import org.apache.jmeter.testelement.TestElement;
@ -24,6 +26,7 @@ import org.apache.jmeter.timers.ConstantTimer;
import org.apache.jorphan.collections.HashTree; import org.apache.jorphan.collections.HashTree;
import java.util.List; import java.util.List;
import java.util.UUID;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ -42,6 +45,9 @@ public class MsLoopController extends MsTestElement {
@JSONField(ordinal = 23) @JSONField(ordinal = 23)
private MsWhileController whileController; private MsWhileController whileController;
private String ms_current_timer = UUID.randomUUID().toString();
@Override @Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
// 非导出操作且不是启用状态则跳过执行 // 非导出操作且不是启用状态则跳过执行
@ -122,7 +128,8 @@ public class MsLoopController extends MsTestElement {
operator = ""; operator = "";
value = ""; value = "";
} }
return "${__jexl3(" + variable + operator + value + ")}"; ms_current_timer = UUID.randomUUID().toString();
return "${__jexl3(" + variable + operator + value + " && \"${" + ms_current_timer + "}\" !=\"stop\")}";
} }
private WhileController initWhileController() { private WhileController initWhileController() {
@ -151,6 +158,32 @@ public class MsLoopController extends MsTestElement {
return controller; return controller;
} }
private String script() {
String script = "\n" +
"import java.util.*;\n" +
"import java.text.SimpleDateFormat;\n" +
"import org.apache.jmeter.threads.JMeterContextService;\n" +
"\n" +
"// 循环控制器超时后结束循环\n" +
"try{\n" +
"\tString ms_current_timer = vars.get(\"" + ms_current_timer + "\");\n" +
"\tlong _nowTime = System.currentTimeMillis(); \n" +
"\tif(ms_current_timer == null ){\n" +
"\t\tvars.put(\"" + ms_current_timer + "\",_nowTime.toString());\n" +
"\t}\n" +
"\tlong time = Long.parseLong(vars.get(\"" + ms_current_timer + "\"));\n" +
"\t if((_nowTime - time) > " + this.whileController.getTimeout() + " ){\n" +
"\t \tvars.put(\"" + ms_current_timer + "\", \"stop\");\n" +
"\t \tlog.info( \"结束循环\");\n" +
"\t }\n" +
"}catch (Exception e){\n" +
"\tlog.info( e.getMessage());\n" +
"\tvars.put(\"" + ms_current_timer + "\", \"stop\");\n" +
"}\n";
return script;
}
private HashTree controller(HashTree tree) { private HashTree controller(HashTree tree) {
if (StringUtils.equals(this.loopType, LoopConstants.WHILE.name()) && this.whileController != null) { if (StringUtils.equals(this.loopType, LoopConstants.WHILE.name()) && this.whileController != null) {
RunTime runTime = new RunTime(); RunTime runTime = new RunTime();
@ -162,9 +195,17 @@ public class MsLoopController extends MsTestElement {
timeout = 1; timeout = 1;
} }
runTime.setRuntime(timeout); runTime.setRuntime(timeout);
HashTree hashTree = tree.add(initWhileController());
// 添加超时处理防止死循环 // 添加超时处理防止死循环
HashTree hashTree = tree.add(runTime); JSR223PreProcessor jsr223PreProcessor = new JSR223PreProcessor();
return hashTree.add(initWhileController()); jsr223PreProcessor.setName("循环超时处理");
jsr223PreProcessor.setProperty(TestElement.TEST_CLASS, JSR223Sampler.class.getName());
jsr223PreProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
jsr223PreProcessor.setProperty("cacheKey", "true");
jsr223PreProcessor.setProperty("scriptLanguage", "beanshell");
jsr223PreProcessor.setProperty("script", script());
hashTree.add(jsr223PreProcessor);
return hashTree;
} }
if (StringUtils.equals(this.loopType, LoopConstants.FOREACH.name()) && this.forEachController != null) { if (StringUtils.equals(this.loopType, LoopConstants.FOREACH.name()) && this.forEachController != null) {
return tree.add(initForeachController()); return tree.add(initForeachController());

View File

@ -34,10 +34,10 @@ public class MsExtract extends MsTestElement {
if (!config.isOperating() && !this.isEnable()) { if (!config.isOperating() && !this.isEnable()) {
return; return;
} }
addRequestExtractors(tree); addRequestExtractors(tree, config);
} }
private void addRequestExtractors(HashTree samplerHashTree) { private void addRequestExtractors(HashTree samplerHashTree, ParameterConfig config) {
StringJoiner extract = new StringJoiner(";"); StringJoiner extract = new StringJoiner(";");
if (CollectionUtils.isNotEmpty(this.getRegex())) { if (CollectionUtils.isNotEmpty(this.getRegex())) {
@ -55,7 +55,7 @@ public class MsExtract extends MsTestElement {
samplerHashTree.add(jsonPostProcessor(extractJSONPath, extract)) samplerHashTree.add(jsonPostProcessor(extractJSONPath, extract))
); );
} }
if (Optional.ofNullable(extract).orElse(extract).length() > 0) { if (Optional.ofNullable(extract).orElse(extract).length() > 0 && !config.isOperating()) {
JSR223PostProcessor shell = new JSR223PostProcessor(); JSR223PostProcessor shell = new JSR223PostProcessor();
shell.setEnabled(true); shell.setEnabled(true);
shell.setName(StringUtils.isEmpty(this.getName()) ? "JSR223PostProcessor" : this.getName()); shell.setName(StringUtils.isEmpty(this.getName()) ? "JSR223PostProcessor" : this.getName());

View File

@ -52,6 +52,7 @@ public class ShiroUtils {
filterChainDefinitionMap.put("/", "apikey, authc"); // 跳转到 / 不用校验 csrf filterChainDefinitionMap.put("/", "apikey, authc"); // 跳转到 / 不用校验 csrf
filterChainDefinitionMap.put("/language", "apikey, authc");// 跳转到 /language 不用校验 csrf filterChainDefinitionMap.put("/language", "apikey, authc");// 跳转到 /language 不用校验 csrf
filterChainDefinitionMap.put("/document", "apikey, authc"); // 跳转到 /document 不用校验 csrf filterChainDefinitionMap.put("/document", "apikey, authc"); // 跳转到 /document 不用校验 csrf
filterChainDefinitionMap.put("/test/case/file/preview/**", "apikey, authc"); // 预览测试用例附件 不用校验 csrf
} }
public static Cookie getSessionIdCookie(){ public static Cookie getSessionIdCookie(){

View File

@ -6,7 +6,7 @@ public class TrackCount {
public static final String P2 = "P2"; public static final String P2 = "P2";
public static final String P3 = "P3"; public static final String P3 = "P3";
public static final String API = "api"; public static final String TESTCASE = "testcase";
public static final String PERFORMANCE = "performance"; public static final String PERFORMANCE = "performance";
public static final String AUTOMATION = "automation"; public static final String AUTOMATION = "automation";
} }

View File

@ -145,7 +145,7 @@ public class TrackStatisticsDTO {
public void countRelevance(List<TrackCountResult> relevanceResults) { public void countRelevance(List<TrackCountResult> relevanceResults) {
for (TrackCountResult countResult : relevanceResults) { for (TrackCountResult countResult : relevanceResults) {
switch (countResult.getGroupField()){ switch (countResult.getGroupField()){
case TrackCount.API: case TrackCount.TESTCASE:
this.apiCaseCount += countResult.getCountNumber(); this.apiCaseCount += countResult.getCountNumber();
this.allRelevanceCaseCount += countResult.getCountNumber(); this.allRelevanceCaseCount += countResult.getCountNumber();
break; break;

View File

@ -945,9 +945,9 @@ export default {
export_tip: "Export Tip", export_tip: "Export Tip",
ms_tip: "Support for MeterSphere JSON format", ms_tip: "Support for MeterSphere JSON format",
ms_export_tip: "Export jSON-formatted files via MeterSphere website or browser plug-ins", ms_export_tip: "Export jSON-formatted files via MeterSphere website or browser plug-ins",
har_export_tip: "Export Har files by browser dev-tool", har_export_tip: "Export HAR files by browser dev-tool",
swagger_tip: "Swagger 2.0 and 3.0 json files are supported", swagger_tip: "Swagger 2.0 and 3.0 json files are supported",
har_tip: "Only Har files are supported", har_tip: "Only HAR files are supported",
postman_tip: "Only Postman Collection V2.1 json files are supported", postman_tip: "Only Postman Collection V2.1 json files are supported",
postman_export_tip: "Export the test collection by Postman", postman_export_tip: "Export the test collection by Postman",
swagger_export_tip: "Export jSON-formatted files via Swagger website", swagger_export_tip: "Export jSON-formatted files via Swagger website",

View File

@ -948,10 +948,10 @@ export default {
export_tip: "导出方法", export_tip: "导出方法",
ms_tip: "支持 MeterSphere json 格式", ms_tip: "支持 MeterSphere json 格式",
ms_export_tip: "通过 MeterSphere 接口测试页面或者浏览器插件导出 json 格式文件", ms_export_tip: "通过 MeterSphere 接口测试页面或者浏览器插件导出 json 格式文件",
har_export_tip: "通过 浏览器的开发者工具 导出 Har 格式文件", har_export_tip: "通过 浏览器的开发者工具 导出 HAR 格式文件",
postman_tip: "只支持 Postman Collection v2.1 格式的 json 文件", postman_tip: "只支持 Postman Collection v2.1 格式的 json 文件",
swagger_tip: "支持 Swagger 2.0 与 3.0 版本的 json 文件", swagger_tip: "支持 Swagger 2.0 与 3.0 版本的 json 文件",
har_tip: "只支持 Har 文件", har_tip: "只支持 HAR 文件",
post_export_tip: "通过 Postman 导出测试集合", post_export_tip: "通过 Postman 导出测试集合",
swagger_export_tip: "通过 Swagger 页面导出", swagger_export_tip: "通过 Swagger 页面导出",
jmeter_export_tip: "通过 JMeter 生成JMX文件", jmeter_export_tip: "通过 JMeter 生成JMX文件",

View File

@ -947,10 +947,10 @@ export default {
export_tip: "導出方法", export_tip: "導出方法",
ms_tip: "支持 MeterSphere json 格式", ms_tip: "支持 MeterSphere json 格式",
ms_export_tip: "通過 MeterSphere 接口測試頁面或者瀏覽器插件導出 json 格式文件", ms_export_tip: "通過 MeterSphere 接口測試頁面或者瀏覽器插件導出 json 格式文件",
har_export_tip: "通过 瀏覽器到開發者工具 导出 Har 格式文件", har_export_tip: "通过 瀏覽器到開發者工具 导出 HAR 格式文件",
postman_tip: "只支持 Postman Collection v2.1 格式的 json 文件", postman_tip: "只支持 Postman Collection v2.1 格式的 json 文件",
swagger_tip: "支持 Swagger 2.0 與 3.0 版本的 json 文件", swagger_tip: "支持 Swagger 2.0 與 3.0 版本的 json 文件",
har_tip: "只支持 Har 文件", har_tip: "只支持 HAR 文件",
post_export_tip: "通過 Postman 導出測試集合", post_export_tip: "通過 Postman 導出測試集合",
swagger_export_tip: "通過 Swagger 頁面導出", swagger_export_tip: "通過 Swagger 頁面導出",
jmeter_export_tip: "通過 JMeter 生成JMX文件", jmeter_export_tip: "通過 JMeter 生成JMX文件",