This commit is contained in:
chenjianxing 2020-09-17 15:11:37 +08:00
commit 370b424e7c
5 changed files with 31 additions and 3 deletions

View File

@ -439,6 +439,12 @@ public class JmeterDocumentParser implements DocumentParser {
item.appendChild(ele.getOwnerDocument().createTextNode(context.getProperty("timeout").toString())); item.appendChild(ele.getOwnerDocument().createTextNode(context.getProperty("timeout").toString()));
} }
} }
// 增加一个response_timeout避免目标网站不反回结果导致测试不能结束
if (item instanceof Element && nodeNameEquals(item, STRING_PROP)
&& StringUtils.equals(((Element) item).getAttribute("name"), "HTTPSampler.response_timeout")) {
removeChildren(item);
item.appendChild(ele.getOwnerDocument().createTextNode(""));
}
} }
} }

View File

@ -1,5 +1,6 @@
package io.metersphere.xmind; package io.metersphere.xmind;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import io.metersphere.base.domain.TestCaseWithBLOBs; import io.metersphere.base.domain.TestCaseWithBLOBs;
@ -23,6 +24,8 @@ import java.util.*;
/** /**
* 数据转换 * 数据转换
* 1 解析Xmind文件 XmindParser.parseJson
* 2 解析后的JSON 转成测试用例
*/ */
public class XmindToTestCaseParser { public class XmindToTestCaseParser {
@ -218,14 +221,25 @@ public class XmindToTestCaseParser {
return true; return true;
} }
// 导入思维导图处理
public String importXmind(MultipartFile multipartFile) { public String importXmind(MultipartFile multipartFile) {
StringBuffer processBuffer = new StringBuffer(); StringBuffer processBuffer = new StringBuffer();
File file = null;
try { try {
File file = multipartFileToFile(multipartFile); file = multipartFileToFile(multipartFile);
if (file == null || !file.exists()) if (file == null || !file.exists())
return Translator.get("incorrect_format"); return Translator.get("incorrect_format");
JsonRootBean root = XmindParser.parseObject(file);
file.delete(); // 获取思维导图内容
String content = XmindParser.parseJson(file);
if (StringUtils.isEmpty(content) || content.split("(?:tc:|tc)").length == 1) {
return Translator.get("import_xmind_not_found");
}
if (!StringUtils.isEmpty(content) && content.split("(?:tc:|tc)").length > 500) {
return Translator.get("import_xmind_count_error");
}
JsonRootBean root = JSON.parseObject(content, JsonRootBean.class);
if (root != null && root.getRootTopic() != null && root.getRootTopic().getChildren() != null) { if (root != null && root.getRootTopic() != null && root.getRootTopic().getChildren() != null) {
// 判断是模块还是用例 // 判断是模块还是用例
root.getRootTopic().getChildren().getAttached().forEach(item -> { root.getRootTopic().getChildren().getAttached().forEach(item -> {
@ -246,6 +260,8 @@ public class XmindToTestCaseParser {
LogUtil.error(ex.getMessage()); LogUtil.error(ex.getMessage());
ex.printStackTrace(); ex.printStackTrace();
} finally { } finally {
if (file != null)
file.delete();
testCaseWithBLOBs.clear(); testCaseWithBLOBs.clear();
} }
return process.toString(); return process.toString();

View File

@ -153,3 +153,5 @@ quota_duration_excess_workspace=The stress test duration exceeds the work space
quota_duration_excess_organization=The stress test duration exceeds the organization quota quota_duration_excess_organization=The stress test duration exceeds the organization quota
email_subject=Metersphere timing task result notification email_subject=Metersphere timing task result notification
import_xmind_count_error=The number of use cases imported into the mind map cannot exceed 500
import_xmind_not_found=Test case not found

View File

@ -152,6 +152,8 @@ quota_max_threads_excess_organization=最大并发数超过组织限额
quota_duration_excess_workspace=压测时长超过工作空间限额 quota_duration_excess_workspace=压测时长超过工作空间限额
quota_duration_excess_organization=压测时长超过组织限额 quota_duration_excess_organization=压测时长超过组织限额
email_subject=MeterSphere定时任务结果通知 email_subject=MeterSphere定时任务结果通知
import_xmind_count_error=思维导图导入用例数量不能超过 500 条
import_xmind_not_found=未找到测试用例

View File

@ -156,3 +156,5 @@ license_valid_license_code=授權碼已經存在
email_subject=MeterSphere定時任務結果通知 email_subject=MeterSphere定時任務結果通知
import_xmind_count_error=思維導圖導入用例數量不能超過 500 條
import_xmind_not_found=未找到测试用例