新增调试按钮以及http结果记录请求头和请求体参数
This commit is contained in:
@@ -67,6 +67,7 @@ public class JMeterUtil {
|
|||||||
String method = jmeterRequest.getMethod().toUpperCase();
|
String method = jmeterRequest.getMethod().toUpperCase();
|
||||||
String requestBody = jmeterRequest.getRequestBody();
|
String requestBody = jmeterRequest.getRequestBody();
|
||||||
String requestParams = jmeterRequest.getRequestParams();
|
String requestParams = jmeterRequest.getRequestParams();
|
||||||
|
String requestHeaderJson = "";
|
||||||
Map<String, String> requestParamsMap = convertJsonStringToMap(requestParams);
|
Map<String, String> requestParamsMap = convertJsonStringToMap(requestParams);
|
||||||
String requestHeader = jmeterRequest.getRequestHeader();
|
String requestHeader = jmeterRequest.getRequestHeader();
|
||||||
String jmeterHomePath = jmeterRequest.getJmeterHomePath();
|
String jmeterHomePath = jmeterRequest.getJmeterHomePath();
|
||||||
@@ -113,7 +114,7 @@ public class JMeterUtil {
|
|||||||
String value = entry.get("value");
|
String value = entry.get("value");
|
||||||
headerMap.put(key, value);
|
headerMap.put(key, value);
|
||||||
}
|
}
|
||||||
|
requestHeaderJson = gson.toJson(headerMap);
|
||||||
}
|
}
|
||||||
HeaderManager headerManager = createHeaderManager(headerMap);
|
HeaderManager headerManager = createHeaderManager(headerMap);
|
||||||
|
|
||||||
@@ -147,6 +148,10 @@ public class JMeterUtil {
|
|||||||
}
|
}
|
||||||
// 10. 获取响应结果
|
// 10. 获取响应结果
|
||||||
result = getResultMessageFromFile(jmeterHomePath + "/replay_result"+ id +".log");
|
result = getResultMessageFromFile(jmeterHomePath + "/replay_result"+ id +".log");
|
||||||
|
if (result != null) {
|
||||||
|
result.put("requestHeader", requestHeaderJson);
|
||||||
|
result.put("requestBody", requestBody);
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("JMeter 测试执行完成!");
|
System.out.println("JMeter 测试执行完成!");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -32,6 +32,14 @@ public class TestCaseResult extends BaseEntity {
|
|||||||
@Excel(name = "用例步骤id")
|
@Excel(name = "用例步骤id")
|
||||||
private Long stepId;
|
private Long stepId;
|
||||||
|
|
||||||
|
/** http 请求头 */
|
||||||
|
@Excel(name = "http 请求头")
|
||||||
|
private String requestHeader;
|
||||||
|
|
||||||
|
/** http 请求体 */
|
||||||
|
@Excel(name = "http 请求体")
|
||||||
|
private String requestBody;
|
||||||
|
|
||||||
/** http 响应头 */
|
/** http 响应头 */
|
||||||
@Excel(name = "http 响应头")
|
@Excel(name = "http 响应头")
|
||||||
private String responseHeader;
|
private String responseHeader;
|
||||||
|
|||||||
@@ -194,6 +194,8 @@ public class TestCaseServiceImpl implements ITestCaseService
|
|||||||
testCaseResult.setCaseId(testCase.getId());
|
testCaseResult.setCaseId(testCase.getId());
|
||||||
testCaseResult.setStepId(testCaseStep.getId());
|
testCaseResult.setStepId(testCaseStep.getId());
|
||||||
if (resultMap != null) {
|
if (resultMap != null) {
|
||||||
|
testCaseResult.setRequestHeader(resultMap.get("requestHeader"));
|
||||||
|
testCaseResult.setRequestBody(resultMap.get("requestBody"));
|
||||||
testCaseResult.setResponseHeader(resultMap.get("responseHeader"));
|
testCaseResult.setResponseHeader(resultMap.get("responseHeader"));
|
||||||
testCaseResult.setResponseBody(resultMap.get("responseBody"));
|
testCaseResult.setResponseBody(resultMap.get("responseBody"));
|
||||||
// 处理参数提取
|
// 处理参数提取
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<result property="id" column="id" />
|
<result property="id" column="id" />
|
||||||
<result property="caseId" column="case_id" />
|
<result property="caseId" column="case_id" />
|
||||||
<result property="stepId" column="step_id" />
|
<result property="stepId" column="step_id" />
|
||||||
|
<result property="requestHeader" column="request_header" />
|
||||||
|
<result property="requestBody" column="request_body" />
|
||||||
<result property="responseHeader" column="response_header" />
|
<result property="responseHeader" column="response_header" />
|
||||||
<result property="responseBody" column="response_body" />
|
<result property="responseBody" column="response_body" />
|
||||||
<result property="sqlResult" column="sql_result" />
|
<result property="sqlResult" column="sql_result" />
|
||||||
@@ -21,7 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectTestCaseResultVo">
|
<sql id="selectTestCaseResultVo">
|
||||||
select id, case_id, step_id, response_header, response_body, sql_result, polling_count, loop_count, assignment, assertion, use_time, execute_time, status from test_case_result
|
select id, case_id, step_id, request_header, request_body, response_header, response_body, sql_result, polling_count, loop_count, assignment, assertion, use_time, execute_time, status from test_case_result
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="selectTestCaseResultList" parameterType="TestCaseResult" resultMap="TestCaseResultResult">
|
<select id="selectTestCaseResultList" parameterType="TestCaseResult" resultMap="TestCaseResultResult">
|
||||||
@@ -29,6 +31,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<where>
|
<where>
|
||||||
<if test="caseId != null "> and case_id = #{caseId}</if>
|
<if test="caseId != null "> and case_id = #{caseId}</if>
|
||||||
<if test="stepId != null "> and step_id = #{stepId}</if>
|
<if test="stepId != null "> and step_id = #{stepId}</if>
|
||||||
|
<if test="requestHeader != null and requestHeader != ''"> and request_header = #{requestHeader}</if>
|
||||||
|
<if test="requestBody != null and requestBody != ''"> and request_body = #{requestBody}</if>
|
||||||
<if test="responseHeader != null and responseHeader != ''"> and response_header = #{responseHeader}</if>
|
<if test="responseHeader != null and responseHeader != ''"> and response_header = #{responseHeader}</if>
|
||||||
<if test="responseBody != null and responseBody != ''"> and response_body = #{responseBody}</if>
|
<if test="responseBody != null and responseBody != ''"> and response_body = #{responseBody}</if>
|
||||||
<if test="sqlResult != null and sqlResult != ''"> and sql_result = #{sqlResult}</if>
|
<if test="sqlResult != null and sqlResult != ''"> and sql_result = #{sqlResult}</if>
|
||||||
@@ -52,6 +56,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
<if test="caseId != null">case_id,</if>
|
<if test="caseId != null">case_id,</if>
|
||||||
<if test="stepId != null">step_id,</if>
|
<if test="stepId != null">step_id,</if>
|
||||||
|
<if test="requestHeader != null">request_header,</if>
|
||||||
|
<if test="requestBody != null">request_body,</if>
|
||||||
<if test="responseHeader != null">response_header,</if>
|
<if test="responseHeader != null">response_header,</if>
|
||||||
<if test="responseBody != null">response_body,</if>
|
<if test="responseBody != null">response_body,</if>
|
||||||
<if test="sqlResult != null">sql_result,</if>
|
<if test="sqlResult != null">sql_result,</if>
|
||||||
@@ -66,6 +72,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="caseId != null">#{caseId},</if>
|
<if test="caseId != null">#{caseId},</if>
|
||||||
<if test="stepId != null">#{stepId},</if>
|
<if test="stepId != null">#{stepId},</if>
|
||||||
|
<if test="requestHeader != null">#{requestHeader},</if>
|
||||||
|
<if test="requestBody != null">#{requestBody},</if>
|
||||||
<if test="responseHeader != null">#{responseHeader},</if>
|
<if test="responseHeader != null">#{responseHeader},</if>
|
||||||
<if test="responseBody != null">#{responseBody},</if>
|
<if test="responseBody != null">#{responseBody},</if>
|
||||||
<if test="sqlResult != null">#{sqlResult},</if>
|
<if test="sqlResult != null">#{sqlResult},</if>
|
||||||
@@ -84,6 +92,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<trim prefix="SET" suffixOverrides=",">
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
<if test="caseId != null">case_id = #{caseId},</if>
|
<if test="caseId != null">case_id = #{caseId},</if>
|
||||||
<if test="stepId != null">step_id = #{stepId},</if>
|
<if test="stepId != null">step_id = #{stepId},</if>
|
||||||
|
<if test="requestHeader != null">request_header = #{requestHeader},</if>
|
||||||
|
<if test="requestBody != null">request_body = #{requestBody},</if>
|
||||||
<if test="responseHeader != null">response_header = #{responseHeader},</if>
|
<if test="responseHeader != null">response_header = #{responseHeader},</if>
|
||||||
<if test="responseBody != null">response_body = #{responseBody},</if>
|
<if test="responseBody != null">response_body = #{responseBody},</if>
|
||||||
<if test="sqlResult != null">sql_result = #{sqlResult},</if>
|
<if test="sqlResult != null">sql_result = #{sqlResult},</if>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
<div style="margin-bottom:20px;">
|
<div style="margin-bottom:20px;">
|
||||||
<el-dropdown trigger="click" @command="handleAdd">
|
<el-dropdown trigger="click" @command="handleAdd">
|
||||||
<el-button type="primary" plain icon="el-icon-plus" size="mini">添加步骤</el-button>
|
<el-button type="primary" plain icon="el-icon-plus" size="mini">添加步骤</el-button>
|
||||||
|
<el-button type="primary" plain icon="el-icon-caret-right" size="mini" @click="handleRun(id)">调试</el-button>
|
||||||
<el-dropdown-menu slot="dropdown">
|
<el-dropdown-menu slot="dropdown">
|
||||||
<el-dropdown-item v-for="dict in dict.type.step_type" :command="dict.value" :key="dict.value">{{ dict.label }}</el-dropdown-item>
|
<el-dropdown-item v-for="dict in dict.type.step_type" :command="dict.value" :key="dict.value">{{ dict.label }}</el-dropdown-item>
|
||||||
</el-dropdown-menu>
|
</el-dropdown-menu>
|
||||||
@@ -39,6 +40,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import draggable from "vuedraggable";
|
import draggable from "vuedraggable";
|
||||||
|
import {runCase} from "@/api/test/case";
|
||||||
import {listCaseStep, updateCaseStep} from "@/api/test/caseStep";
|
import {listCaseStep, updateCaseStep} from "@/api/test/caseStep";
|
||||||
import page1 from "./page1.vue"
|
import page1 from "./page1.vue"
|
||||||
import page2 from "./page2.vue"
|
import page2 from "./page2.vue"
|
||||||
@@ -52,6 +54,7 @@ export default {
|
|||||||
components: {draggable, page1, page2, page3, page4},
|
components: {draggable, page1, page2, page3, page4},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
id: '',
|
||||||
loading: false,
|
loading: false,
|
||||||
activeName: null,
|
activeName: null,
|
||||||
list: [],
|
list: [],
|
||||||
@@ -70,6 +73,7 @@ export default {
|
|||||||
listCaseStep({caseId: this.$route.query.id}).then(res => {
|
listCaseStep({caseId: this.$route.query.id}).then(res => {
|
||||||
this.list = [];
|
this.list = [];
|
||||||
res.data.forEach(item => {
|
res.data.forEach(item => {
|
||||||
|
this.id = item.caseId;
|
||||||
let p = {
|
let p = {
|
||||||
...item,
|
...item,
|
||||||
assertion: item.assertion ? JSON.parse(item.assertion) : [],
|
assertion: item.assertion ? JSON.parse(item.assertion) : [],
|
||||||
@@ -104,6 +108,13 @@ export default {
|
|||||||
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
handleRun(id) {
|
||||||
|
this.$modal.confirm('是否确认执行用例?').then(function () {
|
||||||
|
return runCase(id);
|
||||||
|
}).then(() => {
|
||||||
|
this.$modal.msgSuccess("执行成功");
|
||||||
|
});
|
||||||
|
},
|
||||||
// 拖拽结束后更新排序值
|
// 拖拽结束后更新排序值
|
||||||
onDragEnd() {
|
onDragEnd() {
|
||||||
this.updateSortValues();
|
this.updateSortValues();
|
||||||
|
|||||||
Reference in New Issue
Block a user