fix(接口测试): 修复接口案例全屏优化遗漏的部分

--bug=1010475 --user=宋天阳 【接口测试】case全屏优化遗漏部分
https://www.tapd.cn/55049933/s/1107408
This commit is contained in:
song-tianyang 2022-02-22 14:06:33 +08:00 committed by xiaomeinvG
parent 69b57856cc
commit 89f9c2603e
5 changed files with 106 additions and 74 deletions

View File

@ -235,94 +235,96 @@ public class MockApiUtils {
if (StringUtils.isNotEmpty(response)) { if (StringUtils.isNotEmpty(response)) {
try { try {
JSONObject respObj = JSONObject.parseObject(response); JSONObject respObj = JSONObject.parseObject(response);
if (respObj.containsKey("body")) { if(respObj != null){
String returnStr = ""; if (respObj.containsKey("body")) {
JSONObject bodyObj = respObj.getJSONObject("body"); String returnStr = "";
if (bodyObj.containsKey("type")) { JSONObject bodyObj = respObj.getJSONObject("body");
String type = bodyObj.getString("type"); if (bodyObj.containsKey("type")) {
if (StringUtils.equals(type, "JSON")) { String type = bodyObj.getString("type");
//判断是否是JsonSchema if (StringUtils.equals(type, "JSON")) {
boolean isJsonSchema = false; //判断是否是JsonSchema
if (bodyObj.containsKey("format")) { boolean isJsonSchema = false;
String foramtValue = String.valueOf(bodyObj.get("format")); if (bodyObj.containsKey("format")) {
if (StringUtils.equals("JSON-SCHEMA", foramtValue)) { String foramtValue = String.valueOf(bodyObj.get("format"));
isJsonSchema = true; if (StringUtils.equals("JSON-SCHEMA", foramtValue)) {
isJsonSchema = true;
}
} }
} if (isJsonSchema) {
if (isJsonSchema) { if (bodyObj.containsKey("jsonSchema") && bodyObj.getJSONObject("jsonSchema").containsKey("properties")) {
if (bodyObj.containsKey("jsonSchema") && bodyObj.getJSONObject("jsonSchema").containsKey("properties")) { String bodyRetunStr = bodyObj.getJSONObject("jsonSchema").getJSONObject("properties").toJSONString();
String bodyRetunStr = bodyObj.getJSONObject("jsonSchema").getJSONObject("properties").toJSONString(); JSONObject bodyReturnObj = JSONObject.parseObject(bodyRetunStr);
JSONObject bodyReturnObj = JSONObject.parseObject(bodyRetunStr); JSONObject returnObj = MockApiUtils.parseJsonSchema(bodyReturnObj);
JSONObject returnObj = MockApiUtils.parseJsonSchema(bodyReturnObj); returnStr = returnObj.toJSONString();
returnStr = returnObj.toJSONString(); }
} else {
if (bodyObj.containsKey("raw")) {
returnStr = bodyObj.getString("raw");
}
} }
} else { } else if (StringUtils.equalsAny(type, "XML", "Raw")) {
if (bodyObj.containsKey("raw")) { if (bodyObj.containsKey("raw")) {
returnStr = bodyObj.getString("raw"); String raw = bodyObj.getString("raw");
returnStr = raw;
} }
} } else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) {
} else if (StringUtils.equalsAny(type, "XML", "Raw")) { Map<String, String> paramMap = new LinkedHashMap<>();
if (bodyObj.containsKey("raw")) { if (bodyObj.containsKey("kvs")) {
String raw = bodyObj.getString("raw"); JSONArray bodyParamArr = new JSONArray();
returnStr = raw; JSONArray kvsArr = bodyObj.getJSONArray("kvs");
} for (int i = 0; i < kvsArr.size(); i++) {
} else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) { JSONObject kv = kvsArr.getJSONObject(i);
Map<String, String> paramMap = new LinkedHashMap<>(); if (kv.containsKey("name")) {
if (bodyObj.containsKey("kvs")) { String values = kv.getString("value");
JSONArray bodyParamArr = new JSONArray(); if (StringUtils.isEmpty(values)) {
JSONArray kvsArr = bodyObj.getJSONArray("kvs"); values = "";
for (int i = 0; i < kvsArr.size(); i++) { } else {
JSONObject kv = kvsArr.getJSONObject(i); try {
if (kv.containsKey("name")) { values = values.startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(values) : values;
String values = kv.getString("value"); } catch (Exception e) {
if (StringUtils.isEmpty(values)) { }
values = "";
} else {
try {
values = values.startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(values) : values;
} catch (Exception e) {
} }
paramMap.put(kv.getString("name"), values);
} }
paramMap.put(kv.getString("name"), values); }
}
returnStr = JSONObject.toJSONString(paramMap);
}
}
responseDTO.setReturnData(returnStr);
}
if (respObj.containsKey("statusCode")) {
JSONArray statusCodeArray = respObj.getJSONArray("statusCode");
int code = 200;
if (statusCodeArray != null) {
for (int i = 0; i < statusCodeArray.size(); i++) {
JSONObject object = statusCodeArray.getJSONObject(i);
if (object.containsKey("name")) {
try {
code = Integer.parseInt(object.getString("name"));
break;
} catch (Exception e) {
LogUtil.error(e);
} }
} }
} }
returnStr = JSONObject.toJSONString(paramMap);
} }
responseDTO.setReturnCode(code);
} }
responseDTO.setReturnData(returnStr); if(respObj.containsKey("headers")){
} JSONArray jsonArray = respObj.getJSONArray("headers");
if (respObj.containsKey("statusCode")) { Map<String,String> headMap = new HashMap<>();
JSONArray statusCodeArray = respObj.getJSONArray("statusCode"); for(int i = 0; i < jsonArray.size(); i ++){
int code = 200; JSONObject headObj = jsonArray.getJSONObject(i);
if (statusCodeArray != null) { if(headObj.containsKey("name") && headObj.containsKey("value") && headObj.containsKey("enable")){
for (int i = 0; i < statusCodeArray.size(); i++) { boolean enable = headObj.getBoolean("enable");
JSONObject object = statusCodeArray.getJSONObject(i); if(enable){
if (object.containsKey("name")) { headMap.put(headObj.getString("name"),headObj.getString("value"));
try {
code = Integer.parseInt(object.getString("name"));
break;
} catch (Exception e) {
LogUtil.error(e);
} }
} }
} }
responseDTO.setHeaders(headMap);
} }
responseDTO.setReturnCode(code);
}
if(respObj.containsKey("headers")){
JSONArray jsonArray = respObj.getJSONArray("headers");
Map<String,String> headMap = new HashMap<>();
for(int i = 0; i < jsonArray.size(); i ++){
JSONObject headObj = jsonArray.getJSONObject(i);
if(headObj.containsKey("name") && headObj.containsKey("value") && headObj.containsKey("enable")){
boolean enable = headObj.getBoolean("enable");
if(enable){
headMap.put(headObj.getString("name"),headObj.getString("value"));
}
}
}
responseDTO.setHeaders(headMap);
} }
} catch (Exception e) { } catch (Exception e) {
MSException.throwException(e); MSException.throwException(e);

View File

@ -140,6 +140,11 @@ export default {
this.getApiTest(true); this.getApiTest(true);
this.visible = true; this.visible = true;
this.$store.state.currentApiCase = undefined; this.$store.state.currentApiCase = undefined;
//
this.$nextTick(() => {
this.$refs.testCaseDrawer.setfullScreen();
});
}, },
add(api) { add(api) {
this.api = api; this.api = api;
@ -169,6 +174,11 @@ export default {
this.condition = {components: API_CASE_CONFIGS}; this.condition = {components: API_CASE_CONFIGS};
this.sysAddition(apiCase); this.sysAddition(apiCase);
this.visible = true; this.visible = true;
//
this.$nextTick(() => {
this.$refs.testCaseDrawer.setfullScreen();
});
}, },
runTestCase(api, testCaseId) { runTestCase(api, testCaseId) {
if (api && testCaseId) { if (api && testCaseId) {
@ -195,6 +205,11 @@ export default {
this.api = api; this.api = api;
this.currentApi = api; this.currentApi = api;
this.addCase(); this.addCase();
//
this.$nextTick(() => {
this.$refs.testCaseDrawer.setfullScreen();
});
}, },
setEnvironment(environment) { setEnvironment(environment) {
this.environment = environment; this.environment = environment;

View File

@ -34,6 +34,7 @@ import MsDropdown from "@/business/components/common/components/MsDropdown";
import CustomFunctionRelate from "@/business/components/project/menu/function/CustomFunctionRelate"; import CustomFunctionRelate from "@/business/components/project/menu/function/CustomFunctionRelate";
import ApiFuncRelevance from "@/business/components/project/menu/function/ApiFuncRelevance"; import ApiFuncRelevance from "@/business/components/project/menu/function/ApiFuncRelevance";
import MockScriptNavMenu from "@/business/components/api/definition/components/mock/Components/MockScriptNavMenu"; import MockScriptNavMenu from "@/business/components/api/definition/components/mock/Components/MockScriptNavMenu";
import i18n from "@/i18n/i18n";
export default { export default {
name: "MockApiScriptEditor", name: "MockApiScriptEditor",
@ -112,6 +113,19 @@ export default {
] ]
}, },
{
title: i18n.t('project.code_segment.custom_value'),
children: [
{
title: i18n.t('api_test.request.processor.code_template_get_variable'),
value: 'vars.get("variable_name");',
},
{
title: i18n.t('api_test.request.processor.code_template_set_variable'),
value: 'vars.put("variable_name", "variable_value");',
},
]
},
{ {
title: this.$t('project.code_segment.code_segment'), title: this.$t('project.code_segment.code_segment'),
children: [ children: [

View File

@ -3,6 +3,7 @@
<el-card> <el-card>
<el-row> <el-row>
<el-col :span="1"> <el-col :span="1">
<span style="color: #f56c6c">*</span>
{{ $t('commons.name') }} {{ $t('commons.name') }}
</el-col> </el-col>
<el-col :span="9"> <el-col :span="9">

View File

@ -20,7 +20,7 @@
:screen-height="screenHeight" :screen-height="screenHeight"
@row-click="clickRow" @row-click="clickRow"
row-key="id" row-key="id"
operator-width="120px" operator-width="170px"
ref="table" ref="table"
> >