fix (接口自动化): 单条场景执行支持导出及生成测试报告
This commit is contained in:
parent
737f75eb7b
commit
9ebb834878
|
@ -20,6 +20,7 @@ import io.metersphere.controller.request.ScheduleRequest;
|
||||||
import io.metersphere.log.annotation.MsAuditLog;
|
import io.metersphere.log.annotation.MsAuditLog;
|
||||||
import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest;
|
import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest;
|
||||||
import io.metersphere.track.request.testplan.FileOperationRequest;
|
import io.metersphere.track.request.testplan.FileOperationRequest;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
@ -182,7 +183,9 @@ public class ApiAutomationController {
|
||||||
@PostMapping(value = "/run")
|
@PostMapping(value = "/run")
|
||||||
@MsAuditLog(module = "api_automation", type = OperLogConstants.EXECUTE, content = "#msClass.getLogDetails(#request.ids)", msClass = ApiAutomationService.class)
|
@MsAuditLog(module = "api_automation", type = OperLogConstants.EXECUTE, content = "#msClass.getLogDetails(#request.ids)", msClass = ApiAutomationService.class)
|
||||||
public String run(@RequestBody RunScenarioRequest request) {
|
public String run(@RequestBody RunScenarioRequest request) {
|
||||||
request.setExecuteType(ExecuteType.Completed.name());
|
if(!StringUtils.equals(request.getExecuteType(),ExecuteType.Saved.name())){
|
||||||
|
request.setExecuteType(ExecuteType.Completed.name());
|
||||||
|
}
|
||||||
request.setTriggerMode(TriggerMode.MANUAL.name());
|
request.setTriggerMode(TriggerMode.MANUAL.name());
|
||||||
request.setRunMode(ApiRunMode.SCENARIO.name());
|
request.setRunMode(ApiRunMode.SCENARIO.name());
|
||||||
return apiAutomationService.run(request);
|
return apiAutomationService.run(request);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<header class="report-header">
|
<header class="report-header">
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col>
|
<el-col>
|
||||||
<!-- <span v-if="!debug"><el-input size="mini" style="width: 200px" v-model="report.name"/> </span>-->
|
<!-- <span v-if="!debug"><el-input size="mini" style="width: 200px" v-model="report.name"/> </span>-->
|
||||||
<span v-if="!debug">
|
<span v-if="!debug">
|
||||||
<el-input v-if="nameIsEdit" size="mini" @blur="nameIsEdit = false" style="width: 200px" v-model="report.name"/>
|
<el-input v-if="nameIsEdit" size="mini" @blur="nameIsEdit = false" style="width: 200px" v-model="report.name"/>
|
||||||
<span v-else>
|
<span v-else>
|
||||||
|
@ -17,12 +17,12 @@
|
||||||
</span>
|
</span>
|
||||||
<span class="time"> {{ report.createTime | timestampFormatDate }}</span>
|
<span class="time"> {{ report.createTime | timestampFormatDate }}</span>
|
||||||
|
|
||||||
<el-button v-if="!debug" v-permission="['PROJECT_API_REPORT:READ+EXPORT']" :disabled="isReadOnly" class="export-button" plain type="primary" size="mini" @click="handleExport(report.name)" style="margin-right: 10px">
|
<el-button v-if="!debug || exportFlag" v-permission="['PROJECT_API_REPORT:READ+EXPORT']" :disabled="isReadOnly" class="export-button" plain type="primary" size="mini" @click="handleExport(report.name)" style="margin-right: 10px">
|
||||||
{{$t('test_track.plan_view.export_report')}}
|
{{ $t('test_track.plan_view.export_report') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
|
|
||||||
<el-button v-if="!debug" :disabled="isReadOnly" class="export-button" plain type="primary" size="mini" @click="handleSave(report.name)" style="margin-right: 10px">
|
<el-button v-if="!debug" :disabled="isReadOnly" class="export-button" plain type="primary" size="mini" @click="handleSave(report.name)" style="margin-right: 10px">
|
||||||
{{$t('commons.save')}}
|
{{ $t('commons.save') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
|
|
||||||
</el-col>
|
</el-col>
|
||||||
|
@ -32,56 +32,60 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "MsApiReportViewHeader",
|
name: "MsApiReportViewHeader",
|
||||||
props: {
|
props: {
|
||||||
report: {},
|
report: {},
|
||||||
debug: Boolean,
|
debug: Boolean,
|
||||||
|
exportFlag: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
path() {
|
||||||
|
return "/api/test/edit?id=" + this.report.testId;
|
||||||
},
|
},
|
||||||
computed: {
|
scenarioId() {
|
||||||
path() {
|
if (typeof this.report.scenarioId === 'string') {
|
||||||
return "/api/test/edit?id=" + this.report.testId;
|
return this.report.scenarioId;
|
||||||
},
|
} else {
|
||||||
scenarioId(){
|
return "";
|
||||||
if(typeof this.report.scenarioId === 'string'){
|
|
||||||
return this.report.scenarioId;
|
|
||||||
}else {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
isSingleScenario(){
|
|
||||||
try {
|
|
||||||
JSON.parse(this.report.scenarioId);
|
|
||||||
return false;
|
|
||||||
} catch(e){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
isSingleScenario() {
|
||||||
return {
|
try {
|
||||||
isReadOnly: false,
|
JSON.parse(this.report.scenarioId);
|
||||||
nameIsEdit:false,
|
return false;
|
||||||
}
|
} catch (e) {
|
||||||
},
|
return true;
|
||||||
created() {
|
|
||||||
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
handleExport(name) {
|
|
||||||
this.$emit('reportExport', name);
|
|
||||||
},
|
|
||||||
handleSave(name) {
|
|
||||||
this.$emit('reportSave', name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
isReadOnly: false,
|
||||||
|
nameIsEdit: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
handleExport(name) {
|
||||||
|
this.$emit('reportExport', name);
|
||||||
|
},
|
||||||
|
handleSave(name) {
|
||||||
|
this.$emit('reportSave', name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
||||||
.export-button {
|
.export-button {
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<ms-main-container>
|
<ms-main-container>
|
||||||
<el-card>
|
<el-card>
|
||||||
<section class="report-container">
|
<section class="report-container">
|
||||||
<ms-api-report-view-header :debug="debug" :report="report" @reportExport="handleExport"/>
|
<ms-api-report-view-header :debug="debug" :export-flag="exportFlag" :report="report" @reportExport="handleExport" @reportSave="handleSave"/>
|
||||||
<main>
|
<main>
|
||||||
<ms-metric-chart :content="content" :totalTime="totalTime" v-if="!loading"/>
|
<ms-metric-chart :content="content" :totalTime="totalTime" v-if="!loading"/>
|
||||||
<div>
|
<div>
|
||||||
|
@ -61,8 +61,8 @@ export default {
|
||||||
failsTreeNodes: [],
|
failsTreeNodes: [],
|
||||||
totalTime: 0,
|
totalTime: 0,
|
||||||
isRequestResult: false,
|
isRequestResult: false,
|
||||||
startTime : 99991611737506593,
|
startTime: 99991611737506593,
|
||||||
endTime : 0,
|
endTime: 0,
|
||||||
request: {},
|
request: {},
|
||||||
isActive: false,
|
isActive: false,
|
||||||
scenarioName: null,
|
scenarioName: null,
|
||||||
|
@ -71,6 +71,7 @@ export default {
|
||||||
fullTreeNodes: [],
|
fullTreeNodes: [],
|
||||||
debugResult: new Map,
|
debugResult: new Map,
|
||||||
scenarioMap: new Map,
|
scenarioMap: new Map,
|
||||||
|
exportFlag:false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
activated() {
|
activated() {
|
||||||
|
@ -247,7 +248,7 @@ export default {
|
||||||
this.$success(this.$t('schedule.event_success'));
|
this.$success(this.$t('schedule.event_success'));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getTransaction(transRequests,resMap) {
|
getTransaction(transRequests, resMap) {
|
||||||
transRequests.forEach(subItem => {
|
transRequests.forEach(subItem => {
|
||||||
if (subItem.method === 'Request') {
|
if (subItem.method === 'Request') {
|
||||||
this.getTransaction(subItem.subRequestResults, resMap);
|
this.getTransaction(subItem.subRequestResults, resMap);
|
||||||
|
@ -365,6 +366,7 @@ export default {
|
||||||
})
|
})
|
||||||
this.formatTree(array, this.failsTreeNodes);
|
this.formatTree(array, this.failsTreeNodes);
|
||||||
this.recursiveSorting(this.failsTreeNodes);
|
this.recursiveSorting(this.failsTreeNodes);
|
||||||
|
this.exportFlag = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
formatTree(array, tree) {
|
formatTree(array, tree) {
|
||||||
|
@ -459,6 +461,22 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
handleSave() {
|
||||||
|
if (!this.report.name) {
|
||||||
|
this.$warning(this.$t('api_test.automation.report_name_info'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.loading = true;
|
||||||
|
this.report.projectId = this.projectId;
|
||||||
|
let url = "/api/scenario/report/update";
|
||||||
|
this.result = this.$post(url, this.report, response => {
|
||||||
|
this.$success(this.$t('commons.save_success'));
|
||||||
|
this.loading = false;
|
||||||
|
this.$emit('refresh');
|
||||||
|
}, error => {
|
||||||
|
this.loading = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
projectId() {
|
projectId() {
|
||||||
|
@ -486,7 +504,7 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
/deep/ .el-card__body {
|
/deep/ .el-card__body {
|
||||||
padding: 0px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.report-header a {
|
.report-header a {
|
||||||
|
|
|
@ -836,6 +836,7 @@ export default {
|
||||||
run.id = getUUID();
|
run.id = getUUID();
|
||||||
run.projectId = this.projectId;
|
run.projectId = this.projectId;
|
||||||
run.ids = scenarioIds;
|
run.ids = scenarioIds;
|
||||||
|
run.executeType = "Saved";
|
||||||
this.$post(url, run, response => {
|
this.$post(url, run, response => {
|
||||||
this.runVisible = true;
|
this.runVisible = true;
|
||||||
this.reportId = run.id;
|
this.reportId = run.id;
|
||||||
|
|
Loading…
Reference in New Issue