fix(接口测试): 修复场景无数据源执行错误问题

--bug=1012630 --user=赵勇 【接口测试】场景中添加自定义sql请求-勾选引用环境-运行环境从无数据源切换为有数据源的-保存后单独执行提示未选环境 https://www.tapd.cn/55049933/s/1146461
This commit is contained in:
fit2-zhao 2022-04-25 14:08:21 +08:00 committed by fit2-zhao
parent 6cfd429869
commit 5887adc932
14 changed files with 75 additions and 102 deletions

View File

@ -210,7 +210,6 @@
:scenario="data"
:response="response"
:currentScenario="currentScenario"
:currentEnvironmentId="currentEnvironmentId"
:node="node"
:project-list="projectList"
:env-map="projectEnvMap"
@ -463,7 +462,6 @@ export default {
],
},
environments: [],
currentEnvironmentId: "",
maintainerOptions: [],
value: API_STATUS[0].id,
options: API_STATUS,
@ -1423,16 +1421,6 @@ export default {
this.environments.forEach(environment => {
parseEnvironment(environment);
});
let hasEnvironment = false;
for (let i in this.environments) {
if (this.environments[i].id === this.currentEnvironmentId) {
hasEnvironment = true;
break;
}
}
if (!hasEnvironment) {
this.currentEnvironmentId = '';
}
//
this.checkDataIsCopy();
});
@ -1576,7 +1564,6 @@ export default {
if (response.data.scenarioDefinition != null) {
let obj = JSON.parse(response.data.scenarioDefinition);
if (obj) {
this.currentEnvironmentId = obj.environmentId;
if (response.data.environmentJson) {
this.projectEnvMap = objToStrMap(JSON.parse(response.data.environmentJson));
} else {

View File

@ -99,7 +99,7 @@ export default {
type: Boolean,
default: true,
},
isScenario: String,
scenarioId: String,
isReadOnly: {
type: Boolean,
default: false
@ -117,7 +117,7 @@ export default {
}
},
created() {
if (!this.isScenario) {
if (!this.scenarioId) {
this.request.environmentId = this.$store.state.useEnvironment;
}
this.getEnvironments();
@ -135,7 +135,7 @@ export default {
deep: true
},
'$store.state.useEnvironment': function () {
if (!this.isScenario) {
if (!this.scenarioId) {
this.request.environmentId = this.$store.state.useEnvironment;
this.getEnvironments();
}
@ -186,15 +186,15 @@ export default {
getEnvironments() {
let envId = "";
let id = this.request.projectId ? this.request.projectId : this.projectId;
let scenarioEnvId = this.isScenario ? (this.isScenario + "_" + id) : id;
let scenarioEnvId = this.scenarioId ? (this.scenarioId + "_" + id) : id;
if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map
&& this.$store.state.scenarioEnvMap.has(scenarioEnvId)) {
envId = this.$store.state.scenarioEnvMap.get(scenarioEnvId);
}
if (this.request.referenced === 'Created' && this.isScenario && !this.request.isRefEnvironment) {
if (this.request.referenced === 'Created' && this.scenarioId && !this.request.isRefEnvironment) {
this.itselfEnvironment();
return;
} else if (!this.isScenario && !this.request.customizeReq) {
} else if (!this.scenarioId && !this.request.customizeReq) {
this.itselfEnvironment();
return;
}

View File

@ -84,7 +84,7 @@
:isShowEnable="true"
:response="response"
:referenced="true"
:isScenario="currentScenario.id"
:scenarioId="currentScenario.id"
:headers="request.headers "
:is-read-only="isCompReadOnly"
:request="request"/>
@ -101,21 +101,21 @@
:is-read-only="isCompReadOnly"
:response="response"
:show-pre-script="true"
:isScenario="currentScenario.id"
:scenarioId="currentScenario.id"
:show-script="true" :request="request"/>
<ms-sql-basis-parameters
v-if="request.protocol==='SQL'|| request.type==='JDBCSampler'"
:request="request"
:response="response"
:isScenario="currentScenario.id"
:scenarioId="currentScenario.id"
:is-read-only="isCompReadOnly"
:showScript="true"/>
<ms-dubbo-basis-parameters
v-if="request.protocol==='DUBBO' || request.protocol==='dubbo://'|| request.type==='DubboSampler'"
:request="request"
:isScenario="currentScenario.id"
:scenarioId="currentScenario.id"
:response="response"
:is-read-only="isCompReadOnly"
:showScript="true"/>
@ -196,7 +196,6 @@ export default {
type: Boolean,
default: true,
},
currentEnvironmentId: String,
projectList: Array,
envMap: Map,
message: String,
@ -501,17 +500,18 @@ export default {
this.reload();
},
run() {
let selectEnvId;
//
if (this.isApiImport || this.request.isRefEnvironment) {
if (this.request.type && (this.request.type === "HTTPSamplerProxy" || this.request.type === "JDBCSampler" || this.request.type === "TCPSampler")) {
if (!this.environmentMap || this.environmentMap.size === 0) {
this.$warning(this.$t('api_test.automation.env_message'));
return false;
} else if (this.environmentMap && this.environmentMap.size > 0) {
const env = this.environmentMap.get(this.request.projectId);
if (!env) {
this.$warning(this.$t('api_test.automation.env_message'));
return false;
if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map
&& this.$store.state.scenarioEnvMap.has((this.currentScenario.id + "_" + this.request.projectId))) {
selectEnvId = this.$store.state.scenarioEnvMap.get((this.currentScenario.id + "_" + this.request.projectId));
this.environmentMap = this.envMap;
}
if (!selectEnvId) {
this.$warning(this.$t('api_test.automation.env_message'));
return false;
}
}
}
@ -523,12 +523,15 @@ export default {
this.request.active = true;
this.loading = true;
this.runData = [];
this.request.useEnvironment = this.currentEnvironmentId;
if (selectEnvId) {
this.request.useEnvironment = selectEnvId;
this.request.environmentId = selectEnvId;
}
this.request.customizeReq = this.isCustomizeReq;
let debugData = {
id: this.currentScenario.id, name: this.currentScenario.name, type: "scenario",
variables: this.currentScenario.variables, referenced: 'Created', headers: this.currentScenario.headers,
enableCookieShare: this.enableCookieShare, environmentId: this.currentEnvironmentId, hashTree: [this.request],
enableCookieShare: this.enableCookieShare, environmentId: selectEnvId, hashTree: [this.request],
};
this.runData.push(debugData);
this.request.requestResult = [];

View File

@ -93,7 +93,6 @@ export default {
type: Boolean,
default: false,
},
currentEnvironmentId: String,
projectList: Array,
environmentType: String,
environmentGroupId: String,

View File

@ -14,7 +14,6 @@
:jsr223-processor="scenario"
:request="scenario"
:currentScenario="currentScenario"
:currentEnvironmentId="currentEnvironmentId"
:node="node"
:draggable="draggable"
:title="title"
@ -97,7 +96,6 @@ export default {
default: true,
},
currentScenario: {},
currentEnvironmentId: String,
response: {},
node: {},
projectList: Array,

View File

@ -15,7 +15,7 @@
<template v-slot:request>
<jdbc-processor-content
:showScript="false"
:isScenario="isScenario"
:scenarioId="scenarioId"
:request="request"/>
</template>
</api-base-component>
@ -35,7 +35,7 @@ export default {
ApiBaseComponent, MsDropdown, MsInstructionsIcon, MsCodeEdit
},
props: {
isScenario: String,
scenarioId: String,
draggable: {
type: Boolean,
default: false,

View File

@ -1,7 +1,8 @@
<template>
<div>
<ms-run :debug="true" :environment="envMap" :reportId="reportId" :saved="false" :runMode="'DEFINITION'" :run-data="debugData" @runRefresh="runRefresh" ref="runTest"/>
<api-base-component :if-from-variable-advance="ifFromVariableAdvance" @copy="copyRow" @active="active(controller)" @remove="remove" :data="controller" :draggable="draggable" :is-max="isMax" :show-btn="showBtn" :show-version="showVersion" color="#02A7F0" background-color="#F4F4F5" :title="$t('api_test.automation.loop_controller')" v-loading="loading">
<ms-run :debug="true" :environment="envMap" :reportId="reportId" :saved="false" :runMode="'DEFINITION'" :run-data="debugData" @errorRefresh="errorRefresh" @runRefresh="runRefresh" ref="runTest"/>
<api-base-component :if-from-variable-advance="ifFromVariableAdvance" @copy="copyRow" @active="active(controller)" @remove="remove" :data="controller" :draggable="draggable" :is-max="isMax" :show-btn="showBtn" :show-version="showVersion" color="#02A7F0"
background-color="#F4F4F5" :title="$t('api_test.automation.loop_controller')">
<template v-slot:headerLeft>
<i class="icon el-icon-arrow-right" :class="{'is-active': controller.active}" style="margin-right: 10px" v-if="!isMax"/>
@ -18,7 +19,7 @@
<template v-slot:button>
<el-button @click="runDebug" :disabled="!controller.enable" :tip="$t('api_test.run')" icon="el-icon-video-play" style="background-color: #409EFF;color: white;padding: 5px" size="mini" circle/>
</template>
<div v-if="controller.loopType==='LOOP_COUNT'" draggable>
<div v-if="controller.loopType==='LOOP_COUNT'" draggable v-loading="loading">
<el-row>
<el-col :span="8">
<span class="ms-span ms-radio">{{ $t('loop.loops') }}</span>
@ -40,7 +41,7 @@
</el-row>
</div>
<div v-else-if="controller.loopType==='FOREACH'" draggable>
<div v-else-if="controller.loopType==='FOREACH'" draggable v-loading="loading">
<el-row>
<el-col :span="8">
<el-input :placeholder="$t('api_test.automation.loop_return_val')" v-model="controller.forEachController.returnVal" size="small"/>
@ -58,7 +59,7 @@
</el-col>
</el-row>
</div>
<div v-else draggable>
<div v-else draggable v-loading="loading">
<el-input size="small" v-model="controller.whileController.variable" style="width: 20%" :placeholder="$t('api_test.request.condition_variable')"/>
<el-select v-model="controller.whileController.operator" :placeholder="$t('commons.please_select')" size="small" @change="change" style="width: 10%;margin-left: 10px">
<el-option v-for="o in operators" :key="o.value" :label="$t(o.label)" :value="o.value"/>
@ -95,7 +96,6 @@ export default {
components: {ApiBaseComponent, ApiResponseComponent, MsRun},
props: {
controller: {},
currentEnvironmentId: String,
currentScenario: {},
node: {},
message: String,
@ -254,11 +254,16 @@ export default {
this.$warning("当前循环下没有请求,不能执行");
return;
}
if(!this.controller.enable){
if (!this.controller.enable) {
this.$warning(this.$t('api_test.automation.debug_message'));
return;
}
this.loading = true;
let currentEnvironmentId;
if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map
&& this.$store.state.scenarioEnvMap.has((this.currentScenario.id + "_" + this.controller.projectId))) {
currentEnvironmentId = this.$store.state.scenarioEnvMap.get((this.currentScenario.id + "_" + this.controller.projectId));
}
this.debugData = {
id: this.currentScenario.id,
name: this.currentScenario.name,
@ -267,7 +272,7 @@ export default {
headers: this.currentScenario.headers,
referenced: "Created",
enableCookieShare: this.enableCookieShare,
environmentId: this.currentEnvironmentId,
environmentId: currentEnvironmentId,
hashTree: [this.controller],
};
if (this.node && this.node.data) {
@ -307,6 +312,9 @@ export default {
runRefresh() {
this.initMessageSocket();
},
errorRefresh() {
this.loading = false;
},
setResult(hashTree) {
if (hashTree) {
hashTree.forEach((item) => {

View File

@ -43,7 +43,7 @@
<div class="el-step__icon-inner">{{ request.preSize }}</div>
</div>
</span>
<ms-jmx-step :request="request" :apiId="request.id" :is-scenario="true" :response="response" :tab-type="'pre'" ref="preStep"/>
<ms-jmx-step :request="request" :apiId="request.id" :scenario-id="currentScenario.id" :response="response" :tab-type="'pre'" ref="preStep"/>
</el-tab-pane>
<el-tab-pane :label="$t('api_test.definition.request.post_operation')" name="postOperate">
<span class="item-tabs" effect="dark" placement="top-start" slot="label">
@ -52,7 +52,7 @@
<div class="el-step__icon-inner">{{ request.postSize }}</div>
</div>
</span>
<ms-jmx-step :request="request" :apiId="request.id" :is-scenario="true" :response="response" :tab-type="'post'" ref="postStep"/>
<ms-jmx-step :request="request" :apiId="request.id" :scenario-id="currentScenario.id" :response="response" :tab-type="'post'" ref="postStep"/>
</el-tab-pane>
<el-tab-pane :label="$t('api_test.definition.request.assertions_rule')" name="assertionsRule">
<span class="item-tabs" effect="dark" placement="top-start" slot="label">
@ -62,7 +62,7 @@
</div>
</span>
<div style="margin-right: 20px">
<ms-jmx-step :request="request" :apiId="request.id" :is-scenario="true" :response="response" @reload="reload" :tab-type="'assertionsRule'" ref="assertionsRule"/>
<ms-jmx-step :request="request" :apiId="request.id" :scenario-id="currentScenario.id" :response="response" @reload="reload" :tab-type="'assertionsRule'" ref="assertionsRule"/>
</div>
</el-tab-pane>
@ -302,30 +302,20 @@ export default {
}
},
run() {
if (this.isApiImport || this.request.isRefEnvironment) {
if (this.request.type && (this.request.type === "HTTPSamplerProxy" || this.request.type === "JDBCSampler" || this.request.type === "TCPSampler")) {
if (!this.envMap || this.envMap.size === 0) {
this.$warning(this.$t('api_test.automation.env_message'));
return false;
} else if (this.envMap && this.envMap.size > 0) {
const env = this.envMap.get(this.request.projectId);
if (!env) {
this.$warning(this.$t('api_test.automation.env_message'));
return false;
}
}
}
}
this.request.debug = true;
this.loading = true;
this.runData = [];
this.runData.projectId = this.request.projectId;
this.request.useEnvironment = this.currentEnvironmentId;
this.request.customizeReq = this.isCustomizeReq;
let currentEnvironmentId;
if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map
&& this.$store.state.scenarioEnvMap.has((this.currentScenario.id + "_" + this.request.projectId))) {
currentEnvironmentId = this.$store.state.scenarioEnvMap.get((this.currentScenario.id + "_" + this.request.projectId));
}
let debugData = {
id: this.currentScenario.id, name: this.currentScenario.name, type: "scenario",
variables: this.currentScenario.variables, referenced: 'Created', headers: this.currentScenario.headers,
enableCookieShare: this.enableCookieShare, environmentId: this.currentEnvironmentId, hashTree: [this.request],
enableCookieShare: this.enableCookieShare, environmentId: currentEnvironmentId, hashTree: [this.request],
};
this.runData.push(debugData);
this.request.requestResult = [];

View File

@ -98,7 +98,6 @@
:scenario="data"
:response="response"
:currentScenario="currentScenario"
:currentEnvironmentId="currentEnvironmentId"
:node="node"
:project-list="projectList"
:env-map="projectEnvMap"
@ -146,7 +145,6 @@
:scenario="selectedTreeNode"
:response="response"
:currentScenario="currentScenario"
:currentEnvironmentId="currentEnvironmentId"
:node="selectedNode"
:project-list="projectList"
:env-map="projectEnvMap"
@ -165,7 +163,6 @@
:scenario="item"
:response="response"
:currentScenario="currentScenario"
:currentEnvironmentId="currentEnvironmentId"
:project-list="projectList"
:env-map="projectEnvMap"
:draggable="false"
@ -287,7 +284,6 @@ export default {
},
environments: [],
projectEnvMap: Map,
currentEnvironmentId: "",
maintainerOptions: [],
value: API_STATUS[0].id,
options: API_STATUS,
@ -696,16 +692,6 @@ export default {
this.environments.forEach(environment => {
parseEnvironment(environment);
});
let hasEnvironment = false;
for (let i in this.environments) {
if (this.environments[i].id === this.currentEnvironmentId) {
hasEnvironment = true;
break;
}
}
if (!hasEnvironment) {
this.currentEnvironmentId = '';
}
//
this.checkDataIsCopy();
});

View File

@ -41,7 +41,7 @@
</el-col>
<el-col :span="2">
<el-checkbox
v-if="request.referenced==='Created' && isScenario"
v-if="request.referenced==='Created' && scenarioId !==''"
v-model="request.isRefEnvironment" :disabled="request.disabled" class="ref_environment" @change="getEnvironments">
{{ $t('api_test.request.refer_to_environment') }}
</el-checkbox>
@ -73,7 +73,7 @@
<div class="el-step__icon-inner">{{ request.preSize }}</div>
</div>
</span>
<ms-jmx-step :request="request" :isScenario="isScenario" :apiId="request.id" :response="response" :tab-type="'pre'"
<ms-jmx-step :request="request" :scenarioId="scenarioId" :apiId="request.id" :response="response" :tab-type="'pre'"
ref="preStep"/>
</el-tab-pane>
<el-tab-pane :label="$t('api_test.definition.request.post_operation')" name="postOperate"
@ -84,7 +84,7 @@
<div class="el-step__icon-inner">{{ request.postSize }}</div>
</div>
</span>
<ms-jmx-step :request="request" :isScenario="isScenario" :apiId="request.id" :response="response" :tab-type="'post'"
<ms-jmx-step :request="request" :scenarioId="scenarioId" :apiId="request.id" :response="response" :tab-type="'post'"
ref="postStep"/>
</el-tab-pane>
<el-tab-pane :label="$t('api_test.definition.request.assertions_rule')" name="assertionsRule"
@ -95,7 +95,7 @@
<div class="el-step__icon-inner">{{ request.ruleSize }}</div>
</div>
</span>
<ms-jmx-step :request="request" :apiId="request.id" :response="response" :isScenario="isScenario" @reload="reloadBody"
<ms-jmx-step :request="request" :apiId="request.id" :response="response" :scenarioId="scenarioId" @reload="reloadBody"
:tab-type="'assertionsRule'" ref="assertionsRule"/>
</el-tab-pane>
@ -149,7 +149,7 @@ export default {
type: Boolean,
default: false,
},
isScenario: String,
scenarioId: String,
isReadOnly: {
type: Boolean,
default: false
@ -176,7 +176,7 @@ export default {
deep: true
},
'$store.state.useEnvironment': function () {
if (!this.isScenario) {
if (!this.scenarioId) {
this.request.environmentId = this.$store.state.useEnvironment;
this.getEnvironments();
}
@ -281,10 +281,12 @@ export default {
&& this.$store.state.scenarioEnvMap.has(scenarioEnvId)) {
envId = this.$store.state.scenarioEnvMap.get(scenarioEnvId);
}
if (this.request.referenced === 'Created' && this.isScenario && !this.request.isRefEnvironment) {
if (this.request.referenced === 'Created' && this.scenarioId && !this.request.isRefEnvironment) {
alert(2222)
this.itselfEnvironment();
return;
} else if (!this.isScenario && !this.request.customizeReq) {
} else if (!this.scenarioId && !this.request.customizeReq) {
alert(333)
this.itselfEnvironment();
return;
}

View File

@ -46,7 +46,7 @@
<div class="el-step__icon-inner">{{ request.preSize }}</div>
</div>
</span>
<ms-jmx-step :request="request" :apiId="request.id" :response="response" :is-scenario="isScenario" :tab-type="'pre'"
<ms-jmx-step :request="request" :apiId="request.id" :response="response" :scenario-id="scenarioId" :tab-type="'pre'"
ref="preStep"/>
</el-tab-pane>
<el-tab-pane :label="$t('api_test.definition.request.post_operation')" name="postOperate"
@ -57,7 +57,7 @@
<div class="el-step__icon-inner">{{ request.postSize }}</div>
</div>
</span>
<ms-jmx-step :request="request" :apiId="request.id" :isScenario="isScenario"
<ms-jmx-step :request="request" :apiId="request.id" :scenarioId="scenarioId"
:response="response" :tab-type="'post'"
ref="postStep"/>
</el-tab-pane>
@ -69,7 +69,7 @@
<div class="el-step__icon-inner">{{ request.ruleSize }}</div>
</div>
</span>
<ms-jmx-step :request="request" :apiId="request.id" :isScenario="isScenario"
<ms-jmx-step :request="request" :apiId="request.id" :scenarioId="scenarioId"
:response="response" @reload="reloadBody"
:tab-type="'assertionsRule'" ref="assertionsRule"/>
</el-tab-pane>
@ -116,7 +116,7 @@ export default {
MsJmxStep
},
props: {
isScenario: String,
scenarioId: String,
request: {},
basisData: {},
moduleOptions: Array,

View File

@ -121,7 +121,7 @@
:apiId="request.id"
:response="response"
:tab-type="'pre'"
:isScenario="isScenario"
:scenarioId="scenarioId"
ref="preStep"
v-if="activeName === 'preOperate'"
/>
@ -138,7 +138,7 @@
:apiId="request.id"
:response="response"
:tab-type="'post'"
:isScenario="isScenario"
:scenarioId="scenarioId"
ref="postStep"
v-if="activeName === 'postOperate'"
/>
@ -153,7 +153,7 @@
<ms-jmx-step
:request="request"
:apiId="request.id"
:isScenario="isScenario"
:scenarioId="scenarioId"
:response="response"
@reload="reloadBody"
:tab-type="'assertionsRule'"
@ -210,7 +210,7 @@ export default {
return false;
}
},
isScenario: String,
scenarioId: String,
showScript: {
type: Boolean,
default: true,

View File

@ -128,7 +128,7 @@
<div class="el-step__icon-inner">{{ request.preSize }}</div>
</div>
</span>
<ms-jmx-step :request="request" :isScenario="isScenario"
<ms-jmx-step :request="request" :scenarioId="scenarioId"
:apiId="request.id" protocol="TCP" :response="response"
:tab-type="'pre'"
ref="preStep"/>
@ -141,7 +141,7 @@
<div class="el-step__icon-inner">{{ request.postSize }}</div>
</div>
</span>
<ms-jmx-step :request="request" :isScenario="isScenario"
<ms-jmx-step :request="request" :scenarioId="scenarioId"
:apiId="request.id" protocol="TCP" :response="response"
:tab-type="'post'"
ref="postStep"/>
@ -154,7 +154,7 @@
<div class="el-step__icon-inner">{{ request.ruleSize }}</div>
</div>
</span>
<ms-jmx-step :request="request" :apiId="request.id" protocol="TCP" :is-scenario="isScenario" :response="response"
<ms-jmx-step :request="request" :apiId="request.id" protocol="TCP" :scenario-id="scenarioId" :response="response"
@reload="reloadBody"
:tab-type="'assertionsRule'" ref="assertionsRule"/>
</el-tab-pane>
@ -202,7 +202,7 @@ export default {
MsJmxStep
},
props: {
isScenario: String,
scenarioId: String,
request: {},
basisData: {},
response: {},

View File

@ -49,7 +49,7 @@
@remove="remove"
:title="$t('api_test.definition.request.pre_sql')"
:is-read-only="false"
:isScenario="isScenario"
:scenarioId="scenarioId"
:request="data"
:jdbc-processor="data"
color="#B8741A"
@ -80,7 +80,7 @@
:title="$t('api_test.definition.request.post_sql')"
:is-read-only="false"
:request="data"
:isScenario="isScenario"
:scenarioId="scenarioId"
:jdbc-processor="data"
color="#783887"
background-color="#F2ECF3"/>
@ -139,7 +139,7 @@ export default {
tabType: String,
response: {},
apiId: String,
isScenario: String,
scenarioId: String,
showScript: {
type: Boolean,
default: true,