用例步骤表触发JMeter调用接口调整
This commit is contained in:
@@ -63,8 +63,8 @@ public class JMeterUtil {
|
||||
* @param jmeterHomePath
|
||||
* @return
|
||||
*/
|
||||
public static String getJmeterResult(Long id, String url, int port, String method, String paramJson, String requestHeader, String jmeterHomePath) {
|
||||
String result = "";
|
||||
public static Map<String, String> getJmeterResult(Long id, String url, int port, String method, String paramJson, String requestHeader, String jmeterHomePath) {
|
||||
Map<String, String> result = null;
|
||||
try {
|
||||
// 1. 初始化 JMeter
|
||||
JMeterUtils.loadJMeterProperties(jmeterHomePath + "/bin/jmeter.properties");
|
||||
@@ -379,7 +379,7 @@ public class JMeterUtil {
|
||||
* @param filePath
|
||||
* @return
|
||||
*/
|
||||
private static String getResultMessageFromFile(String filePath) {
|
||||
private static Map<String, String> getResultMessageFromFile(String filePath) {
|
||||
File file = new File(filePath);
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
@@ -395,12 +395,16 @@ public class JMeterUtil {
|
||||
NodeList httpSampleList = document.getElementsByTagName("httpSample");
|
||||
Node httpSampleNode = httpSampleList.item(0);
|
||||
if (httpSampleNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Map<String, String> resultMap = new HashMap<>();
|
||||
Element httpSampleElement = (Element) httpSampleNode;
|
||||
String costMiliseconds = httpSampleElement.getAttribute("t");
|
||||
resultMap.put("costMiliseconds", costMiliseconds);
|
||||
// 提取子节点<responseData>的内容
|
||||
NodeList responseDataList = httpSampleElement.getElementsByTagName("responseData");
|
||||
if (responseDataList.getLength() > 0) {
|
||||
Element responseDataElement = (Element) responseDataList.item(0);
|
||||
return responseDataElement.getTextContent();
|
||||
resultMap.put("costMiliseconds", responseDataElement.getTextContent());
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -415,7 +419,7 @@ public class JMeterUtil {
|
||||
String requestHeader = "{\"Content-Type\":\"application/json; charset=UTF-8\",\"Authorization\":\"Bearer token123\"}";
|
||||
String jmeterHomePath = "D:/apache-jmeter-5.4.3";
|
||||
// String result = getJmeterResult("http://127.0.0.1:3000/api/items/add", 3000, "POST", paramJson, requestHeader, jmeterHomePath);
|
||||
String result = getJmeterResult(123L, "http://127.0.0.1:3000/api/items/user", 3000, "GET", paramJson, requestHeader, jmeterHomePath);
|
||||
System.out.println(result);
|
||||
getJmeterResult(123L, "http://127.0.0.1:3000/api/items/user", 3000, "GET", paramJson, requestHeader, jmeterHomePath);
|
||||
// System.out.println(result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user