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.setProjectId(caseWithBLOBs.getProjectId());
report.setVersionId(caseWithBLOBs.getVersionId());
report.setIntegratedReportId(finalSerialReportId);
if (StringUtils.isNotEmpty(finalSerialReportId)) {
report.setIntegratedReportId(finalSerialReportId);
}
executeQueue.put(caseWithBLOBs.getId(), report);
responseDTOS.add(new MsExecResponseDTO(caseWithBLOBs.getId(), report.getId(), request.getTriggerMode()));
});

View File

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

View File

@ -127,7 +127,7 @@
'Saved' as execute_type,
'API_INDEPENDENT' as report_type
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
<where>
<if test="request.combine != null">
@ -211,7 +211,7 @@
'Saved' as execute_type,
'API_INDEPENDENT' as report_type
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
<where>
<if test="request.combine != null">

View File

@ -33,7 +33,7 @@
<if test="request.executor != null and request.executor != ''">
and t.user_id = #{request.executor}
</if>
and t.integrated_report_id is null
and (t.integrated_report_id is null or t.integrated_report_id = 'null')
)
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
@ -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
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
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
(select t.id,t.create_time as executionTime

View File

@ -10,23 +10,22 @@
</slot>
<span>
<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">
<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"/>
</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"
v-if="data.referenced!='REF' && !data.disabled"/>
<el-tooltip placement="top" :content="data.name">
<span>{{ data.name }}</span>
</el-tooltip>
<el-tag size="mini" v-if="data.method && !data.pluginId" style="margin-left: 1rem">{{ getMethod() }}</el-tag>
<slot name = "afterTitle"/>
<slot name="afterTitle"/>
</span>
</slot>
<slot name="scenarioEnable"/>
</span>
<div v-if="!ifFromVariableAdvance" class="header-right" @click.stop>
@ -39,7 +38,15 @@
<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-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>
@ -66,6 +73,7 @@
<script>
import StepExtendBtns from "../component/StepExtendBtns";
import {STEP} from "../Setting";
export default {
name: "ApiBaseComponent",
components: {StepExtendBtns},
@ -124,7 +132,10 @@ export default {
ifFromVariableAdvance: {
type: Boolean,
default: false,
}
},
environmentType: String,
environmentGroupId: String,
envMap: Map,
},
watch: {
'$store.state.selectStep': function () {
@ -178,18 +189,18 @@ export default {
this.$refs.nameEdit.focus();
});
},
enter($event){
if(this.showVersion){
$event.currentTarget.className="scenario-name"
}else{
$event.currentTarget.className="scenario-version"
enter($event) {
if (this.showVersion) {
$event.currentTarget.className = "scenario-name"
} else {
$event.currentTarget.className = "scenario-version"
}
},
leave($event){
if(this.showVersion){
$event.currentTarget.className="scenario-unscroll"
}else{
$event.currentTarget.className="scenario-version"
leave($event) {
if (this.showVersion) {
$event.currentTarget.className = "scenario-unscroll"
} else {
$event.currentTarget.className = "scenario-version"
}
}
@ -240,7 +251,8 @@ export default {
white-space: nowrap;
width: 140px;
}
.scenario-version{
.scenario-version {
display: inline-block;
font-size: 13px;
margin: 0 5px;
@ -254,30 +266,31 @@ export default {
width: calc(100% - 23rem);
height: auto;
}
.scenario-version::-webkit-scrollbar
{
.scenario-version::-webkit-scrollbar {
background-color: #fff;
}
/*定义滚动条轨道 内阴影+圆角*/
.scenario-version::-webkit-scrollbar-track
{
.scenario-version::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px #fff;
border-radius: 1px;
background-color: #ffffff;
}
/*定义滑块 内阴影+圆角*/
.scenario-version::-webkit-scrollbar-thumb
{
.scenario-version::-webkit-scrollbar-thumb {
border-radius: 1px;
-webkit-box-shadow: inset 0 0 6px #fff;
background-color: #783887;
}
.scenario-version::-webkit-scrollbar {
/* width: 0px; */
height: 3px;
position: fixed;
}
.scenario-name {
display: inline-block;
font-size: 13px;
@ -296,32 +309,32 @@ export default {
scrollbar-track-color: transparent;
-ms-scrollbar-track-color: transparent;
}
.scenario-name::-webkit-scrollbar
{
.scenario-name::-webkit-scrollbar {
background-color: #fff;
}
/*定义滚动条轨道 内阴影+圆角*/
.scenario-name::-webkit-scrollbar-track
{
.scenario-name::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px #fff;
border-radius: 1px;
background-color: #ffffff;
}
/*定义滑块 内阴影+圆角*/
.scenario-name::-webkit-scrollbar-thumb
{
.scenario-name::-webkit-scrollbar-thumb {
border-radius: 1px;
-webkit-box-shadow: inset 0 0 6px #fff;
background-color: #783887;
}
.scenario-name::-webkit-scrollbar {
/* width: 0px; */
height: 3px;
position: fixed;
}
.scenario-unscroll{
.scenario-unscroll {
display: inline-block;
font-size: 13px;
margin: 0 5px;

View File

@ -15,6 +15,9 @@
color="#606266"
background-color="#F4F4F5"
:if-from-variable-advance="ifFromVariableAdvance"
:environmentType="environmentType"
:environmentGroupId="environmentGroupId"
:envMap="envMap"
:title="$t('commons.scenario')">
<template v-slot:afterTitle v-if="isSameSpace">
@ -42,26 +45,6 @@
{{ getCode() }}
</span>
</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">
<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/>

View File

@ -15,10 +15,30 @@
<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") }}
</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>
<ms-variable-list ref="scenarioParameters" @setVariables="setVariables"/>
<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>
</template>
@ -26,19 +46,23 @@
import {STEP} from "../Setting";
import MsVariableList from "../variable/VariableList";
import MsAddBasisApi from "../api/AddBasisApi";
import {getCurrentProjectID, getUUID} from "@/common/js/utils";
import {getCurrentProjectID, getUUID, strMapToObj} from "@/common/js/utils";
export default {
name: "StepExtendBtns",
components: {STEP, MsVariableList, MsAddBasisApi},
props: {
data: Object,
environmentType: String,
environmentGroupId: String,
envMap: Map,
},
data() {
return {
allSamplers: [],
currentProtocol: "HTTP",
filter: new STEP,
dialogVisible: false,
}
},
mounted() {
@ -62,11 +86,17 @@ export default {
case "saveAs":
this.saveAsApi();
break;
case "setScenario":
this.setScenario();
break;
}
},
setVariables(v,h){
setVariables(v, h) {
this.data.variables = v;
},
setScenario() {
this.dialogVisible = true;
},
getScenario() {
this.result = this.$get("/api/automation/getApiScenario/" + this.data.id, response => {
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() {
this.currentProtocol = this.data.protocol;
this.$refs.api.open(this.data);