Merge remote-tracking branch 'origin/v1.6' into v1.6
This commit is contained in:
commit
f33b3b5343
|
@ -82,14 +82,14 @@ public class MsScenario extends MsTestElement {
|
|||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
// 场景变量
|
||||
// 场景变量和环境变量
|
||||
tree.add(arguments(config));
|
||||
|
||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||
for (MsTestElement el : hashTree) {
|
||||
el.toHashTree(tree, el.getHashTree(), config);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Arguments arguments(ParameterConfig config) {
|
||||
|
|
|
@ -20,13 +20,17 @@ import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
|||
import io.metersphere.api.dto.definition.request.sampler.MsJDBCSampler;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler;
|
||||
import io.metersphere.api.dto.definition.request.timer.MsConstantTimer;
|
||||
import io.metersphere.api.dto.scenario.KeyValue;
|
||||
import io.metersphere.api.service.ApiDefinitionService;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.jmeter.config.Arguments;
|
||||
import org.apache.jmeter.protocol.http.control.AuthManager;
|
||||
import org.apache.jmeter.save.SaveService;
|
||||
import org.apache.jmeter.testelement.TestElement;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
import org.apache.jorphan.collections.ListedHashTree;
|
||||
|
||||
|
@ -133,6 +137,22 @@ public abstract class MsTestElement {
|
|||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Arguments addArguments(ParameterConfig config) {
|
||||
if (config != null && config.getConfig() != null && config.getConfig().getCommonConfig() != null
|
||||
&& CollectionUtils.isNotEmpty(config.getConfig().getCommonConfig().getVariables())) {
|
||||
Arguments arguments = new Arguments();
|
||||
arguments.setEnabled(true);
|
||||
arguments.setName(name + "Variables");
|
||||
arguments.setProperty(TestElement.TEST_CLASS, Arguments.class.getName());
|
||||
arguments.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("ArgumentsPanel"));
|
||||
config.getConfig().getCommonConfig().getVariables().stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->
|
||||
arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=")
|
||||
);
|
||||
return arguments;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -114,6 +114,11 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
config.setConfig(JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class));
|
||||
}
|
||||
}
|
||||
// 添加环境中的公共变量
|
||||
Arguments arguments = this.addArguments(config);
|
||||
if (arguments != null) {
|
||||
tree.add(this.addArguments(config));
|
||||
}
|
||||
try {
|
||||
if (config != null && config.getConfig() != null) {
|
||||
String url = config.getConfig().getHttpConfig().getProtocol() + "://" + config.getConfig().getHttpConfig().getSocket();
|
||||
|
@ -138,7 +143,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
envPath += this.getPath();
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) {
|
||||
envPath = getRestParameters(URLDecoder.decode(envPath, "UTF-8"), config);
|
||||
envPath = getRestParameters(URLDecoder.decode(envPath, "UTF-8"));
|
||||
sampler.setPath(envPath);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(this.getArguments())) {
|
||||
|
@ -155,7 +160,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
sampler.setProtocol(urlObject.getProtocol());
|
||||
|
||||
if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) {
|
||||
sampler.setPath(getRestParameters(URLDecoder.decode(urlObject.getPath(), "UTF-8"), config));
|
||||
sampler.setPath(getRestParameters(URLDecoder.decode(urlObject.getPath(), "UTF-8")));
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(this.getArguments())) {
|
||||
sampler.setPath(getPostQueryParameters(URLDecoder.decode(urlObject.getPath(), "UTF-8")));
|
||||
|
@ -198,7 +203,19 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
}
|
||||
}
|
||||
|
||||
private String getRestParameters(String path, ParameterConfig config) {
|
||||
private boolean isVariable(String path, String value) {
|
||||
Pattern p = Pattern.compile("(\\$\\{)([\\w]+)(\\})");
|
||||
Matcher m = p.matcher(path);
|
||||
while (m.find()) {
|
||||
String group = m.group(2);
|
||||
if (group.equals(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getRestParameters(String path) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append(path);
|
||||
stringBuffer.append("/");
|
||||
|
@ -211,8 +228,10 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
Matcher m = p.matcher(path);
|
||||
while (m.find()) {
|
||||
String group = m.group(2);
|
||||
if (!isVariable(path, group)) {
|
||||
path = path.replace("{" + group + "}", keyValueMap.get(group));
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -296,7 +296,6 @@ public class ApiDefinitionService {
|
|||
if (StringUtils.isNotBlank(request.getType()) && StringUtils.equals(request.getType(), ApiRunMode.API_PLAN.name())) {
|
||||
runMode = ApiRunMode.API_PLAN.name();
|
||||
}
|
||||
request.getTestElement().getJmx(hashTree);
|
||||
// 调用执行方法
|
||||
jMeterService.runDefinition(request.getId(), hashTree, request.getReportId(), runMode);
|
||||
return request.getId();
|
||||
|
|
|
@ -118,12 +118,12 @@
|
|||
display: inline-block;
|
||||
}
|
||||
|
||||
.ms-main-container {
|
||||
height: calc(100vh - 80px - 50px);
|
||||
/deep/ .ms-main-container {
|
||||
height: calc(100vh - 80px - 53px);
|
||||
}
|
||||
|
||||
.ms-aside-container {
|
||||
height: calc(100vh - 80px - 51px);
|
||||
/deep/ .ms-aside-container {
|
||||
height: calc(100vh - 80px - 53px);
|
||||
margin-top: 1px;
|
||||
}
|
||||
|
||||
|
@ -133,4 +133,5 @@
|
|||
color: dimgray;
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
|
|
|
@ -126,6 +126,7 @@ export default {
|
|||
modifier: 'Modifier',
|
||||
validate: "Validate",
|
||||
batch_add: "Batch add",
|
||||
check_project_tip: "Create or select the project first",
|
||||
date: {
|
||||
select_date: 'Select date',
|
||||
start_date: 'Start date',
|
||||
|
|
|
@ -126,6 +126,7 @@ export default {
|
|||
modifier: '修改人',
|
||||
validate: "校驗",
|
||||
batch_add: "批量添加",
|
||||
check_project_tip: "請先創建或選擇項目",
|
||||
date: {
|
||||
select_date: '選擇日期',
|
||||
start_date: '開始日期',
|
||||
|
|
Loading…
Reference in New Issue