fix(接口自动化): 修复导出jmx校验问题

This commit is contained in:
fit2-zhao 2021-03-24 17:25:00 +08:00
parent bd0a6132e6
commit 8cf3e3f9ce
7 changed files with 41 additions and 30 deletions

View File

@ -140,7 +140,7 @@ public class MsScenario extends MsTestElement {
if (arguments != null) {
tree.add(config.valueSupposeMock(arguments));
}
this.addCsvDataSet(tree, variables);
this.addCsvDataSet(tree, variables,config);
this.addCounter(tree, variables);
this.addRandom(tree, variables);
if (CollectionUtils.isNotEmpty(this.headers)) {

View File

@ -201,7 +201,7 @@ public abstract class MsTestElement {
return null;
}
protected void addCsvDataSet(HashTree tree, List<ScenarioVariable> variables) {
protected void addCsvDataSet(HashTree tree, List<ScenarioVariable> variables,ParameterConfig config) {
if (CollectionUtils.isNotEmpty(variables)) {
List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isCSVValid).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(list)) {
@ -213,7 +213,7 @@ public abstract class MsTestElement {
csvDataSet.setName(StringUtils.isEmpty(item.getName()) ? "CSVDataSet" : item.getName());
csvDataSet.setProperty("fileEncoding", StringUtils.isEmpty(item.getEncoding()) ? "UTF-8" : item.getEncoding());
if (CollectionUtils.isNotEmpty(item.getFiles())) {
if (new File(BODY_FILE_DIR + "/" + item.getFiles().get(0).getId() + "_" + item.getFiles().get(0).getName()).exists()) {
if (!config.isOperating() && new File(BODY_FILE_DIR + "/" + item.getFiles().get(0).getId() + "_" + item.getFiles().get(0).getName()).exists()) {
MSException.throwException(StringUtils.isEmpty(item.getName()) ? "CSVDataSet" : item.getName() + "[ CSV文件不存在 ]");
}
csvDataSet.setProperty("filename", BODY_FILE_DIR + "/" + item.getFiles().get(0).getId() + "_" + item.getFiles().get(0).getName());

View File

@ -56,7 +56,7 @@ public class MsLoopController extends MsTestElement {
}
final HashTree groupTree = controller(tree);
if (CollectionUtils.isNotEmpty(config.getVariables())) {
this.addCsvDataSet(groupTree, config.getVariables());
this.addCsvDataSet(groupTree, config.getVariables(),config);
this.addCounter(groupTree, config.getVariables());
this.addRandom(groupTree, config.getVariables());
}

View File

@ -58,7 +58,7 @@ public class MsJmeterElement extends MsTestElement {
LogUtil.info(((ThreadGroup) scriptWrapper).getName() + "是被禁用线程组不加入执行");
} else {
// CSV数据检查文件路径是否还存在
if (scriptWrapper instanceof CSVDataSet) {
if (!config.isOperating() && scriptWrapper instanceof CSVDataSet) {
String path = ((CSVDataSet) scriptWrapper).getPropertyAsString("filename");
if (!new File(path).exists()) {
MSException.throwException(StringUtils.isEmpty(((CSVDataSet) scriptWrapper).getName()) ? "CSVDataSet" : ((CSVDataSet) scriptWrapper).getName() + "[ CSV文件不存在 ]");

View File

@ -1,6 +1,6 @@
<template>
<div>
<el-card class="table-card" v-loading="loading">
<el-card class="table-card" v-loading="result.loading">
<template v-slot:header>
<ms-table-header :condition.sync="condition" @search="selectByParam" title=""
:show-create="false" :tip="$t('commons.search_by_id_name_tag')"/>
@ -246,10 +246,10 @@
},
data() {
return {
result: {},
type: API_SCENARIO_LIST,
headerItems: Api_Scenario_List,
tableLabel: Api_Scenario_List,
loading: false,
screenHeight: document.documentElement.clientHeight - 280,//,
condition: {
components: API_SCENARIO_CONFIGS
@ -358,7 +358,7 @@
this.search();
},
batchReportId() {
this.loading = true;
this.result.loading = true;
this.getReport();
}
},
@ -418,7 +418,7 @@
this.selectDataCounts = 0;
let url = "/api/automation/list/" + this.currentPage + "/" + this.pageSize;
if (this.condition.projectId) {
this.loading = true;
this.result.loading = true;
this.$post(url, this.condition, response => {
let data = response.data;
this.total = data.itemCount;
@ -428,7 +428,7 @@
item.tags = JSON.parse(item.tags);
}
});
this.loading = false;
this.result.loading = false;
this.unSelection = data.listObject.map(s => s.id);
if (this.$refs.scenarioTable) {
this.$refs.scenarioTable.doLayout()
@ -550,13 +550,13 @@
} catch (e) {
throw e;
}
this.loading = false;
this.result.loading = false;
this.$success("批量执行成功,请到报告页面查看详情!");
} else {
setTimeout(this.getReport, 2000)
}
} else {
this.loading = false;
this.result.loading = false;
this.$error(this.$t('api_report.not_exist'));
}
});
@ -723,9 +723,9 @@
this.$warning(this.$t("api_test.automation.scenario.check_case"));
return;
}
this.loading = true;
this.result.loading = true;
this.result = this.$post("/api/automation/export", param, response => {
this.loading = false;
this.result.loading = false;
let obj = response.data;
this.buildApiPath(obj.data);
downloadFile("Metersphere_Scenario_" + localStorage.getItem(PROJECT_NAME) + ".json", JSON.stringify(obj));
@ -738,9 +738,9 @@
this.$warning(this.$t("api_test.automation.scenario.check_case"));
return;
}
this.loading = true;
this.result.loading = true;
this.result = this.$post("/api/automation/export/jmx", param, response => {
this.loading = false;
this.result.loading = false;
let obj = response.data;
if (obj && obj.length > 0) {
obj.forEach(item => {

View File

@ -20,28 +20,29 @@
<template v-slot:append>
<el-dropdown v-if="!isReadOnly" size="small" split-button type="primary" class="ms-api-button" @click="handleCommand('add-api')"
v-tester
@command="handleCommand">
@command="handleCommand" trigger="click">
<el-button icon="el-icon-folder-add" @click="addScenario"></el-button>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="add-scenario">{{ $t('api_test.automation.add_scenario') }}</el-dropdown-item>
<el-dropdown-item command="import">{{ $t('api_test.api_import.label') }}</el-dropdown-item>
<el-dropdown-item command="export">{{ $t('report.export') }}MS</el-dropdown-item>
<el-dropdown-item command="exportJmx">{{ $t('report.export') }}JMX</el-dropdown-item>
<el-dropdown-item command="exports">
<el-dropdown placement="right-start" @command="chooseExportType">
<span>
{{ $t('report.export') }} <i class="el-icon-arrow-down el-icon--right"></i>
</span>
<el-dropdown-menu slot="dropdown">
<template>
<el-dropdown-item command="export">{{ $t('report.export_to_ms_format') }}</el-dropdown-item>
<el-dropdown-item command="exportJmx">{{ $t('report.export') }} JMETER 格式</el-dropdown-item>
</template>
</el-dropdown-menu>
</el-dropdown>
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>
</el-input>
<module-trash-button v-if="!isReadOnly" :condition="condition" :exe="enableTrash"/>
<!-- 是否保留这个 -->
<!--<api-scenario-module-header-->
<!--:condition="condition"-->
<!--:current-module="currentModule"-->
<!--:is-read-only="isReadOnly"-->
<!--:project-id="projectId"-->
<!--@exportAPI="exportAPI"-->
<!--@addScenario="addScenario"-->
<!--@refreshTable="$emit('refreshTable')"-->
<!--@refresh="refresh"/>-->
</template>
</ms-node-tree>
@ -150,6 +151,16 @@
break;
}
},
chooseExportType(e) {
switch (e) {
case "export":
this.$emit('exportAPI');
break;
case "exportJmx":
this.$emit('exportJmx');
break;
}
},
list(projectId) {
let url = undefined;
if (this.isPlanModel) {

View File

@ -28,7 +28,7 @@
<div class="header-right" @click.stop>
<slot name="message"></slot>
<el-tooltip :content="$t('test_resource_pool.enable_disable')" placement="top" v-if="showBtn">
<el-switch v-model="data.enable" class="enable-switch" size="mini" :disabled="data.disabled"/>
<el-switch v-model="data.enable" class="enable-switch" size="mini" :disabled="data.disabled && !data.root"/>
</el-tooltip>
<slot name="button"></slot>
<step-extend-btns style="display: contents" :data="data" @copy="copyRow" @remove="remove" @openScenario="openScenario" v-if="showBtn && (!data.disabled || data.root)"/>