refactor(接口测试): 引用设置优化

This commit is contained in:
fit2-zhao 2022-02-17 19:43:23 +08:00 committed by fit2-zhao
parent 45651d1973
commit 2e44835dcb
7 changed files with 120 additions and 64 deletions

View File

@ -201,7 +201,9 @@ public class ApiCaseExecuteService {
report.setName(caseWithBLOBs.getName()); report.setName(caseWithBLOBs.getName());
report.setProjectId(caseWithBLOBs.getProjectId()); report.setProjectId(caseWithBLOBs.getProjectId());
report.setVersionId(caseWithBLOBs.getVersionId()); report.setVersionId(caseWithBLOBs.getVersionId());
report.setIntegratedReportId(finalSerialReportId); if (StringUtils.isNotEmpty(finalSerialReportId)) {
report.setIntegratedReportId(finalSerialReportId);
}
executeQueue.put(caseWithBLOBs.getId(), report); executeQueue.put(caseWithBLOBs.getId(), report);
responseDTOS.add(new MsExecResponseDTO(caseWithBLOBs.getId(), report.getId(), request.getTriggerMode())); responseDTOS.add(new MsExecResponseDTO(caseWithBLOBs.getId(), report.getId(), request.getTriggerMode()));
}); });

View File

@ -701,13 +701,15 @@ public class ApiAutomationService {
} else { } else {
String scenarioId = request.getId(); String scenarioId = request.getId();
ApiScenarioWithBLOBs apiScenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(scenarioId); ApiScenarioWithBLOBs apiScenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(scenarioId);
String environmentType = apiScenarioWithBLOBs.getEnvironmentType(); if (apiScenarioWithBLOBs != null) {
String environmentGroupId = apiScenarioWithBLOBs.getEnvironmentGroupId(); String environmentType = apiScenarioWithBLOBs.getEnvironmentType();
String environmentJson = apiScenarioWithBLOBs.getEnvironmentJson(); String environmentGroupId = apiScenarioWithBLOBs.getEnvironmentGroupId();
if (StringUtils.equals(environmentType, EnvironmentType.GROUP.name())) { String environmentJson = apiScenarioWithBLOBs.getEnvironmentJson();
environmentMap = environmentGroupProjectService.getEnvMap(environmentGroupId); if (StringUtils.equals(environmentType, EnvironmentType.GROUP.name())) {
} else if (StringUtils.equals(environmentType, EnvironmentType.JSON.name())) { environmentMap = environmentGroupProjectService.getEnvMap(environmentGroupId);
environmentMap = JSON.parseObject(environmentJson, Map.class); } else if (StringUtils.equals(environmentType, EnvironmentType.JSON.name())) {
environmentMap = JSON.parseObject(environmentJson, Map.class);
}
} }
} }

View File

@ -127,7 +127,7 @@
'Saved' as execute_type, 'Saved' as execute_type,
'API_INDEPENDENT' as report_type 'API_INDEPENDENT' as report_type
from api_definition_exec_result a_r from api_definition_exec_result a_r
where a_r.integrated_report_id is null where a_r.integrated_report_id is null or a_r.integrated_report_id = 'null'
) r ) r
<where> <where>
<if test="request.combine != null"> <if test="request.combine != null">
@ -211,7 +211,7 @@
'Saved' as execute_type, 'Saved' as execute_type,
'API_INDEPENDENT' as report_type 'API_INDEPENDENT' as report_type
from api_definition_exec_result a_r from api_definition_exec_result a_r
where a_r.integrated_report_id is null where a_r.integrated_report_id is null or a_r.integrated_report_id = 'null'
) r ) r
<where> <where>
<if test="request.combine != null"> <if test="request.combine != null">

View File

@ -33,7 +33,7 @@
<if test="request.executor != null and request.executor != ''"> <if test="request.executor != null and request.executor != ''">
and t.user_id = #{request.executor} and t.user_id = #{request.executor}
</if> </if>
and t.integrated_report_id is null and (t.integrated_report_id is null or t.integrated_report_id = 'null')
) )
UNION ALL UNION ALL
(select t.id,t.name,'PERFORMANCE' as executionModule, ifnull(t2.name,'LOCAL') as actuator, t1.`name` as executor,t.create_time as executionTime, t.trigger_mode as triggerMode ,t.`status` as executionStatus (select t.id,t.name,'PERFORMANCE' as executionModule, ifnull(t2.name,'LOCAL') as actuator, t1.`name` as executor,t.create_time as executionTime, t.trigger_mode as triggerMode ,t.`status` as executionStatus
@ -80,7 +80,7 @@
from api_definition_exec_result t left join `user` t1 ON t.user_id = t1.id left join test_resource_pool t2 on t.actuator = t2.id from api_definition_exec_result t left join `user` t1 ON t.user_id = t1.id left join test_resource_pool t2 on t.actuator = t2.id
left join api_definition t3 on t.resource_id = t3.id left join api_test_case t4 on t4.id = t.resource_id left join api_definition t3 on t.resource_id = t3.id left join api_test_case t4 on t4.id = t.resource_id
left join test_plan_api_case t5 on t.resource_id = t5.id left join test_plan t6 on t5.test_plan_id = t6.id left join test_plan_api_case t5 on t.resource_id = t5.id left join test_plan t6 on t5.test_plan_id = t6.id
where to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) and t.integrated_report_id is null and (t3.project_id =#{request.projectId} OR t4.project_id =#{request.projectId} OR t6.project_id = #{request.projectId}) and t.status not in ("saved","completed","success","error","STOP") where to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) and (t.integrated_report_id is null t.integrated_report_id='null') and (t3.project_id =#{request.projectId} OR t4.project_id =#{request.projectId} OR t6.project_id = #{request.projectId}) and t.status not in ("saved","completed","success","error","STOP")
) )
UNION ALL UNION ALL
(select t.id,t.create_time as executionTime (select t.id,t.create_time as executionTime

View File

@ -10,23 +10,22 @@
</slot> </slot>
<span> <span>
<slot name="headerLeft"> <slot name="headerLeft">
<i class="icon el-icon-arrow-right" :class="{'is-active': data.active}" @click="active(data)" v-if="data.type!='scenario' && !isMax " @click.stop/> <i class="icon el-icon-arrow-right" :class="{'is-active': data.active}" @click="active(data)" v-if="data.type!='scenario' && !isMax " @click.stop/>
<span @click.stop v-if="isShowInput && isShowNameInput"> <span @click.stop v-if="isShowInput && isShowNameInput">
<el-input :draggable="draggable" size="mini" v-model="data.name" class="name-input" @focus="active(data)" <el-input :draggable="draggable" size="mini" v-model="data.name" class="name-input" @focus="active(data)"
@blur="isShowInput = false" :placeholder="$t('commons.input_name')" ref="nameEdit" :disabled="data.disabled"/> @blur="isShowInput = false" :placeholder="$t('commons.input_name')" ref="nameEdit" :disabled="data.disabled"/>
</span> </span>
<span :class="showVersion?'scenario-unscroll':'scenario-version'" id="moveout" @mouseenter="enter($event)" @mouseleave="leave($event)" v-else> <span :class="showVersion?'scenario-unscroll':'scenario-version'" id="moveout" @mouseenter="enter($event)" @mouseleave="leave($event)" v-else>
<i class="el-icon-edit" style="cursor:pointer;" @click="editName" <i class="el-icon-edit" style="cursor:pointer;" @click="editName"
v-if="data.referenced!='REF' && !data.disabled"/> v-if="data.referenced!='REF' && !data.disabled"/>
<el-tooltip placement="top" :content="data.name"> <el-tooltip placement="top" :content="data.name">
<span>{{ data.name }}</span> <span>{{ data.name }}</span>
</el-tooltip> </el-tooltip>
<el-tag size="mini" v-if="data.method && !data.pluginId" style="margin-left: 1rem">{{ getMethod() }}</el-tag> <el-tag size="mini" v-if="data.method && !data.pluginId" style="margin-left: 1rem">{{ getMethod() }}</el-tag>
<slot name = "afterTitle"/> <slot name="afterTitle"/>
</span> </span>
</slot> </slot>
<slot name="scenarioEnable"/>
</span> </span>
<div v-if="!ifFromVariableAdvance" class="header-right" @click.stop> <div v-if="!ifFromVariableAdvance" class="header-right" @click.stop>
@ -39,7 +38,15 @@
<el-tooltip content="Copy" placement="top" v-if="showVersion"> <el-tooltip content="Copy" placement="top" v-if="showVersion">
<el-button size="mini" icon="el-icon-copy-document" circle @click="copyRow" style="padding: 5px" :disabled="data.disabled && !data.root"/> <el-button size="mini" icon="el-icon-copy-document" circle @click="copyRow" style="padding: 5px" :disabled="data.disabled && !data.root"/>
</el-tooltip> </el-tooltip>
<step-extend-btns style="display: contents" :data="data" @copy="copyRow" @remove="remove" @openScenario="openScenario" v-if="showBtn && (!data.disabled || data.root)&&showVersion"/> <step-extend-btns style="display: contents"
:data="data"
:environmentType="environmentType"
:environmentGroupId="environmentGroupId"
:envMap="envMap"
@copy="copyRow"
@remove="remove"
@openScenario="openScenario"
v-if="showBtn && (!data.disabled || data.root) &&showVersion"/>
</div> </div>
</div> </div>
@ -66,6 +73,7 @@
<script> <script>
import StepExtendBtns from "../component/StepExtendBtns"; import StepExtendBtns from "../component/StepExtendBtns";
import {STEP} from "../Setting"; import {STEP} from "../Setting";
export default { export default {
name: "ApiBaseComponent", name: "ApiBaseComponent",
components: {StepExtendBtns}, components: {StepExtendBtns},
@ -124,7 +132,10 @@ export default {
ifFromVariableAdvance: { ifFromVariableAdvance: {
type: Boolean, type: Boolean,
default: false, default: false,
} },
environmentType: String,
environmentGroupId: String,
envMap: Map,
}, },
watch: { watch: {
'$store.state.selectStep': function () { '$store.state.selectStep': function () {
@ -178,18 +189,18 @@ export default {
this.$refs.nameEdit.focus(); this.$refs.nameEdit.focus();
}); });
}, },
enter($event){ enter($event) {
if(this.showVersion){ if (this.showVersion) {
$event.currentTarget.className="scenario-name" $event.currentTarget.className = "scenario-name"
}else{ } else {
$event.currentTarget.className="scenario-version" $event.currentTarget.className = "scenario-version"
} }
}, },
leave($event){ leave($event) {
if(this.showVersion){ if (this.showVersion) {
$event.currentTarget.className="scenario-unscroll" $event.currentTarget.className = "scenario-unscroll"
}else{ } else {
$event.currentTarget.className="scenario-version" $event.currentTarget.className = "scenario-version"
} }
} }
@ -240,7 +251,8 @@ export default {
white-space: nowrap; white-space: nowrap;
width: 140px; width: 140px;
} }
.scenario-version{
.scenario-version {
display: inline-block; display: inline-block;
font-size: 13px; font-size: 13px;
margin: 0 5px; margin: 0 5px;
@ -254,30 +266,31 @@ export default {
width: calc(100% - 23rem); width: calc(100% - 23rem);
height: auto; height: auto;
} }
.scenario-version::-webkit-scrollbar
{ .scenario-version::-webkit-scrollbar {
background-color: #fff; background-color: #fff;
} }
/*定义滚动条轨道 内阴影+圆角*/ /*定义滚动条轨道 内阴影+圆角*/
.scenario-version::-webkit-scrollbar-track .scenario-version::-webkit-scrollbar-track {
{
-webkit-box-shadow: inset 0 0 6px #fff; -webkit-box-shadow: inset 0 0 6px #fff;
border-radius: 1px; border-radius: 1px;
background-color: #ffffff; background-color: #ffffff;
} }
/*定义滑块 内阴影+圆角*/ /*定义滑块 内阴影+圆角*/
.scenario-version::-webkit-scrollbar-thumb .scenario-version::-webkit-scrollbar-thumb {
{
border-radius: 1px; border-radius: 1px;
-webkit-box-shadow: inset 0 0 6px #fff; -webkit-box-shadow: inset 0 0 6px #fff;
background-color: #783887; background-color: #783887;
} }
.scenario-version::-webkit-scrollbar { .scenario-version::-webkit-scrollbar {
/* width: 0px; */ /* width: 0px; */
height: 3px; height: 3px;
position: fixed; position: fixed;
} }
.scenario-name { .scenario-name {
display: inline-block; display: inline-block;
font-size: 13px; font-size: 13px;
@ -296,32 +309,32 @@ export default {
scrollbar-track-color: transparent; scrollbar-track-color: transparent;
-ms-scrollbar-track-color: transparent; -ms-scrollbar-track-color: transparent;
} }
.scenario-name::-webkit-scrollbar
{ .scenario-name::-webkit-scrollbar {
background-color: #fff; background-color: #fff;
} }
/*定义滚动条轨道 内阴影+圆角*/ /*定义滚动条轨道 内阴影+圆角*/
.scenario-name::-webkit-scrollbar-track .scenario-name::-webkit-scrollbar-track {
{
-webkit-box-shadow: inset 0 0 6px #fff; -webkit-box-shadow: inset 0 0 6px #fff;
border-radius: 1px; border-radius: 1px;
background-color: #ffffff; background-color: #ffffff;
} }
/*定义滑块 内阴影+圆角*/ /*定义滑块 内阴影+圆角*/
.scenario-name::-webkit-scrollbar-thumb .scenario-name::-webkit-scrollbar-thumb {
{
border-radius: 1px; border-radius: 1px;
-webkit-box-shadow: inset 0 0 6px #fff; -webkit-box-shadow: inset 0 0 6px #fff;
background-color: #783887; background-color: #783887;
} }
.scenario-name::-webkit-scrollbar { .scenario-name::-webkit-scrollbar {
/* width: 0px; */ /* width: 0px; */
height: 3px; height: 3px;
position: fixed; position: fixed;
} }
.scenario-unscroll{ .scenario-unscroll {
display: inline-block; display: inline-block;
font-size: 13px; font-size: 13px;
margin: 0 5px; margin: 0 5px;

View File

@ -15,6 +15,9 @@
color="#606266" color="#606266"
background-color="#F4F4F5" background-color="#F4F4F5"
:if-from-variable-advance="ifFromVariableAdvance" :if-from-variable-advance="ifFromVariableAdvance"
:environmentType="environmentType"
:environmentGroupId="environmentGroupId"
:envMap="envMap"
:title="$t('commons.scenario')"> :title="$t('commons.scenario')">
<template v-slot:afterTitle v-if="isSameSpace"> <template v-slot:afterTitle v-if="isSameSpace">
@ -42,26 +45,6 @@
{{ getCode() }} {{ getCode() }}
</span> </span>
</template> </template>
<template v-slot:scenarioEnable v-if="!ifFromVariableAdvance">
<el-popover
placement="bottom"
width="200"
trigger="click">
<ul>
<el-tooltip :content="$t('commons.enable_scene_info')" placement="top">-->
<el-checkbox v-model="scenario.environmentEnable" @change="checkEnv" :disabled="scenario.disabled">
{{ $t('commons.enable_scene') }}
</el-checkbox>
</el-tooltip>
<el-checkbox v-model="scenario.variableEnable" :disabled="scenario.disabled">
{{ $t('commons.variable_scene') }}
</el-checkbox>
</ul>
<span class="el-dropdown-link ms-test-running" slot="reference" @click.stop>
{{ $t('commons.reference_settings') }}
</span>
</el-popover>
</template>
<template v-slot:button v-if="!ifFromVariableAdvance"> <template v-slot:button v-if="!ifFromVariableAdvance">
<el-tooltip :content="$t('api_test.run')" placement="top" v-if="!scenario.run"> <el-tooltip :content="$t('api_test.run')" placement="top" v-if="!scenario.run">
<el-button :disabled="!scenario.enable" @click="run" icon="el-icon-video-play" style="padding: 5px" class="ms-btn" size="mini" circle/> <el-button :disabled="!scenario.enable" @click="run" icon="el-icon-video-play" style="padding: 5px" class="ms-btn" size="mini" circle/>

View File

@ -15,10 +15,30 @@
<el-dropdown-item command="saveAs" v-if="allSamplers.indexOf(data.type)!=-1 && (data.referenced===undefined || data.referenced ==='Created' )"> <el-dropdown-item command="saveAs" v-if="allSamplers.indexOf(data.type)!=-1 && (data.referenced===undefined || data.referenced ==='Created' )">
{{ this.$t("api_test.automation.save_as_api") }} {{ this.$t("api_test.automation.save_as_api") }}
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item command="setScenario" v-if="data.type==='scenario'">
{{ $t('commons.reference_settings') }}
</el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</el-dropdown> </el-dropdown>
<ms-variable-list ref="scenarioParameters" @setVariables="setVariables"/> <ms-variable-list ref="scenarioParameters" @setVariables="setVariables"/>
<ms-add-basis-api :currentProtocol="currentProtocol" ref="api"/> <ms-add-basis-api :currentProtocol="currentProtocol" ref="api"/>
<el-dialog
:title="$t('commons.reference_settings')"
:visible.sync="dialogVisible" width="400px">
<ul>
<el-tooltip :content="$t('commons.enable_scene_info')" placement="top">-->
<el-checkbox v-model="data.environmentEnable" @change="checkEnv" :disabled="data.disabled">
{{ $t('commons.enable_scene') }}
</el-checkbox>
</el-tooltip>
<el-checkbox v-model="data.variableEnable" :disabled="data.disabled">
{{ $t('commons.variable_scene') }}
</el-checkbox>
</ul>
</el-dialog>
</div> </div>
</template> </template>
@ -26,19 +46,23 @@
import {STEP} from "../Setting"; import {STEP} from "../Setting";
import MsVariableList from "../variable/VariableList"; import MsVariableList from "../variable/VariableList";
import MsAddBasisApi from "../api/AddBasisApi"; import MsAddBasisApi from "../api/AddBasisApi";
import {getCurrentProjectID, getUUID} from "@/common/js/utils"; import {getCurrentProjectID, getUUID, strMapToObj} from "@/common/js/utils";
export default { export default {
name: "StepExtendBtns", name: "StepExtendBtns",
components: {STEP, MsVariableList, MsAddBasisApi}, components: {STEP, MsVariableList, MsAddBasisApi},
props: { props: {
data: Object, data: Object,
environmentType: String,
environmentGroupId: String,
envMap: Map,
}, },
data() { data() {
return { return {
allSamplers: [], allSamplers: [],
currentProtocol: "HTTP", currentProtocol: "HTTP",
filter: new STEP, filter: new STEP,
dialogVisible: false,
} }
}, },
mounted() { mounted() {
@ -62,11 +86,17 @@ export default {
case "saveAs": case "saveAs":
this.saveAsApi(); this.saveAsApi();
break; break;
case "setScenario":
this.setScenario();
break;
} }
}, },
setVariables(v,h){ setVariables(v, h) {
this.data.variables = v; this.data.variables = v;
}, },
setScenario() {
this.dialogVisible = true;
},
getScenario() { getScenario() {
this.result = this.$get("/api/automation/getApiScenario/" + this.data.id, response => { this.result = this.$get("/api/automation/getApiScenario/" + this.data.id, response => {
if (response.data) { if (response.data) {
@ -84,6 +114,32 @@ export default {
} }
}); });
}, },
checkEnv(val) {
this.$get("/api/automation/checkScenarioEnv/" + this.data.id, res => {
if (this.data.environmentEnable && !res.data) {
this.data.environmentEnable = false;
this.$warning(this.$t('commons.scenario_warning'));
return;
}
this.setDomain(val);
});
},
setDomain(val) {
let param = {
environmentEnable: val,
id: this.data.id,
environmentType: this.environmentType,
environmentGroupId: this.environmentGroupId,
environmentMap: strMapToObj(this.envMap),
definition: JSON.stringify(this.data)
}
this.$post("/api/automation/setDomain", param, res => {
if (res.data) {
let data = JSON.parse(res.data);
this.data.hashTree = data.hashTree;
}
})
},
saveAsApi() { saveAsApi() {
this.currentProtocol = this.data.protocol; this.currentProtocol = this.data.protocol;
this.$refs.api.open(this.data); this.$refs.api.open(this.data);