fix(场景自动化): 禁用场景步骤仍要求选择环境

This commit is contained in:
shiziyuan9527 2021-04-06 23:00:57 +08:00 committed by BugKing
parent 491dd7fc27
commit ab0f6d33c0
11 changed files with 666 additions and 261 deletions

View File

@ -392,9 +392,11 @@ public class ApiAutomationService {
ApiDefinition apiDefinition = apiDefinitionService.get(tr.getId());
http.setUrl(apiDefinition.getPath());
}
if (StringUtils.isBlank(http.getUrl()) || !isURL(http.getUrl())) {
env.getProjectIds().add(http.getProjectId());
env.setFullUrl(false);
if (http.isEnable()) {
if (StringUtils.isBlank(http.getUrl()) || !isURL(http.getUrl())) {
env.getProjectIds().add(http.getProjectId());
env.setFullUrl(false);
}
}
} else if (StringUtils.equals(tr.getType(), "TCPSampler")) {
if (StringUtils.equals(tr.getRefType(), "CASE")) {
@ -405,11 +407,13 @@ public class ApiAutomationService {
env.getProjectIds().add(apiDefinition.getProjectId());
}
} else if (StringUtils.equals(tr.getType(), "scenario")) {
ApiScenarioDTO apiScenario = getApiScenario(tr.getId());
String scenarioDefinition = apiScenario.getScenarioDefinition();
JSONObject element1 = JSON.parseObject(scenarioDefinition);
LinkedList<MsTestElement> hashTree1 = mapper.readValue(element1.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>(){});
tr.setHashTree(hashTree1);
if (tr.isEnable()) {
ApiScenarioDTO apiScenario = getApiScenario(tr.getId());
String scenarioDefinition = apiScenario.getScenarioDefinition();
JSONObject element1 = JSON.parseObject(scenarioDefinition);
LinkedList<MsTestElement> hashTree1 = mapper.readValue(element1.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>(){});
tr.setHashTree(hashTree1);
}
}
} else {
if (StringUtils.equals(tr.getType(), "HTTPSamplerProxy")) {
@ -425,6 +429,9 @@ public class ApiAutomationService {
env.getProjectIds().add(tr.getProjectId());
}
}
if (!tr.isEnable()) {
continue;
}
if (CollectionUtils.isNotEmpty(tr.getHashTree())) {
getHashTree(tr.getHashTree(), env);
}
@ -452,9 +459,11 @@ public class ApiAutomationService {
ApiDefinition apiDefinition = apiDefinitionService.get(tr.getId());
http.setUrl(apiDefinition.getPath());
}
if (StringUtils.isBlank(http.getUrl()) || !this.isURL(http.getUrl())) {
env.setFullUrl(false);
env.getProjectIds().add(http.getProjectId());
if (http.isEnable()) {
if (StringUtils.isBlank(http.getUrl()) || !this.isURL(http.getUrl())) {
env.setFullUrl(false);
env.getProjectIds().add(http.getProjectId());
}
}
} else if (StringUtils.equals(tr.getType(), "TCPSampler")) {
if (StringUtils.equals(tr.getRefType(), "CASE")) {
@ -465,11 +474,13 @@ public class ApiAutomationService {
env.getProjectIds().add(apiDefinition.getProjectId());
}
} else if (StringUtils.equals(tr.getType(), "scenario")) {
ApiScenarioDTO apiScenario = getApiScenario(tr.getId());
String scenarioDefinition = apiScenario.getScenarioDefinition();
JSONObject element1 = JSON.parseObject(scenarioDefinition);
LinkedList<MsTestElement> hashTree1 = mapper.readValue(element1.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>(){});
tr.setHashTree(hashTree1);
if (tr.isEnable()) {
ApiScenarioDTO apiScenario = getApiScenario(tr.getId());
String scenarioDefinition = apiScenario.getScenarioDefinition();
JSONObject element1 = JSON.parseObject(scenarioDefinition);
LinkedList<MsTestElement> hashTree1 = mapper.readValue(element1.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>(){});
tr.setHashTree(hashTree1);
}
}
} else {
if (StringUtils.equals(tr.getType(), "HTTPSamplerProxy")) {
@ -485,6 +496,9 @@ public class ApiAutomationService {
env.getProjectIds().add(tr.getProjectId());
}
}
if (!tr.isEnable()) {
continue;
}
if (CollectionUtils.isNotEmpty(tr.getHashTree())) {
getHashTree(tr.getHashTree(), env);
}

View File

@ -121,7 +121,7 @@
</el-col>
<el-col :span="5">
<env-popover :env-map="projectEnvMap" :project-ids="projectIds" @setProjectEnvMap="setProjectEnvMap"
:project-list="projectList" ref="envPopover"/>
@showPopover="showPopover" :project-list="projectList" ref="envPopover"/>
</el-col>
<el-col :span="4">
<el-button :disabled="scenarioDefinition.length < 1" size="mini" type="primary" v-prevent-re-click @click="runDebug">{{$t('api_test.request.debug')}}</el-button>
@ -205,8 +205,8 @@
<!--步骤最大化-->
<ms-drawer :visible="drawer" :size="100" @close="close" direction="right" :show-full-screen="false" :is-show-close="false" style="overflow: hidden">
<template v-slot:header>
<scenario-header :currentScenario="currentScenario" :projectEnvMap="projectEnvMap" :projectIds="projectIds" :projectList="projectList" :scenarioDefinition="scenarioDefinition" :enableCookieShare="enableCookieShare"
@closePage="close" @unFullScreen="unFullScreen" @showAllBtn="showAllBtn" @runDebug="runDebug" @setProjectEnvMap="setProjectEnvMap" @showScenarioParameters="showScenarioParameters" @setCookieShare="setCookieShare" ref="maximizeHeader"/>
<scenario-header :currentScenario="currentScenario" :projectEnvMap="projectEnvMap" :projectIds.sync="projectIds" :projectList="projectList" :scenarioDefinition="scenarioDefinition" :enableCookieShare="enableCookieShare"
:isFullUrl.sync="isFullUrl" @closePage="close" @unFullScreen="unFullScreen" @showAllBtn="showAllBtn" @runDebug="runDebug" @setProjectEnvMap="setProjectEnvMap" @showScenarioParameters="showScenarioParameters" @setCookieShare="setCookieShare" ref="maximizeHeader"/>
</template>
<maximize-scenario :scenario-definition="scenarioDefinition" :envMap="projectEnvMap" :moduleOptions="moduleOptions"
@ -778,9 +778,9 @@
this.$nextTick(() => {
this.loading = false
});
let definition = JSON.parse(JSON.stringify(this.currentScenario));
definition.hashTree = this.scenarioDefinition;
this.getEnv(JSON.stringify(definition));
// let definition = JSON.parse(JSON.stringify(this.currentScenario));
// definition.hashTree = this.scenarioDefinition;
// this.getEnv(JSON.stringify(definition));
},
runDebug() {
/*触发执行操作*/
@ -789,24 +789,28 @@
let definition = JSON.parse(JSON.stringify(this.currentScenario));
definition.hashTree = this.scenarioDefinition;
this.getEnv(JSON.stringify(definition)).then(() => {
let sign = this.$refs.envPopover.checkEnv(this.isFullUrl);
if (!sign) {
return;
}
this.editScenario().then(() => {
this.debugData = {
id: this.currentScenario.id,
name: this.currentScenario.name,
type: "scenario",
variables: this.currentScenario.variables,
referenced: 'Created',
enableCookieShare: this.enableCookieShare,
headers: this.currentScenario.headers,
environmentMap: this.projectEnvMap,
hashTree: this.scenarioDefinition
};
this.reportId = getUUID().substring(0, 8);
let promise = this.$refs.envPopover.initEnv();
promise.then(() => {
let sign = this.$refs.envPopover.checkEnv(this.isFullUrl);
if (!sign) {
return;
}
this.editScenario().then(() => {
this.debugData = {
id: this.currentScenario.id,
name: this.currentScenario.name,
type: "scenario",
variables: this.currentScenario.variables,
referenced: 'Created',
enableCookieShare: this.enableCookieShare,
headers: this.currentScenario.headers,
environmentMap: this.projectEnvMap,
hashTree: this.scenarioDefinition
};
this.reportId = getUUID().substring(0, 8);
})
})
})
}
})
@ -1002,7 +1006,7 @@
if (response.data) {
this.path = "/api/automation/update";
if (response.data.scenarioDefinition != null) {
this.getEnv(response.data.scenarioDefinition);
// this.getEnv(response.data.scenarioDefinition);
let obj = JSON.parse(response.data.scenarioDefinition);
if (obj) {
this.currentEnvironmentId = obj.environmentId;
@ -1138,6 +1142,13 @@
close(name) {
this.drawer = false;
this.$emit('closePage', name);
},
showPopover() {
let definition = JSON.parse(JSON.stringify(this.currentScenario));
definition.hashTree = this.scenarioDefinition;
this.getEnv(JSON.stringify(definition)).then(() => {
this.$refs.envPopover.openEnvSelect();
})
}
}
}

View File

@ -39,11 +39,17 @@ export default {
},
methods: {
showPopover() {
this.$refs.envSelect.open();
this.$emit("showPopover");
},
openEnvSelect() {
return this.$refs.envSelect.open();
},
setProjectEnvMap(map) {
this.$emit("setProjectEnvMap", map);
},
initEnv() {
return this.$refs.envSelect.initEnv();
},
checkEnv(data) {
return this.$refs.envSelect.checkEnv(data);
}

View File

@ -5,12 +5,14 @@
<el-option v-for="(environment, index) in pe.envs" :key="index"
:label="environment.name + (environment.config.httpConfig.socket ? (': ' + environment.config.httpConfig.protocol + '://' + environment.config.httpConfig.socket) : '')"
:value="environment.id"/>
<el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig(pe.id, pe['selectEnv'])">
<el-button class="ms-scenario-button" size="mini" type="primary"
@click="openEnvironmentConfig(pe.id, pe['selectEnv'])">
{{ $t('api_test.environment.environment_config') }}
</el-button>
<template v-slot:empty>
<div class="empty-environment">
<el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig(pe.id, pe['selectEnv'])">
<el-button class="ms-scenario-button" size="mini" type="primary"
@click="openEnvironmentConfig(pe.id, pe['selectEnv'])">
{{ $t('api_test.environment.environment_config') }}
</el-button>
</div>
@ -29,35 +31,37 @@
</template>
<script>
import {parseEnvironment} from "@/business/components/api/test/model/EnvironmentModel";
import ApiEnvironmentConfig from "@/business/components/api/definition/components/environment/ApiEnvironmentConfig";
import {ELEMENTS} from "./Setting";
import {parseEnvironment} from "@/business/components/api/test/model/EnvironmentModel";
import ApiEnvironmentConfig from "@/business/components/api/definition/components/environment/ApiEnvironmentConfig";
import {ELEMENTS} from "./Setting";
export default {
name: "EnvironmentSelect",
components: {ApiEnvironmentConfig},
props: {
envMap: Map,
projectIds: Set,
projectList: Array
},
data() {
return {
data: [],
result: {},
projects: [],
environments: [],
dialogVisible: false,
isFullUrl: true,
}
},
methods: {
init() {
this.projectIds.forEach(id => {
const project = this.projectList.find(p => p.id === id);
if (project) {
let item = {id: id, envs: [], selectEnv: ""};
this.data.push(item);
export default {
name: "EnvironmentSelect",
components: {ApiEnvironmentConfig},
props: {
envMap: Map,
projectIds: Set,
projectList: Array
},
data() {
return {
data: [],
result: {},
projects: [],
environments: [],
dialogVisible: false,
isFullUrl: true,
}
},
methods: {
init() {
let arr = [];
this.projectIds.forEach(id => {
const project = this.projectList.find(p => p.id === id);
if (project) {
let item = {id: id, envs: [], selectEnv: ""};
this.data.push(item);
let p = new Promise(resolve => {
this.result = this.$get('/api/environment/list/' + id, res => {
let envs = res.data;
envs.forEach(environment => {
@ -69,220 +73,228 @@
let envId = this.envMap.get(id);
//
temp.selectEnv = envs.filter(e => e.id === envId).length === 0 ? null : envId;
resolve();
})
}
})
},
open() {
this.data = [];
if (this.projectIds.size > 0) {
this.init();
}
},
getProjectName(id) {
const project = this.projectList.find(p => p.id === id);
return project ? project.name : "";
},
openEnvironmentConfig(projectId, envId) {
if (!projectId) {
this.$error(this.$t('api_test.select_project'));
return;
}
this.$refs.environmentConfig.open(projectId, envId);
},
handleConfirm() {
let map = new Map();
let sign = true;
this.data.forEach(dt => {
if (!dt.selectEnv) {
sign = false;
return;
}
map.set(dt.id, dt.selectEnv);
})
if (!sign) {
this.$warning("请为每个项目选择一个运行环境!");
return;
}
this.$emit('setProjectEnvMap', map);
this.$emit('close');
},
getApiInfo(request) {
if (request.id && request.referenced === 'REF') {
let requestResult = request.requestResult;
let url = request.refType && request.refType === 'CASE' ? "/api/testcase/get/" : "/api/definition/get/";
let enable = request.enable;
this.$get(url + request.id, response => {
if (response.data) {
Object.assign(request, JSON.parse(response.data.request));
request.name = response.data.name;
request.enable = enable;
if (response.data.path && response.data.path != null) {
request.path = response.data.path;
request.url = response.data.url;
this.setUrl(request.path);
}
if (response.data.method && response.data.method != null) {
request.method = response.data.method;
}
request.requestResult = requestResult;
request.id = response.data.id;
request.disabled = true;
request.root = true;
if (!request.projectId) {
request.projectId = response.data.projectId;
}
this.reload();
this.sort();
} else {
request.referenced = "Deleted";
}
})
arr.push(p);
}
},
getScenario(scenario) {
this.result = this.$get("/api/automation/getApiScenario/" + scenario.id, response => {
})
return arr;
},
open() {
this.data = [];
if (this.projectIds.size > 0) {
this.init();
}
},
initEnv() {
this.data = [];
return Promise.all(this.init());
},
getProjectName(id) {
const project = this.projectList.find(p => p.id === id);
return project ? project.name : "";
},
openEnvironmentConfig(projectId, envId) {
if (!projectId) {
this.$error(this.$t('api_test.select_project'));
return;
}
this.$refs.environmentConfig.open(projectId, envId);
},
handleConfirm() {
let map = new Map();
let sign = true;
this.data.forEach(dt => {
if (!dt.selectEnv) {
sign = false;
return;
}
map.set(dt.id, dt.selectEnv);
})
if (!sign) {
this.$warning("请为每个项目选择一个运行环境!");
return;
}
this.$emit('setProjectEnvMap', map);
this.$emit('close');
},
getApiInfo(request) {
if (request.id && request.referenced === 'REF') {
let requestResult = request.requestResult;
let url = request.refType && request.refType === 'CASE' ? "/api/testcase/get/" : "/api/definition/get/";
let enable = request.enable;
this.$get(url + request.id, response => {
if (response.data) {
scenario.loaded = true;
let obj = {};
if (response.data.scenarioDefinition) {
obj = JSON.parse(response.data.scenarioDefinition);
scenario.hashTree = obj.hashTree;
Object.assign(request, JSON.parse(response.data.request));
request.name = response.data.name;
request.enable = enable;
if (response.data.path && response.data.path != null) {
request.path = response.data.path;
request.url = response.data.url;
this.setUrl(request.path);
}
//scenario.disabled = true;
scenario.name = response.data.name;
if (!scenario.projectId) {
scenario.projectId = response.data.projectId;
if (response.data.method && response.data.method != null) {
request.method = response.data.method;
}
scenario.headers = obj.headers;
scenario.variables = obj.variables;
scenario.environmentMap = obj.environmentMap;
this.$emit('refReload');
request.requestResult = requestResult;
request.id = response.data.id;
request.disabled = true;
request.root = true;
if (!request.projectId) {
request.projectId = response.data.projectId;
}
this.reload();
this.sort();
} else {
scenario.referenced = "Deleted";
request.referenced = "Deleted";
}
})
},
recursiveSorting(arr) {
for (let i in arr) {
if (arr[i].referenced === 'REF') {
//
if (arr[i].type === "HTTPSamplerProxy") {
//
this.getApiInfo(arr[i]);
//
}
},
getScenario(scenario) {
this.result = this.$get("/api/automation/getApiScenario/" + scenario.id, response => {
if (response.data) {
scenario.loaded = true;
let obj = {};
if (response.data.scenarioDefinition) {
obj = JSON.parse(response.data.scenarioDefinition);
scenario.hashTree = obj.hashTree;
}
//scenario.disabled = true;
scenario.name = response.data.name;
if (!scenario.projectId) {
scenario.projectId = response.data.projectId;
}
scenario.headers = obj.headers;
scenario.variables = obj.variables;
scenario.environmentMap = obj.environmentMap;
this.$emit('refReload');
} else {
scenario.referenced = "Deleted";
}
})
},
recursiveSorting(arr) {
for (let i in arr) {
if (arr[i].referenced === 'REF') {
//
if (arr[i].type === "HTTPSamplerProxy") {
//
this.getApiInfo(arr[i]);
//
if (!arr[i].url || (!arr[i].url.startsWith("http://") && !arr[i].url.startsWith("https://"))) {
this.isFullUrl = false;
}
} else if (arr[i].type === "scenario") {
this.getScenario(arr[i]);
}
} else {
if (arr[i].type === "HTTPSamplerProxy") {
//
if (arr[i].enable) {
if (!arr[i].url || (!arr[i].url.startsWith("http://") && !arr[i].url.startsWith("https://"))) {
this.isFullUrl = false;
}
} else if (arr[i].type === "scenario") {
this.getScenario(arr[i]);
}
} else {
if (arr[i].type === "HTTPSamplerProxy") {
//
if (arr[i].enable) {
if (!arr[i].url || (!arr[i].url.startsWith("http://") && !arr[i].url.startsWith("https://"))) {
this.isFullUrl = false;
}
}
}
}
if (arr[i].hashTree != undefined && arr[i].hashTree.length > 0) {
this.recursiveSorting(arr[i].hashTree);
}
}
},
checkFullUrl(scenarioDefinition) {
for (let i in scenarioDefinition) {
// ID
let request = scenarioDefinition[i];
if (request.referenced === 'REF') {
if (request.type === "HTTPSamplerProxy") {
this.getApiInfo(request);
//
if (arr[i].hashTree != undefined && arr[i].hashTree.length > 0) {
this.recursiveSorting(arr[i].hashTree);
}
}
},
checkFullUrl(scenarioDefinition) {
for (let i in scenarioDefinition) {
// ID
let request = scenarioDefinition[i];
if (request.referenced === 'REF') {
if (request.type === "HTTPSamplerProxy") {
this.getApiInfo(request);
//
if (!request.url || (!request.url.startsWith("http://") && !request.url.startsWith("https://"))) {
this.isFullUrl = false;
}
} else if (request.type === "scenario") {
this.getScenario(request);
}
} else {
if (request.type === "HTTPSamplerProxy") {
//
if (request.enable) {
if (!request.url || (!request.url.startsWith("http://") && !request.url.startsWith("https://"))) {
this.isFullUrl = false;
}
} else if (request.type === "scenario") {
this.getScenario(request);
}
} else {
if (request.type === "HTTPSamplerProxy") {
//
if (request.enable) {
if (!request.url || (!request.url.startsWith("http://") && !request.url.startsWith("https://"))) {
this.isFullUrl = false;
}
}
}
}
if (scenarioDefinition[i].hashTree != undefined && scenarioDefinition[i].hashTree.length > 0) {
this.recursiveSorting(scenarioDefinition[i].hashTree);
}
}
},
checkEnv(data) {
let sign = true;
this.isFullUrl = true;
if (this.data.length > 0) {
this.data.forEach(dt => {
if (!dt.selectEnv) {
if (scenarioDefinition[i].hashTree != undefined && scenarioDefinition[i].hashTree.length > 0) {
this.recursiveSorting(scenarioDefinition[i].hashTree);
}
}
},
checkEnv(data) {
let sign = true;
this.isFullUrl = true;
if (this.data.length > 0) {
this.data.forEach(dt => {
if (!dt.selectEnv) {
sign = false;
return false;
}
})
} else {
//
if (this.envMap && this.envMap.size > 0) {
this.projectIds.forEach(id => {
if (!this.envMap.get(id)) {
sign = false;
return false;
}
})
} else {
//
if (this.envMap && this.envMap.size > 0) {
this.projectIds.forEach(id => {
if (!this.envMap.get(id)) {
sign = false;
return false;
}
})
} else {
if (!data) {
sign = false;
}
if (!data) {
sign = false;
}
//
//this.checkFullUrl(data);
//sign = this.isFullUrl;
}
if (!sign) {
this.$warning("请为每个项目选择一个运行环境!");
return false;
}
return true;
},
environmentConfigClose() {
// todo
//
//this.checkFullUrl(data);
//sign = this.isFullUrl;
}
if (!sign) {
this.$warning("请为每个项目选择一个运行环境!");
return false;
}
return true;
},
environmentConfigClose() {
// todo
}
}
}
</script>
<style scoped>
.ms-scenario-button {
margin-left: 20px;
}
.ms-scenario-button {
margin-left: 20px;
}
.env-confirm {
margin-left: 20px;
width: 360px;
margin-top: 10px;
}
.env-confirm {
margin-left: 20px;
width: 360px;
margin-top: 10px;
}
.project-name {
display: inline-block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 150px;
margin-left: 8px;
vertical-align: middle;
}
.project-name {
display: inline-block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 150px;
margin-left: 8px;
vertical-align: middle;
}
</style>

View File

@ -19,7 +19,7 @@
<el-checkbox v-model="cookieShare" @change="setCookieShare" style="margin-right: 20px">共享cookie</el-checkbox>
<env-popover :env-map="envMap" :project-ids="projectIds" @setProjectEnvMap="setProjectEnvMap"
:project-list="projectList" ref="envPopover" class="ms-right"/>
@showPopover="showPopover" :project-list="projectList" ref="envPopover" class="ms-right"/>
<el-button :disabled="scenarioDefinition.length < 1" size="mini" type="primary" v-prevent-re-click @click="runDebug">{{$t('api_test.request.debug')}}</el-button>
@ -37,7 +37,12 @@
export default {
name: "ScenarioHeader",
components: {EnvPopover},
props: {currentScenario: {}, scenarioDefinition: Array, enableCookieShare: Boolean, projectEnvMap: Map, projectIds: Set, projectList: Array},
props: {currentScenario: {}, scenarioDefinition: Array, enableCookieShare: Boolean,
projectEnvMap: Map,
projectIds: Set,
projectList: Array,
isFullUrl: Boolean
},
data() {
return {
envMap: new Map,
@ -102,7 +107,25 @@
setProjectEnvMap(projectEnvMap) {
this.$emit('setProjectEnvMap', projectEnvMap);
this.envMap = projectEnvMap;
}
},
showPopover() {
let definition = JSON.parse(JSON.stringify(this.currentScenario));
definition.hashTree = this.scenarioDefinition;
this.getEnv(JSON.stringify(definition)).then(() => {
this.$refs.envPopover.openEnvSelect();
})
},
getEnv(definition) {
return new Promise((resolve) => {
this.$post("/api/automation/getApiScenarioEnv", {definition: definition}, res => {
if (res.data) {
this.$emit("update:projectIds", new Set(res.data.projectIds))
this.$emit("update:isFullUrl", res.data.fullUrl)
}
resolve();
})
});
},
},
}
</script>

View File

@ -152,9 +152,7 @@ import {TEST_PLAN_CONFIGS} from "../../../../common/components/search/search-com
import {LIST_CHANGE, TrackEvent} from "@/business/components/common/head/ListEvent";
import {getCurrentProjectID} from "../../../../../../common/js/utils";
import {_filter, _sort} from "@/common/js/tableUtils";
import EnvPopover from "@/business/components/api/automation/scenario/EnvPopover";
import EnvPopover from "@/business/components/track/common/EnvPopover";
export default {
name: "TestPlanList",
components: {

View File

@ -41,8 +41,7 @@
<script>
import MsDialogFooter from "../../../common/components/MsDialogFooter";
import {listenGoBack, removeGoBackListener} from "@/common/js/utils";
import EnvPopover from "@/business/components/api/automation/scenario/EnvPopover";
import EnvPopover from "@/business/components/track/common/EnvPopover";
export default {
name: "BatchEdit",
components: {

View File

@ -0,0 +1,57 @@
<template>
<el-popover
v-model="visible"
placement="bottom"
width="400"
:disabled="isReadOnly"
@show="showPopover"
trigger="click">
<env-select :project-ids="projectIds" :env-map="envMap" @close="visible = false"
ref="envSelect" @setProjectEnvMap="setProjectEnvMap" :project-list="projectList"/>
<el-button type="primary" slot="reference" size="mini" style="margin-top: 2px;">
{{ $t('api_test.definition.request.run_env') }}
<i class="el-icon-caret-bottom el-icon--right"></i>
</el-button>
</el-popover>
</template>
<script>
import EnvSelect from "@/business/components/track/common/EnvSelect";
export default {
name: "EnvPopover",
components: {EnvSelect},
props: {
envMap: Map,
projectIds: Set,
projectList: Array,
isReadOnly: {
type: Boolean,
default() {
return false;
}
}
},
data() {
return {
visible: false
}
},
methods: {
showPopover() {
this.$refs.envSelect.open();
},
setProjectEnvMap(map) {
this.$emit("setProjectEnvMap", map);
},
checkEnv() {
return this.$refs.envSelect.checkEnv();
}
}
}
</script>
<style scoped>
</style>

View File

@ -0,0 +1,285 @@
<template>
<div v-loading="result.loading">
<div v-for="pe in data" :key="pe.id" style="margin-left: 20px;">
<el-select v-model="pe['selectEnv']" placeholder="请选择环境" style="margin-top: 8px;width: 200px;" size="small">
<el-option v-for="(environment, index) in pe.envs" :key="index"
:label="environment.name + (environment.config.httpConfig.socket ? (': ' + environment.config.httpConfig.protocol + '://' + environment.config.httpConfig.socket) : '')"
:value="environment.id"/>
<el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig(pe.id, pe['selectEnv'])">
{{ $t('api_test.environment.environment_config') }}
</el-button>
<template v-slot:empty>
<div class="empty-environment">
<el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig(pe.id, pe['selectEnv'])">
{{ $t('api_test.environment.environment_config') }}
</el-button>
</div>
</template>
</el-select>
<span class="project-name" :title="getProjectName(pe.id)">
{{ getProjectName(pe.id) }}
</span>
</div>
<el-button type="primary" @click="handleConfirm" size="small" class="env-confirm"> </el-button>
<!-- 环境配置 -->
<api-environment-config ref="environmentConfig" @close="environmentConfigClose"/>
</div>
</template>
<script>
import {parseEnvironment} from "@/business/components/api/test/model/EnvironmentModel";
import ApiEnvironmentConfig from "@/business/components/api/definition/components/environment/ApiEnvironmentConfig";
export default {
name: "EnvironmentSelect",
components: {ApiEnvironmentConfig},
props: {
envMap: Map,
projectIds: Set,
projectList: Array
},
data() {
return {
data: [],
result: {},
projects: [],
environments: [],
dialogVisible: false,
isFullUrl: true,
}
},
methods: {
init() {
this.projectIds.forEach(id => {
const project = this.projectList.find(p => p.id === id);
if (project) {
let item = {id: id, envs: [], selectEnv: ""};
this.data.push(item);
this.result = this.$get('/api/environment/list/' + id, res => {
let envs = res.data;
envs.forEach(environment => {
parseEnvironment(environment);
});
//
let temp = this.data.find(dt => dt.id === id);
temp.envs = envs;
let envId = this.envMap.get(id);
//
temp.selectEnv = envs.filter(e => e.id === envId).length === 0 ? null : envId;
})
}
})
},
open() {
this.data = [];
if (this.projectIds.size > 0) {
this.init();
}
},
getProjectName(id) {
const project = this.projectList.find(p => p.id === id);
return project ? project.name : "";
},
openEnvironmentConfig(projectId, envId) {
if (!projectId) {
this.$error(this.$t('api_test.select_project'));
return;
}
this.$refs.environmentConfig.open(projectId, envId);
},
handleConfirm() {
let map = new Map();
let sign = true;
this.data.forEach(dt => {
if (!dt.selectEnv) {
sign = false;
return;
}
map.set(dt.id, dt.selectEnv);
})
if (!sign) {
this.$warning("请为每个项目选择一个运行环境!");
return;
}
this.$emit('setProjectEnvMap', map);
this.$emit('close');
},
getApiInfo(request) {
if (request.id && request.referenced === 'REF') {
let requestResult = request.requestResult;
let url = request.refType && request.refType === 'CASE' ? "/api/testcase/get/" : "/api/definition/get/";
let enable = request.enable;
this.$get(url + request.id, response => {
if (response.data) {
Object.assign(request, JSON.parse(response.data.request));
request.name = response.data.name;
request.enable = enable;
if (response.data.path && response.data.path != null) {
request.path = response.data.path;
request.url = response.data.url;
this.setUrl(request.path);
}
if (response.data.method && response.data.method != null) {
request.method = response.data.method;
}
request.requestResult = requestResult;
request.id = response.data.id;
request.disabled = true;
request.root = true;
if (!request.projectId) {
request.projectId = response.data.projectId;
}
this.reload();
this.sort();
} else {
request.referenced = "Deleted";
}
})
}
},
getScenario(scenario) {
this.result = this.$get("/api/automation/getApiScenario/" + scenario.id, response => {
if (response.data) {
scenario.loaded = true;
let obj = {};
if (response.data.scenarioDefinition) {
obj = JSON.parse(response.data.scenarioDefinition);
scenario.hashTree = obj.hashTree;
}
//scenario.disabled = true;
scenario.name = response.data.name;
if (!scenario.projectId) {
scenario.projectId = response.data.projectId;
}
scenario.headers = obj.headers;
scenario.variables = obj.variables;
scenario.environmentMap = obj.environmentMap;
this.$emit('refReload');
} else {
scenario.referenced = "Deleted";
}
})
},
recursiveSorting(arr) {
for (let i in arr) {
if (arr[i].referenced === 'REF') {
//
if (arr[i].type === "HTTPSamplerProxy") {
//
this.getApiInfo(arr[i]);
//
if (!arr[i].url || (!arr[i].url.startsWith("http://") && !arr[i].url.startsWith("https://"))) {
this.isFullUrl = false;
}
} else if (arr[i].type === "scenario") {
this.getScenario(arr[i]);
}
} else {
if (arr[i].type === "HTTPSamplerProxy") {
//
if (arr[i].enable) {
if (!arr[i].url || (!arr[i].url.startsWith("http://") && !arr[i].url.startsWith("https://"))) {
this.isFullUrl = false;
}
}
}
}
if (arr[i].hashTree != undefined && arr[i].hashTree.length > 0) {
this.recursiveSorting(arr[i].hashTree);
}
}
},
checkFullUrl(scenarioDefinition) {
for (let i in scenarioDefinition) {
// ID
let request = scenarioDefinition[i];
if (request.referenced === 'REF') {
if (request.type === "HTTPSamplerProxy") {
this.getApiInfo(request);
//
if (!request.url || (!request.url.startsWith("http://") && !request.url.startsWith("https://"))) {
this.isFullUrl = false;
}
} else if (request.type === "scenario") {
this.getScenario(request);
}
} else {
if (request.type === "HTTPSamplerProxy") {
//
if (request.enable) {
if (!request.url || (!request.url.startsWith("http://") && !request.url.startsWith("https://"))) {
this.isFullUrl = false;
}
}
}
}
if (scenarioDefinition[i].hashTree != undefined && scenarioDefinition[i].hashTree.length > 0) {
this.recursiveSorting(scenarioDefinition[i].hashTree);
}
}
},
checkEnv() {
let sign = true;
this.isFullUrl = true;
if (this.data.length > 0) {
this.data.forEach(dt => {
if (!dt.selectEnv) {
sign = false;
return false;
}
})
} else {
//
if (this.envMap && this.envMap.size > 0) {
this.projectIds.forEach(id => {
if (!this.envMap.get(id)) {
sign = false;
return false;
}
})
} else {
sign = false;
}
//
//this.checkFullUrl(data);
//sign = this.isFullUrl;
}
if (!sign) {
this.$warning("请为每个项目选择一个运行环境!");
return false;
}
return true;
},
environmentConfigClose() {
// todo
}
}
}
</script>
<style scoped>
.ms-scenario-button {
margin-left: 20px;
}
.env-confirm {
margin-left: 20px;
width: 360px;
margin-top: 10px;
}
.project-name {
display: inline-block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 150px;
margin-left: 8px;
vertical-align: middle;
}
</style>

View File

@ -68,7 +68,7 @@
import MsTestPlanList from "../../../../../api/automation/scenario/testplan/TestPlanList";
import TestPlanScenarioListHeader from "./TestPlanScenarioListHeader";
import {_handleSelect, _handleSelectAll} from "../../../../../../../common/js/tableUtils";
import EnvPopover from "@/business/components/api/automation/scenario/EnvPopover";
import EnvPopover from "@/business/components/track/common/EnvPopover";
export default {
name: "RelevanceScenarioList",

View File

@ -56,7 +56,7 @@
<script>
import {_handleSelect, _handleSelectAll} from "@/common/js/tableUtils";
import MsTag from "@/business/components/common/components/MsTag";
import EnvPopover from "@/business/components/api/automation/scenario/EnvPopover";
import EnvPopover from "@/business/components/track/common/EnvPopover";
import MsTablePagination from "@/business/components/common/pagination/TablePagination";
export default {