This commit is contained in:
wenyann 2020-12-24 18:40:47 +08:00
commit d492561453
6 changed files with 68 additions and 20 deletions

View File

@ -90,6 +90,13 @@ public class ApiAutomationController {
apiAutomationService.run(request);
}
@PostMapping(value = "/run/batch")
public void runBatch(@RequestBody RunScenarioRequest request) {
request.setExecuteType(ExecuteType.Saved.name());
apiAutomationService.run(request);
}
@PostMapping("/getReference")
public ReferenceDTO getReference(@RequestBody ApiScenarioRequest request) {
return apiAutomationService.getReference(request);

View File

@ -83,9 +83,7 @@ public class MsScenario extends MsTestElement {
}
}
// 场景变量
if (CollectionUtils.isNotEmpty(this.getVariables())) {
tree.add(arguments());
}
tree.add(arguments(config));
if (CollectionUtils.isNotEmpty(hashTree)) {
for (MsTestElement el : hashTree) {
@ -95,16 +93,23 @@ public class MsScenario extends MsTestElement {
}
private Arguments arguments() {
private Arguments arguments(ParameterConfig config) {
Arguments arguments = new Arguments();
arguments.setEnabled(true);
arguments.setName(name + "Variables");
arguments.setProperty(TestElement.TEST_CLASS, Arguments.class.getName());
arguments.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("ArgumentsPanel"));
variables.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->
arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=")
);
if (CollectionUtils.isNotEmpty(this.getVariables())) {
variables.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->
arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=")
);
}
if (config != null && config.getConfig() != null && config.getConfig().getCommonConfig() != null
&& CollectionUtils.isNotEmpty(config.getConfig().getCommonConfig().getVariables())) {
config.getConfig().getCommonConfig().getVariables().stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->
arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=")
);
}
return arguments;
}
}

View File

@ -297,10 +297,6 @@ public class ApiAutomationService {
testPlan.setHashTree(new LinkedList<>());
HashTree jmeterTestPlanHashTree = new ListedHashTree();
String projectID = request.getProjectId();
// 批量执行的结果直接存储为报告
if (apiScenarios.size() > 1) {
request.setExecuteType(ExecuteType.Saved.name());
}
boolean isOne = true;
for (ApiScenarioWithBLOBs item : apiScenarios) {
MsThreadGroup group = new MsThreadGroup();

View File

@ -6,7 +6,7 @@
:show-create="false"/>
</template>
<el-table ref="scenarioTable" border :data="tableData" class="adjust-table" @select-all="select" @select="select">
<el-table ref="scenarioTable" border :data="tableData" class="adjust-table" @select-all="select" @select="select" v-loading="loading">
<el-table-column type="selection"/>
<el-table-column width="40" :resizable="false" align="center">
<template v-slot:default="{row}">
@ -118,11 +118,14 @@
pageSize: 10,
total: 0,
reportId: "",
batchReportId: "",
content: {},
infoDb: false,
runVisible: false,
planVisible: false,
projectId: "",
runData: [],
report: {},
buttons: [
{
name: this.$t('api_test.automation.batch_add_plan'), handleClick: this.handleBatchAddCase
@ -145,12 +148,20 @@
this.search();
}
},
batchReportId() {
this.loading = true;
this.getReport();
}
},
computed: {
isNotRunning() {
return "Running" !== this.report.status;
}
},
methods: {
search() {
this.loading = true;
this.condition.filters = ["Prepare", "Underway", "Completed"];
this.condition.moduleIds = this.selectNodeIds;
if (this.trashEnable) {
@ -197,9 +208,33 @@
this.$success(this.$t("commons.save_success"));
});
},
getReport() {
if (this.batchReportId) {
let url = "/api/scenario/report/get/" + this.batchReportId;
this.$get(url, response => {
this.report = response.data || {};
if (response.data) {
if (this.isNotRunning) {
try {
this.content = JSON.parse(this.report.content);
} catch (e) {
throw e;
}
this.loading = false;
this.$success("批量执行成功,请到报告页面查看详情!");
} else {
setTimeout(this.getReport, 2000)
}
} else {
this.loading = false;
this.$error(this.$t('api_report.not_exist'));
}
});
}
},
handleBatchExecute() {
this.infoDb = false;
let url = "/api/automation/run";
let url = "/api/automation/run/batch";
let run = {};
let scenarioIds = this.selection;
run.id = getUUID();
@ -207,8 +242,8 @@
run.projectId = getCurrentProjectID();
this.$post(url, run, response => {
let data = response.data;
this.runVisible = true;
this.reportId = run.id;
this.runVisible = false;
this.batchReportId = run.id;
});
},
selectAllChange() {

View File

@ -22,7 +22,7 @@
<span class="custom-tree-node father" @click="handleNodeSelect(node)">
<span v-if="data.isEdit" @click.stop>
<el-input @blur.stop="save(node, data)" v-model="data.name" class="name-input" size="mini"/>
<el-input @blur.stop="save(node, data)" v-model="data.name" class="name-input" size="mini" ref="nameInput"/>
</span>
<span v-if="!data.isEdit" class="node-icon">
@ -164,8 +164,9 @@ export default {
}
data.children.push(newChild);
this.edit(node, newChild);
node.expanded = true;
this.$nextTick(() => {
this.$refs.tree.setCurrentKey(data.id);
this.$refs.nameInput.focus();
});
},
save(node, data) {
@ -187,6 +188,10 @@ export default {
this.$set(data, 'isEdit', false);
},
remove(node, data) {
if (data.label === undefined) {
this.$refs.tree.remove(node);
return;
}
let tip = '确定删除节点 ' + data.label + ' 及其子节点下所有资源' + '';
// let info = this.$t("test_track.module.delete_confirm") + data.label + "" + this.$t("test_track.module.delete_all_resource") + "";
this.$alert(tip, "", {

@ -1 +1 @@
Subproject commit 010ad7a5f072a5e9d368c756a2473bbd20781433
Subproject commit 8cda5c873cd9985c97adb34efacf507167fa4182