fix(接口测试): 导入jmx文件query参数处理
--bug=1008540 --user=赵勇 【github#8283】jmeter脚本上传到ms之后url拼接丢失 https://www.tapd.cn/55049933/s/1077896
This commit is contained in:
parent
7f18cf17cd
commit
cb6f8f716c
|
@ -175,7 +175,6 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
|||
if (!path.startsWith("http://") && !path.startsWith("https://")) {
|
||||
String domain = source.getDomain();
|
||||
String protocol = source.getProtocol();
|
||||
String method = source.getMethod();
|
||||
StringBuilder pathAndQuery = new StringBuilder(100);
|
||||
if ("file".equalsIgnoreCase(protocol)) {
|
||||
domain = null;
|
||||
|
@ -184,18 +183,6 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
|||
}
|
||||
|
||||
pathAndQuery.append(path);
|
||||
if ("GET".equals(method) || "DELETE".equals(method) || "OPTIONS".equals(method)) {
|
||||
String queryString = source.getQueryString(source.getContentEncoding());
|
||||
if (queryString.length() > 0) {
|
||||
if (path.contains("?")) {
|
||||
pathAndQuery.append("&");
|
||||
} else {
|
||||
pathAndQuery.append("?");
|
||||
}
|
||||
|
||||
pathAndQuery.append(queryString);
|
||||
}
|
||||
}
|
||||
String portAsString = source.getPropertyAsString("HTTPSampler.port");
|
||||
return this.isProtocolDefaultPort(source) ? new URL(protocol, domain, pathAndQuery.toString()).toExternalForm() : this.url(protocol, domain, portAsString, pathAndQuery.toString());
|
||||
} else {
|
||||
|
@ -213,6 +200,44 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static String truncateUrlPage(String strURL) {
|
||||
String strAllParam = null;
|
||||
if (StringUtils.isNotEmpty(strURL)) {
|
||||
String[] arrSplit = strURL.split("[?]");
|
||||
if (strURL.length() > 1) {
|
||||
if (arrSplit.length > 1) {
|
||||
if (arrSplit[1] != null) {
|
||||
strAllParam = arrSplit[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return strAllParam;
|
||||
}
|
||||
|
||||
public static Map<String, String> parseURLParam(String URL) {
|
||||
Map<String, String> mapRequest = new LinkedHashMap<>();
|
||||
String strUrlParam = truncateUrlPage(URL);
|
||||
if (StringUtils.isEmpty(strUrlParam)) {
|
||||
return mapRequest;
|
||||
}
|
||||
//每个键值为一组
|
||||
String[] arrSplit = strUrlParam.split("[&]");
|
||||
for (String strSplit : arrSplit) {
|
||||
String[] arrSplitEqual = strSplit.split("[=]");
|
||||
//解析出键值
|
||||
if (arrSplitEqual.length > 1) {
|
||||
mapRequest.put(arrSplitEqual[0], arrSplitEqual[1]);
|
||||
} else {
|
||||
if (StringUtils.isNotEmpty(arrSplitEqual[0])) {
|
||||
//只有参数没有值,不加入
|
||||
mapRequest.put(arrSplitEqual[0], "");
|
||||
}
|
||||
}
|
||||
}
|
||||
return mapRequest;
|
||||
}
|
||||
|
||||
private void convertHttpSampler(MsHTTPSamplerProxy samplerProxy, Object key) {
|
||||
try {
|
||||
HTTPSamplerProxy source = (HTTPSamplerProxy) key;
|
||||
|
@ -303,9 +328,9 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
|||
}
|
||||
samplerProxy.getBody().initBinary();
|
||||
}
|
||||
// samplerProxy.setPath(source.getPath());
|
||||
samplerProxy.setMethod(source.getMethod());
|
||||
if (this.getUrl(source) != null) {
|
||||
URL url = source.getUrl();
|
||||
if (url != null) {
|
||||
samplerProxy.setUrl(this.getUrl(source));
|
||||
samplerProxy.setPath(null);
|
||||
}
|
||||
|
@ -530,9 +555,11 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
|||
RegexExtractor regexExtractor = (RegexExtractor) key;
|
||||
if (regexExtractor.useRequestHeaders()) {
|
||||
regex.setUseHeaders("request_headers");
|
||||
}if (regexExtractor.useHeaders()) {
|
||||
}
|
||||
if (regexExtractor.useHeaders()) {
|
||||
regex.setUseHeaders("true");
|
||||
} if (regexExtractor.useBody()) {
|
||||
}
|
||||
if (regexExtractor.useBody()) {
|
||||
regex.setUseHeaders("false");
|
||||
} else if (regexExtractor.useUnescapedBody()) {
|
||||
regex.setUseHeaders("unescaped");
|
||||
|
|
Loading…
Reference in New Issue