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