fix(接口自动化): 优化报告显示问题

This commit is contained in:
fit2-zhao 2021-01-28 14:38:40 +08:00
parent 997d1ef02a
commit 1777735325
9 changed files with 67 additions and 8 deletions

View File

@ -71,6 +71,7 @@ public class MsScenario extends MsTestElement {
ex.printStackTrace();
}
}
config.setStep(this.name);
config.setStepType("SCENARIO");
config.setEnableCookieShare(enableCookieShare);
@ -91,6 +92,8 @@ public class MsScenario extends MsTestElement {
this.addRandom(tree, variables);
if (CollectionUtils.isNotEmpty(hashTree)) {
for (MsTestElement el : hashTree) {
// 给所有孩子加一个父亲标志
el.setParent(this);
el.toHashTree(tree, el.getHashTree(), config);
}
}

View File

@ -29,10 +29,12 @@ import io.metersphere.api.service.ApiDefinitionService;
import io.metersphere.api.service.ApiTestEnvironmentService;
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.commons.constants.LoopConstants;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.LogUtil;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.config.CSVDataSet;
import org.apache.jmeter.config.RandomVariableConfig;
@ -96,7 +98,10 @@ public abstract class MsTestElement {
@JSONField(ordinal = 10)
private LinkedList<MsTestElement> hashTree;
private MsTestElement parent;
private static final String BODY_FILE_DIR = "/opt/metersphere/data/body";
// 公共环境逐层传递如果自身有环境 以自身引用环境为准否则以公共环境作为请求环境
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
for (MsTestElement el : hashTree) {
@ -173,7 +178,7 @@ public abstract class MsTestElement {
return null;
}
protected void addCsvDataSet(HashTree tree,List<ScenarioVariable> variables) {
protected void addCsvDataSet(HashTree tree, List<ScenarioVariable> variables) {
if (CollectionUtils.isNotEmpty(variables)) {
List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isCSVValid).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(list)) {
@ -197,7 +202,7 @@ public abstract class MsTestElement {
}
}
protected void addCounter(HashTree tree,List<ScenarioVariable> variables) {
protected void addCounter(HashTree tree, List<ScenarioVariable> variables) {
if (CollectionUtils.isNotEmpty(variables)) {
List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isCounterValid).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(list)) {
@ -219,7 +224,7 @@ public abstract class MsTestElement {
}
}
protected void addRandom(HashTree tree,List<ScenarioVariable> variables) {
protected void addRandom(HashTree tree, List<ScenarioVariable> variables) {
if (CollectionUtils.isNotEmpty(variables)) {
List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isRandom).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(list)) {
@ -240,6 +245,38 @@ public abstract class MsTestElement {
}
}
public MsTestElement getRootParent(MsTestElement element) {
if (element.getParent() == null) {
return element;
}
if ("LoopController".equals(element.getType())) {
return element;
}
return getRootParent(element.getParent());
}
protected String getParentName(MsTestElement element) {
if (element != null) {
MsTestElement parent = this.getRootParent(element);
if (parent != null) {
if ("LoopController".equals(parent.getType())) {
MsLoopController loopController = (MsLoopController) parent;
if (StringUtils.equals(loopController.getLoopType(), LoopConstants.WHILE.name()) && loopController.getWhileController() != null) {
return "While 循环-" + "${LoopCounterConfigXXX}";
}
if (StringUtils.equals(loopController.getLoopType(), LoopConstants.FOREACH.name()) && loopController.getForEachController() != null) {
return "ForEach 循环-" + "${LoopCounterConfigXXX}";
}
if (StringUtils.equals(loopController.getLoopType(), LoopConstants.LOOP_COUNT.name()) && loopController.getCountController() != null) {
return "次数循环-" + "${LoopCounterConfigXXX}";
}
}
return parent.getName();
}
return element.getName();
}
return "";
}
}

View File

@ -32,6 +32,8 @@ public class MsIfController extends MsTestElement {
final HashTree groupTree = tree.add(ifController());
if (CollectionUtils.isNotEmpty(hashTree)) {
hashTree.forEach(el -> {
// 给所有孩子加一个父亲标志
el.setParent(this);
el.toHashTree(groupTree, el.getHashTree(), config);
});
}

View File

@ -83,6 +83,8 @@ public class MsLoopController extends MsTestElement {
if (CollectionUtils.isNotEmpty(hashTree)) {
hashTree.forEach(el -> {
// 给所有孩子加一个父亲标志
el.setParent(this);
el.toHashTree(groupTree, el.getHashTree(), config);
});
}

View File

@ -39,7 +39,10 @@ public class MsJSR223Processor extends MsTestElement {
} else {
processor.setName("JSR223Processor");
}
if (config != null && StringUtils.isNotEmpty(config.getStep())) {
String name = this.getParentName(this.getParent());
if (StringUtils.isNotEmpty(name)) {
processor.setName(this.getName() + "<->" + name);
} else if (config != null && StringUtils.isNotEmpty(config.getStep())) {
if ("SCENARIO".equals(config.getStepType())) {
processor.setName(this.getName() + "<->" + config.getStep());
} else {

View File

@ -77,7 +77,10 @@ public class MsDubboSampler extends MsTestElement {
private DubboSample dubboSample(ParameterConfig config) {
DubboSample sampler = new DubboSample();
sampler.setName(this.getName());
if (config != null && StringUtils.isNotEmpty(config.getStep())) {
String name = this.getParentName(this.getParent());
if (StringUtils.isNotEmpty(name)) {
sampler.setName(this.getName() + "<->" + name);
} else if (config != null && StringUtils.isNotEmpty(config.getStep())) {
if ("SCENARIO".equals(config.getStepType())) {
sampler.setName(this.getName() + "<->" + config.getStep());
} else {

View File

@ -97,7 +97,10 @@ public class MsHTTPSamplerProxy extends MsTestElement {
HTTPSamplerProxy sampler = new HTTPSamplerProxy();
sampler.setEnabled(true);
sampler.setName(this.getName());
if (config != null && StringUtils.isNotEmpty(config.getStep())) {
String name = this.getParentName(this.getParent());
if (StringUtils.isNotEmpty(name)) {
sampler.setName(this.getName() + "<->" + name);
} else if (config != null && StringUtils.isNotEmpty(config.getStep())) {
if ("SCENARIO".equals(config.getStepType())) {
sampler.setName(this.getName() + "<->" + config.getStep());
} else {

View File

@ -110,7 +110,10 @@ public class MsJDBCSampler extends MsTestElement {
private JDBCSampler jdbcSampler(ParameterConfig config) {
JDBCSampler sampler = new JDBCSampler();
sampler.setName(this.getName());
if (config != null && StringUtils.isNotEmpty(config.getStep())) {
String name = this.getParentName(this.getParent());
if (StringUtils.isNotEmpty(name)) {
sampler.setName(this.getName() + "<->" + name);
} else if (config != null && StringUtils.isNotEmpty(config.getStep())) {
if ("SCENARIO".equals(config.getStepType())) {
sampler.setName(this.getName() + "<->" + config.getStep());
} else {

View File

@ -102,7 +102,10 @@ public class MsTCPSampler extends MsTestElement {
private TCPSampler tcpSampler(ParameterConfig config) {
TCPSampler tcpSampler = new TCPSampler();
tcpSampler.setName(this.getName());
if (config != null && StringUtils.isNotEmpty(config.getStep())) {
String name = this.getParentName(this.getParent());
if (StringUtils.isNotEmpty(name)) {
tcpSampler.setName(this.getName() + "<->" + name);
} else if (config != null && StringUtils.isNotEmpty(config.getStep())) {
if ("SCENARIO".equals(config.getStepType())) {
tcpSampler.setName(this.getName() + "<->" + config.getStep());
} else {