Skip to content

Commit

Permalink
fix(接口自动化): 修复场景调试无环境报错问题 #09e9b5b7
Browse files Browse the repository at this point in the history
--bug=1005268 --user=赵勇 【接口自动化】编辑场... https://www.tapd.cn/55049933/s/1026836
  • Loading branch information
fit2-zhao committed Jul 21, 2021
1 parent dd17584 commit 34811a9
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1393,9 +1393,11 @@ public String debugRun(RunDefinitionRequest request, List<MultipartFile> bodyFil
if (map != null) {
map.keySet().forEach(id -> {
ApiTestEnvironmentWithBLOBs environment = environmentService.get(map.get(id));
EnvironmentConfig env = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class);
env.setApiEnvironmentid(environment.getId());
envConfig.put(id, env);
if (environment != null && environment.getConfig() != null) {
EnvironmentConfig env = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class);
env.setApiEnvironmentid(environment.getId());
envConfig.put(id, env);
}
});
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,9 @@ export default {
.report-header {
font-size: 15px;
}
/deep/ .el-card__body{
padding: 0px;
}
.report-header a {
text-decoration: none;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
:allow-drop="allowDrop" @node-drag-end="allowDrag" @node-click="nodeClick" v-if="!loading" draggable ref="stepTree">
<span class="custom-tree-node father" slot-scope="{ node, data}" style="width: 96%">
<!-- 步骤组件-->
<ms-component-config :type="data.type" :scenario="data" :response="response" :currentScenario="currentScenario" :expandedNode="expandedNode"
<ms-component-config :message="message" :type="data.type" :scenario="data" :response="response" :currentScenario="currentScenario" :expandedNode="expandedNode"
:currentEnvironmentId="currentEnvironmentId" :node="node" :project-list="projectList" :env-map="projectEnvMap"
@remove="remove" @copyRow="copyRow" @suggestClick="suggestClick" @refReload="refReload" @openScenario="openScenario"/>
</span>
Expand Down Expand Up @@ -416,6 +416,7 @@ export default {
stopDebug: "",
isTop: false,
stepSize: 0,
message: "",
}
},
created() {
Expand Down Expand Up @@ -509,6 +510,7 @@ export default {
if (e.data) {
let data = JSON.parse(e.data);
this.formatResult(data);
this.message = getUUID();
if (data.end) {
this.removeReport();
this.debugLoading = false;
Expand Down Expand Up @@ -561,7 +563,7 @@ export default {
}
this.debugResult = resMap;
this.sort();
this.reload();
// this.reload();
this.reloadDebug = getUUID();
},
removeReport() {
Expand Down Expand Up @@ -709,74 +711,44 @@ export default {
this.isBtnHide = true;
this.$refs.scenarioApiRelevance.open();
},
recursiveSorting(arr, scenarioProjectId) {
for (let i in arr) {
arr[i].index = Number(i) + 1;
if (!arr[i].resourceId) {
arr[i].resourceId = getUUID();
sort(stepArray, scenarioProjectId) {
if (!stepArray) {
stepArray = this.scenarioDefinition;
}
for (let i in stepArray) {
stepArray[i].index = Number(i) + 1;
if (!stepArray[i].resourceId) {
stepArray[i].resourceId = getUUID();
}
if (arr[i].type === ELEMENT_TYPE.LoopController && arr[i].loopType === "LOOP_COUNT" && arr[i].hashTree && arr[i].hashTree.length > 1) {
arr[i].countController.proceed = true;
if (stepArray[i].type === ELEMENT_TYPE.LoopController
&& stepArray[i].loopType === "LOOP_COUNT"
&& stepArray[i].hashTree
&& stepArray[i].hashTree.length > 1) {
stepArray[i].countController.proceed = true;
}
if (!arr[i].projectId) {
if (!stepArray[i].projectId) {
// 如果自身没有ID并且场景有ID则赋值场景ID,否则赋值当前项目ID
arr[i].projectId = scenarioProjectId ? scenarioProjectId : this.projectId;
stepArray[i].projectId = scenarioProjectId ? scenarioProjectId : this.projectId;
} else {
const project = this.projectList.find(p => p.id === arr[i].projectId);
const project = this.projectList.find(p => p.id === stepArray[i].projectId);
if (!project) {
arr[i].projectId = scenarioProjectId ? scenarioProjectId : this.projectId;
stepArray[i].projectId = scenarioProjectId ? scenarioProjectId : this.projectId;
}
}
// 添加debug结果
let key = arr[i].resourceId;
let key = stepArray[i].resourceId;
if (this.debugResult && this.debugResult.get(key)) {
arr[i].requestResult = this.debugResult.get(key);
arr[i].result = null;
arr[i].debug = this.debug;
this.findNode(key, arr[i].requestResult[0].success);
stepArray[i].requestResult = this.debugResult.get(key);
stepArray[i].result = null;
stepArray[i].debug = this.debug;
this.findNode(key, stepArray[i].requestResult[0].success);
}
if (arr[i].hashTree && arr[i].hashTree.length > 0) {
this.stepSize += arr[i].hashTree.length;
this.recursiveSorting(arr[i].hashTree, arr[i].projectId);
if (stepArray[i].hashTree && stepArray[i].hashTree.length > 0) {
this.stepSize += stepArray[i].hashTree.length;
this.sort(stepArray[i].hashTree, stepArray[i].projectId);
}
}
},
sort() {
this.stepSize = this.scenarioDefinition.length;
for (let i in this.scenarioDefinition) {
// 排序
this.scenarioDefinition[i].index = Number(i) + 1;
if (!this.scenarioDefinition[i].resourceId) {
this.scenarioDefinition[i].resourceId = getUUID();
}
// 设置循环控制
if (this.scenarioDefinition[i].type === ELEMENT_TYPE.LoopController && this.scenarioDefinition[i].hashTree
&& this.scenarioDefinition[i].hashTree.length > 1) {
this.scenarioDefinition[i].countController.proceed = true;
}
// 设置项目ID
if (!this.scenarioDefinition[i].projectId) {
this.scenarioDefinition[i].projectId = this.projectId;
} else {
const project = this.projectList.find(p => p.id === this.scenarioDefinition[i].projectId);
if (!project) {
this.scenarioDefinition[i].projectId = this.projectId;
}
}
if (this.scenarioDefinition[i].hashTree !== undefined && this.scenarioDefinition[i].hashTree.length > 0) {
this.stepSize += this.scenarioDefinition[i].hashTree.length;
this.recursiveSorting(this.scenarioDefinition[i].hashTree, this.scenarioDefinition[i].projectId);
}
// 添加debug结果
if (this.debugResult && this.debugResult.get(this.scenarioDefinition[i].resourceId)) {
this.scenarioDefinition[i].result = null;
this.scenarioDefinition[i].requestResult = this.debugResult.get(this.scenarioDefinition[i].resourceId);
this.scenarioDefinition[i].debug = this.debug;
}
}
},
addCustomizeApi(request) {
this.customizeVisible = false;
request.enable === undefined ? request.enable = true : request.enable;
Expand Down Expand Up @@ -970,7 +942,6 @@ export default {
});
}
},
checkDataIsCopy() {
// 如果是复制按钮创建的场景,直接进行保存
if (this.currentScenario.copy) {
Expand Down Expand Up @@ -1148,8 +1119,7 @@ export default {
this.currentScenario.apiScenarioModuleId = this.currentModule.id;
}
this.currentScenario.projectId = this.projectId;
}
,
},
runRefresh() {
if (!this.debug) {
this.debugVisible = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<el-tag size="mini" class="ms-tag" v-if="request.referenced ==='REF'">{{ $t('api_test.scenario.reference') }}</el-tag>
</template>
<template v-slot:debugStepCode>
<span class="ms-step-debug-code" :class="request.requestResult[0].success?'ms-req-success':'ms-req-error'" v-if="request.debug && request.requestResult[0] && request.requestResult[0].responseResult">
<span class="ms-step-debug-code" :class="request.requestResult[0].success?'ms-req-success':'ms-req-error'" v-if="!loading && request.debug && request.requestResult[0] && request.requestResult[0].responseResult">
{{ request.requestResult[0].success ? 'success' : 'error' }}
</span>
</template>
Expand Down Expand Up @@ -133,7 +133,8 @@ export default {
currentEnvironmentId: String,
projectList: Array,
expandedNode: Array,
envMap: Map
envMap: Map,
message: String
},
components: {
TemplateComponent,
Expand Down Expand Up @@ -188,6 +189,9 @@ export default {
envMap() {
this.getEnvironments();
},
message() {
this.reload();
},
},
computed: {
displayColor() {
Expand Down Expand Up @@ -264,7 +268,7 @@ export default {
if (this.request.protocol === 'SQL' || this.request.type === 'JDBCSampler') {
if (this.environment && this.environment.config) {
let config = JSON.parse(this.environment.config);
if(config && config.databaseConfigs) {
if (config && config.databaseConfigs) {
config.databaseConfigs.forEach(item => {
databaseConfigsOptions.push(item);
});
Expand Down Expand Up @@ -337,27 +341,18 @@ export default {
})
}
},
recursiveSorting(arr) {
sort(arr) {
if (!arr) {
arr = this.request.hashTree;
}
for (let i in arr) {
arr[i].disabled = true;
arr[i].index = Number(i) + 1;
if (!arr[i].resourceId) {
arr[i].resourceId = getUUID();
}
if (arr[i].hashTree != undefined && arr[i].hashTree.length > 0) {
this.recursiveSorting(arr[i].hashTree);
}
}
},
sort() {
for (let i in this.request.hashTree) {
if (!this.request.hashTree[i].resourceId) {
this.request.hashTree[i].resourceId = getUUID();
}
this.request.hashTree[i].disabled = true;
this.request.hashTree[i].index = Number(i) + 1;
if (this.request.hashTree[i].hashTree != undefined && this.request.hashTree[i].hashTree.length > 0) {
this.recursiveSorting(this.request.hashTree[i].hashTree);
this.sort(arr[i].hashTree);
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<span class="ms-tag">{{ getProjectName(scenario.projectId) }}</span>
</template>
<template v-slot:debugStepCode>
<span class="ms-step-debug-code" :class="node.data.code ==='error'?'ms-req-error':'ms-req-success'" v-if="node.data.debug">
<span class="ms-step-debug-code" :class="node.data.code ==='error'?'ms-req-error':'ms-req-success'" v-if="!loading && node.data.debug">
{{ getCode() }}
</span>
</template>
Expand All @@ -43,6 +43,7 @@ export default {
name: "ApiScenarioComponent",
props: {
scenario: {},
message: String,
node: {},
isMax: {
type: Boolean,
Expand All @@ -59,7 +60,11 @@ export default {
currentEnvironmentId: String,
projectList: Array
},
watch: {},
watch: {
message() {
this.reload();
},
},
created() {
if (!this.scenario.projectId) {
this.scenario.projectId = getCurrentProjectID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<component v-bind:is="component" :isMax="isMax" :show-btn="showBtn" :expandedNode="expandedNode"
:scenario="scenario" :controller="scenario" :timer="scenario" :assertions="scenario" :extract="scenario" :jsr223-processor="scenario" :request="scenario" :currentScenario="currentScenario" :currentEnvironmentId="currentEnvironmentId" :node="node"
:draggable="draggable" :title="title" :color="titleColor" :background-color="backgroundColor" @suggestClick="suggestClick(node)" :response="response"
@remove="remove" @copyRow="copyRow" @refReload="refReload" @openScenario="openScenario" :project-list="projectList" :env-map="envMap"/>
@remove="remove" @copyRow="copyRow" @refReload="refReload" @openScenario="openScenario" :project-list="projectList" :env-map="envMap" :message="message"/>
</keep-alive>
</div>
</template>
Expand All @@ -28,6 +28,7 @@
components: {MsConstantTimer, MsIfController, MsTransactionController, MsJsr233Processor, MsApiAssertions, MsApiExtract, MsApiComponent, MsLoopController, MsApiScenarioComponent, MsJdbcProcessor,JmeterElementComponent},
props: {
type: String,
message: String,
scenario: {},
draggable: {
type: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</template>

<template v-slot:debugStepCode>
<span class="ms-step-debug-code" :class="node.data.code ==='error'?'ms-req-error':'ms-req-success'" v-if="node.data.debug">
<span class="ms-step-debug-code" :class="node.data.code ==='error'?'ms-req-error':'ms-req-success'" v-if="!loading && node.data.debug">
{{ getCode() }}
</span>
</template>
Expand All @@ -43,6 +43,7 @@
props: {
controller: {},
node: {},
message: String,
isMax: {
type: Boolean,
default: false,
Expand All @@ -59,6 +60,7 @@
},
data() {
return {
loading: false,
operators: {
EQ: {
label: "commons.adv_search.operators.equals",
Expand Down Expand Up @@ -95,7 +97,18 @@
}
}
},
watch: {
message() {
this.reload();
},
},
methods: {
reload() {
this.loading = true
this.$nextTick(() => {
this.loading = false
})
},
getCode() {
if (this.node && this.node.data.debug) {
if (this.node.data.code && this.node.data.code === 'error') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</div>

<template v-slot:debugStepCode>
<span class="ms-step-debug-code" :class="node.data.code ==='error'?'ms-req-error':'ms-req-success'" v-if="node.data.debug">
<span class="ms-step-debug-code" :class="node.data.code ==='error'?'ms-req-error':'ms-req-success'" v-if="!loading && node.data.debug">
{{ getCode() }}
</span>
</template>
Expand All @@ -38,6 +38,7 @@
type: Boolean,
default: false,
},
message: String,
isReadOnly: {
type: Boolean,
default:
Expand All @@ -59,7 +60,23 @@
defBackgroundColor: {type: String, default: "#F4F4FF"},
node: {},
},
data() {
return {
loading: false,
}
},
watch: {
message() {
this.reload();
},
},
methods: {
reload() {
this.loading = true
this.$nextTick(() => {
this.loading = false
})
},
getCode() {
if (this.node && this.node.data.debug) {
if (this.node.data.code && this.node.data.code === 'error') {
Expand Down
Loading

0 comments on commit 34811a9

Please sign in to comment.