This commit is contained in:
chenjianxing 2021-02-19 17:47:51 +08:00
commit ff478c3d88
5 changed files with 34 additions and 23 deletions

View File

@ -20,6 +20,8 @@ import lombok.EqualsAndHashCode;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.http.control.Header;
import org.apache.jmeter.protocol.http.control.HeaderManager;
import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jorphan.collections.HashTree;
@ -100,6 +102,9 @@ public class MsScenario extends MsTestElement {
el.toHashTree(tree, el.getHashTree(), config);
}
}
if (CollectionUtils.isNotEmpty(this.headers)) {
setHeader(tree, this.headers);
}
}
public void setOldVariables(List<KeyValue> oldVariables) {
@ -109,6 +114,20 @@ public class MsScenario extends MsTestElement {
}
}
public void setHeader(HashTree tree, List<KeyValue> headers) {
if (CollectionUtils.isNotEmpty(headers)) {
HeaderManager headerManager = new HeaderManager();
headerManager.setEnabled(true);
headerManager.setName(this.getName() + "场景Headers");
headerManager.setProperty(TestElement.TEST_CLASS, HeaderManager.class.getName());
headerManager.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("HeaderPanel"));
headers.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->
headerManager.add(new Header(keyValue.getName(), keyValue.getValue()))
);
tree.add(headerManager);
}
}
private Arguments arguments(ParameterConfig config) {
Arguments arguments = new Arguments();
arguments.setEnabled(true);
@ -134,11 +153,6 @@ public class MsScenario extends MsTestElement {
arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=")
);
}
if (CollectionUtils.isNotEmpty(this.headers)) {
this.headers.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->
arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=")
);
}
return arguments;
}

View File

@ -102,7 +102,7 @@ public class MsLoopController extends MsTestElement {
return counterConfig;
}
private LoopController loopController() {
private LoopController initLoopController() {
LoopController loopController = new LoopController();
loopController.setEnabled(true);
loopController.setName("LoopController");
@ -113,7 +113,7 @@ public class MsLoopController extends MsTestElement {
return loopController;
}
public String getCondition() {
private String getCondition() {
String variable = "\"" + this.whileController.getVariable() + "\"";
String operator = this.whileController.getOperator();
String value = "\"" + this.whileController.getValue() + "\"";
@ -136,7 +136,7 @@ public class MsLoopController extends MsTestElement {
return "${__jexl3(" + variable + operator + value + ")}";
}
private WhileController whileController() {
private WhileController initWhileController() {
String condition = getCondition();
if (StringUtils.isEmpty(condition)) {
return null;
@ -150,7 +150,7 @@ public class MsLoopController extends MsTestElement {
return controller;
}
private ForeachController foreachController() {
private ForeachController initForeachController() {
ForeachController controller = new ForeachController();
controller.setEnabled(true);
controller.setName("ForeachController");
@ -175,13 +175,13 @@ public class MsLoopController extends MsTestElement {
runTime.setRuntime(timeout);
// 添加超时处理防止死循环
HashTree hashTree = tree.add(runTime);
return hashTree.add(whileController());
return hashTree.add(initWhileController());
}
if (StringUtils.equals(this.loopType, LoopConstants.FOREACH.name()) && this.forEachController != null) {
return tree.add(foreachController());
return tree.add(initForeachController());
}
if (StringUtils.equals(this.loopType, LoopConstants.LOOP_COUNT.name()) && this.countController != null) {
return tree.add(loopController());
return tree.add(initLoopController());
}
return null;
}

View File

@ -276,22 +276,19 @@ public class XmindCaseParser {
testCase.setType("functional");
String tc = title.replace("", ":");
String[] tcArr = tc.split(":");
if (tcArr.length < 1) {
String[] tcArrs = tc.split(":");
if (tcArrs.length < 1) {
process.add(Translator.get("test_case_name") + Translator.get("incorrect_format"), title);
return;
}
// 用例名称
StringBuffer name = new StringBuffer();
for (int i = 1; i < tcArr.length; i++) {
name.append(tcArr[i]);
}
testCase.setName(name.toString());
String name = title.replace(tcArrs[0] + "", "").replace(tcArrs[0] + ":", "");
testCase.setName(name);
testCase.setNodePath(nodePath);
// 用例等级和用例性质处理
if (tcArr[0].indexOf("-") != -1) {
for (String item : tcArr[0].split("-")) {
if (tcArrs[0].indexOf("-") != -1) {
for (String item : tcArrs[0].split("-")) {
if (isAvailable(item, TC_REGEX)) {
continue;
} else if (item.toUpperCase().startsWith("P")) {

@ -1 +1 @@
Subproject commit b35af517d888268abd3a8f2b58d6ea94335138a5
Subproject commit 5e0b365f1080197e84055e80071165787e2e79c5

@ -1 +1 @@
Subproject commit a3d469fd18f663d11e5c1c49f71ced6e3e4b292f
Subproject commit 4cc8926bad84083f675a262d6766a92bb09a890a