feat(接口自动化): 循环控制器 结果处理
This commit is contained in:
parent
7412faa7d9
commit
33cd6b37e8
|
@ -7,4 +7,6 @@ public class CountController {
|
||||||
private int loops;
|
private int loops;
|
||||||
private int interval;
|
private int interval;
|
||||||
private boolean proceed;
|
private boolean proceed;
|
||||||
|
private Object requestResult;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,4 +7,6 @@ public class MsForEachController {
|
||||||
private String inputVal;
|
private String inputVal;
|
||||||
private String returnVal;
|
private String returnVal;
|
||||||
private String interval;
|
private String interval;
|
||||||
|
private Object requestResult;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,4 +8,5 @@ public class MsWhileController {
|
||||||
private String operator;
|
private String operator;
|
||||||
private String value;
|
private String value;
|
||||||
private int timeout;
|
private int timeout;
|
||||||
|
private Object requestResult;
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,6 @@
|
||||||
if (this.isNotRunning) {
|
if (this.isNotRunning) {
|
||||||
try {
|
try {
|
||||||
this.content = JSON.parse(this.report.content);
|
this.content = JSON.parse(this.report.content);
|
||||||
console.log(this.content)
|
|
||||||
if (!this.content) {
|
if (!this.content) {
|
||||||
this.content = {scenarios: []};
|
this.content = {scenarios: []};
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<div class="header-right" @click.stop>
|
<div class="header-right" @click.stop>
|
||||||
|
<slot name="message"></slot>
|
||||||
<el-switch v-model="data.enable" class="enable-switch"/>
|
<el-switch v-model="data.enable" class="enable-switch"/>
|
||||||
<slot name="button"></slot>
|
<slot name="button"></slot>
|
||||||
<el-button size="mini" icon="el-icon-copy-document" circle @click="copyRow"/>
|
<el-button size="mini" icon="el-icon-copy-document" circle @click="copyRow"/>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
:draggable="true"
|
:draggable="true"
|
||||||
color="#02A7F0"
|
color="#02A7F0"
|
||||||
background-color="#F4F4F5"
|
background-color="#F4F4F5"
|
||||||
:title="$t('api_test.automation.loop_controller')">
|
:title="$t('api_test.automation.loop_controller')" v-loading="loading">
|
||||||
|
|
||||||
<template v-slot:headerLeft>
|
<template v-slot:headerLeft>
|
||||||
<i class="icon el-icon-arrow-right" :class="{'is-active': controller.active}" @click="active(controller)" style="margin-right: 10px"/>
|
<i class="icon el-icon-arrow-right" :class="{'is-active': controller.active}" @click="active(controller)" style="margin-right: 10px"/>
|
||||||
|
@ -16,6 +16,15 @@
|
||||||
<el-radio @change="changeRadio" class="ms-radio" v-model="controller.loopType" label="WHILE">{{$t('loop.while')}}</el-radio>
|
<el-radio @change="changeRadio" class="ms-radio" v-model="controller.loopType" label="WHILE">{{$t('loop.while')}}</el-radio>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template v-slot:message>
|
||||||
|
<span v-if="requestResult && requestResult.scenarios && requestResult.scenarios.length > 0 " style="color: #8c939d;margin-right: 10px">
|
||||||
|
循环{{requestResult.scenarios.length}}次 成功{{success}}次 失败{{error}}次
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-slot:button>
|
||||||
|
<el-button @click="runDebug" :tip="$t('api_test.run')" icon="el-icon-video-play" style="background-color: #409EFF;color: white;" size="mini" circle/>
|
||||||
|
</template>
|
||||||
<div v-if="controller.loopType==='LOOP_COUNT'" draggable>
|
<div v-if="controller.loopType==='LOOP_COUNT'" draggable>
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col :span="8">
|
<el-col :span="8">
|
||||||
|
@ -69,17 +78,34 @@
|
||||||
<span class="ms-span ms-radio">ms</span>
|
<span class="ms-span ms-radio">ms</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<p class="tip">{{$t('api_test.definition.request.res_param')}} </p>
|
||||||
|
<el-tabs v-model="activeName">
|
||||||
|
<el-tab-pane :label="item.name" :name="item.name" v-for="(item,index) in requestResult.scenarios" :key="index">
|
||||||
|
<div v-for="(result,i) in item.requestResults" :key="i" style="margin-bottom: 5px">
|
||||||
|
<api-response-component :result="result"/>
|
||||||
|
</div>
|
||||||
|
</el-tab-pane>
|
||||||
|
</el-tabs>
|
||||||
|
|
||||||
|
<ms-run :debug="true" :environment="currentEnvironmentId" :reportId="reportId" :run-data="debugData"
|
||||||
|
@runRefresh="runRefresh" ref="runTest"/>
|
||||||
|
|
||||||
</api-base-component>
|
</api-base-component>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import ApiBaseComponent from "../common/ApiBaseComponent";
|
import ApiBaseComponent from "../common/ApiBaseComponent";
|
||||||
|
import ApiResponseComponent from "./ApiResponseComponent";
|
||||||
|
import MsRun from "../DebugRun";
|
||||||
|
import {getUUID, getCurrentProjectID} from "@/common/js/utils";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "MsLoopController",
|
name: "MsLoopController",
|
||||||
components: {ApiBaseComponent},
|
components: {ApiBaseComponent, ApiResponseComponent, MsRun},
|
||||||
props: {
|
props: {
|
||||||
controller: {},
|
controller: {},
|
||||||
|
currentEnvironmentId: String,
|
||||||
|
currentScenario: {},
|
||||||
node: {},
|
node: {},
|
||||||
index: Object,
|
index: Object,
|
||||||
draggable: {
|
draggable: {
|
||||||
|
@ -87,9 +113,19 @@
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
created() {
|
||||||
|
this.initResult();
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
loading: false,
|
loading: false,
|
||||||
|
activeName: "first",
|
||||||
|
requestResult: {responseResult: {}},
|
||||||
|
success: 0,
|
||||||
|
error: 0,
|
||||||
|
debugData: {},
|
||||||
|
report: [],
|
||||||
|
reportId: "",
|
||||||
operators: {
|
operators: {
|
||||||
EQ: {
|
EQ: {
|
||||||
label: "commons.adv_search.operators.equals",
|
label: "commons.adv_search.operators.equals",
|
||||||
|
@ -127,6 +163,25 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
initResult() {
|
||||||
|
if (this.controller) {
|
||||||
|
switch (this.controller.loopType) {
|
||||||
|
case "LOOP_COUNT":
|
||||||
|
this.requestResult = this.controller.countController && this.controller.countController.requestResult ? this.controller.countController.requestResult : {};
|
||||||
|
break;
|
||||||
|
case "FOREACH":
|
||||||
|
this.requestResult = this.controller.forEachController && this.controller.forEachController.requestResult ? this.controller.forEachController.requestResult : {};
|
||||||
|
break;
|
||||||
|
case "WHILE":
|
||||||
|
this.requestResult = this.controller.whileController && this.controller.whileController.requestResult ? this.controller.whileController.requestResult : {};
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.getFails();
|
||||||
|
this.activeName = this.requestResult && this.requestResult.scenarios && this.requestResult.scenarios.length > 0 ? this.requestResult.scenarios[0].name : "";
|
||||||
|
},
|
||||||
switchChange() {
|
switchChange() {
|
||||||
if (this.controller.hashTree && this.controller.hashTree.length > 1) {
|
if (this.controller.hashTree && this.controller.hashTree.length > 1) {
|
||||||
this.$warning("当前循环下超过一个请求,不能关闭状态")
|
this.$warning("当前循环下超过一个请求,不能关闭状态")
|
||||||
|
@ -134,6 +189,26 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
runDebug() {
|
||||||
|
/*触发执行操作*/
|
||||||
|
if (!this.currentEnvironmentId) {
|
||||||
|
this.$error(this.$t('api_test.environment.select_environment'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this.controller.hashTree || this.controller.hashTree.length < 1) {
|
||||||
|
this.$warning("当前循环下没有请求,不能执行")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.loading = true;
|
||||||
|
|
||||||
|
this.debugData = {
|
||||||
|
id: this.currentScenario.id, name: this.currentScenario.name, type: "scenario",
|
||||||
|
variables: this.currentScenario.variables, referenced: 'Created', enableCookieShare: this.enableCookieShare,
|
||||||
|
environmentId: this.currentEnvironmentId, hashTree: [this.controller]
|
||||||
|
};
|
||||||
|
this.reportId = getUUID().substring(0, 8);
|
||||||
|
},
|
||||||
|
|
||||||
remove() {
|
remove() {
|
||||||
this.$emit('remove', this.controller, this.node);
|
this.$emit('remove', this.controller, this.node);
|
||||||
},
|
},
|
||||||
|
@ -146,6 +221,7 @@
|
||||||
},
|
},
|
||||||
changeRadio() {
|
changeRadio() {
|
||||||
this.controller.active = true;
|
this.controller.active = true;
|
||||||
|
this.initResult();
|
||||||
this.reload();
|
this.reload();
|
||||||
},
|
},
|
||||||
change(value) {
|
change(value) {
|
||||||
|
@ -159,11 +235,77 @@
|
||||||
this.loading = false
|
this.loading = false
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
runRefresh() {
|
||||||
|
this.getReport();
|
||||||
|
},
|
||||||
|
getFails() {
|
||||||
|
this.error = 0;
|
||||||
|
this.success = 0;
|
||||||
|
if (this.requestResult.scenarios) {
|
||||||
|
this.requestResult.scenarios.forEach((scenario) => {
|
||||||
|
if (scenario.requestResults) {
|
||||||
|
scenario.requestResults.forEach(item => {
|
||||||
|
if (item.error > 0) {
|
||||||
|
this.error++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.success = this.requestResult.scenarios.length - this.error;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getReport() {
|
||||||
|
if (this.reportId) {
|
||||||
|
let url = "/api/scenario/report/get/" + this.reportId;
|
||||||
|
this.$get(url, response => {
|
||||||
|
this.report = response.data || {};
|
||||||
|
if (response.data) {
|
||||||
|
if (this.isNotRunning) {
|
||||||
|
try {
|
||||||
|
this.requestResult = JSON.parse(this.report.content);
|
||||||
|
this.controller.requestResult = this.requestResult;
|
||||||
|
switch (this.controller.loopType) {
|
||||||
|
case "LOOP_COUNT":
|
||||||
|
this.controller.countController.requestResult = this.requestResult;
|
||||||
|
break;
|
||||||
|
case "FOREACH":
|
||||||
|
this.controller.forEachController.requestResult = this.requestResult;
|
||||||
|
break;
|
||||||
|
case "WHILE":
|
||||||
|
this.controller.whileController.requestResult = this.requestResult;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
this.getFails();
|
||||||
|
if (!this.requestResult) {
|
||||||
|
this.requestResult = {scenarios: []};
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
this.loading = false;
|
||||||
|
this.activeName = this.requestResult && this.requestResult.scenarios ? this.requestResult.scenarios[0].name : "";
|
||||||
|
} else {
|
||||||
|
setTimeout(this.getReport, 2000)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.loading = false;
|
||||||
|
this.$error(this.$t('api_report.not_exist'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
hasEmptyOperator() {
|
hasEmptyOperator() {
|
||||||
return !!this.controller.operator && this.controller.operator.indexOf("empty") > 0;
|
return !!this.controller.operator && this.controller.operator.indexOf("empty") > 0;
|
||||||
|
},
|
||||||
|
isNotRunning() {
|
||||||
|
return "Running" !== this.report.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -180,6 +322,14 @@
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tip {
|
||||||
|
padding: 3px 5px;
|
||||||
|
font-size: 16px;
|
||||||
|
border-radius: 4px;
|
||||||
|
border-left: 4px solid #783887;
|
||||||
|
margin: 20px 0;
|
||||||
|
}
|
||||||
|
|
||||||
.icon.is-active {
|
.icon.is-active {
|
||||||
transform: rotate(90deg);
|
transform: rotate(90deg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="metric-container">
|
<div class="metric-container">
|
||||||
<el-row type="flex">
|
<el-row type="flex">
|
||||||
|
<el-col>
|
||||||
|
<div style="font-size: 14px;color: #AAAAAA;float: left">请求名称 :</div>
|
||||||
|
<div style="font-size: 14px;color:#61C550;margin-top:2px;margin-left:10px;float: left">{{response.name}}</div>
|
||||||
|
</el-col>
|
||||||
<el-col>
|
<el-col>
|
||||||
<div style="font-size: 14px;color: #AAAAAA;float: left">{{$t('api_report.response_code')}} :</div>
|
<div style="font-size: 14px;color: #AAAAAA;float: left">{{$t('api_report.response_code')}} :</div>
|
||||||
<div style="font-size: 14px;color:#61C550;margin-top:2px;margin-left:10px;float: left">{{response.responseResult.responseCode ? response.responseResult.responseCode :'0'}}</div>
|
<div style="font-size: 14px;color:#61C550;margin-top:2px;margin-left:10px;float: left">{{response.responseResult.responseCode ? response.responseResult.responseCode :'0'}}</div>
|
||||||
|
|
|
@ -1024,9 +1024,9 @@ export class LoopController extends Controller {
|
||||||
this.type = "LoopController";
|
this.type = "LoopController";
|
||||||
this.active = false;
|
this.active = false;
|
||||||
this.loopType = "LOOP_COUNT";
|
this.loopType = "LOOP_COUNT";
|
||||||
this.countController = {loops: 0, interval: 0, proceed: true};
|
this.countController = {loops: 0, interval: 0, proceed: true, requestResult: {}};
|
||||||
this.forEachController = {inputVal: "", returnVal: "", interval: 0};
|
this.forEachController = {inputVal: "", returnVal: "", interval: 0, requestResult: {}};
|
||||||
this.whileController = {variable: "", operator: "", value: "", timeout: 0};
|
this.whileController = {variable: "", operator: "", value: "", timeout: 0, requestResult: {}};
|
||||||
this.hashTree = [];
|
this.hashTree = [];
|
||||||
this.set(options);
|
this.set(options);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue