diff --git a/backend/src/main/java/io/metersphere/api/controller/APITestController.java b/backend/src/main/java/io/metersphere/api/controller/APITestController.java index 61eb6e2fef..85b1bc768c 100644 --- a/backend/src/main/java/io/metersphere/api/controller/APITestController.java +++ b/backend/src/main/java/io/metersphere/api/controller/APITestController.java @@ -393,7 +393,7 @@ public class APITestController { String testName = runRequest.getName(); //将jmx处理封装为通用方法 - jmxString = apiTestService.updateJmxString(jmxString,testName,true); + jmxString = apiTestService.updateJmxString(jmxString,testName,false); JmxInfoDTO dto = new JmxInfoDTO(); dto.setName(runRequest.getName() + ".jmx"); diff --git a/backend/src/main/java/io/metersphere/api/service/APITestService.java b/backend/src/main/java/io/metersphere/api/service/APITestService.java index 10cf3ab666..781ca72078 100644 --- a/backend/src/main/java/io/metersphere/api/service/APITestService.java +++ b/backend/src/main/java/io/metersphere/api/service/APITestService.java @@ -461,7 +461,20 @@ public class APITestService { }); } - public String updateJmxString(String jmxString,String testName,boolean updateHTTPSamplerProxyName) { + /** + * @param jmxString 原JMX文件 + * @param testName 某些节点要替换的testName + * @param isFromScenario 是否来源于场景 (来源于场景的话,testName要进行处理) + * @return + */ + public String updateJmxString(String jmxString, String testName, boolean isFromScenario) { + if (isFromScenario) { + //如果调用源来自场景, 原testName是 案例<->场景 ,需要进行切分,只保留案例名 + String[] testNameArr = testName.split("<->"); + if (testNameArr.length > 0) { + testName = testNameArr[0]; + } + } try { //将ThreadGroup的testname改为接口名称 Document doc = DocumentHelper.parseText(jmxString);// 获取可续保保单列表报文模板 @@ -473,11 +486,9 @@ public class APITestService { List thirdHashTreeElementList = innerHashTreeElement.elements("hashTree"); for (Element element : thirdHashTreeElementList) { - if(updateHTTPSamplerProxyName){ - List sampleProxyElementList = element.elements("HTTPSamplerProxy"); - for (Element itemElement : sampleProxyElementList) { - itemElement.attribute("testname").setText(testName); - } + List sampleProxyElementList = element.elements("HTTPSamplerProxy"); + for (Element itemElement : sampleProxyElementList) { + itemElement.attribute("testname").setText(testName); } //检查有没有自定义参数 List scriptHashTreeElementList = element.elements("hashTree"); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index bbe5e68f36..661e607b61 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -709,7 +709,7 @@ public class ApiAutomationService { HashTree jmeterHashTree = generateHashTree(apiScenarios, request, null); String jmx = testPlan.getJmx(jmeterHashTree); - jmx = apiTestService.updateJmxString(jmx, testName, false); + jmx = apiTestService.updateJmxString(jmx,testName,true); //将ThreadGroup的testname改为接口名称 // Document doc = DocumentHelper.parseText(jmx);// 获取可续保保单列表报文模板