feat(接口测试): 场景和接口支持禁用和启用

This commit is contained in:
chenjianxing 2020-08-19 15:41:14 +08:00
parent b04c573362
commit 478d6db83b
10 changed files with 115 additions and 39 deletions

View File

@ -15,4 +15,5 @@ public class Scenario {
private List<KeyValue> headers;
private List<Request> requests;
private DubboConfig dubboConfig;
private Boolean enable;
}

View File

@ -49,4 +49,6 @@ public class DubboRequest implements Request {
private BeanShellPreProcessor beanShellPreProcessor;
@JSONField(ordinal = 13)
private BeanShellPostProcessor beanShellPostProcessor;
@JSONField(ordinal = 14)
private Boolean enable;
}

View File

@ -41,4 +41,6 @@ public class HttpRequest implements Request {
private BeanShellPreProcessor beanShellPreProcessor;
@JSONField(ordinal = 12)
private BeanShellPostProcessor beanShellPostProcessor;
@JSONField(ordinal = 13)
private Boolean enable;
}

View File

@ -5,13 +5,13 @@
<ms-api-collapse v-model="activeName" @change="handleChange" accordion>
<draggable :list="scenarios" group="Scenario" class="scenario-draggable" ghost-class="scenario-ghost">
<ms-api-collapse-item v-for="(scenario, index) in scenarios" :key="index"
:title="scenario.name" :name="index">
:title="scenario.name" :name="index" :class="{'disable-scenario': !scenario.enable}">
<template slot="title">
<div class="scenario-name">
{{scenario.name}}
<span id="hint" v-if="!scenario.name">
{{$t('api_test.scenario.config')}}
</span>
{{$t('api_test.scenario.config')}}
</span>
</div>
<el-dropdown trigger="click" @command="handleCommand">
<span class="el-dropdown-link el-icon-more scenario-btn"/>
@ -22,6 +22,12 @@
<el-dropdown-item :disabled="isReadOnly" :command="{type:'delete', index:index}">
{{$t('api_test.scenario.delete')}}
</el-dropdown-item>
<el-dropdown-item v-if="scenario.enable" :disabled="isReadOnly" :command="{type:'disable', index:index}">
{{$t('api_test.scenario.disable')}}
</el-dropdown-item>
<el-dropdown-item v-if="!scenario.enable" :disabled="isReadOnly" :command="{type:'enable', index:index}">
{{$t('api_test.scenario.enable')}}
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>
@ -108,6 +114,12 @@ export default {
this.select(this.scenarios[0]);
}
},
disableScenario: function (index) {
this.scenarios[index].enable = false;
},
enableScenario: function (index) {
this.scenarios[index].enable = true;
},
handleChange: function (index) {
this.select(this.scenarios[index]);
},
@ -119,6 +131,12 @@ export default {
case "delete":
this.deleteScenario(command.index);
break;
case "disable":
this.disableScenario(command.index);
break;
case "enable":
this.enableScenario(command.index);
break;
}
},
select: function (obj, scenario) {
@ -203,9 +221,9 @@ export default {
width: 100%;
}
.scenario-name > #hint {
color: #8a8b8d;
}
/*.scenario-name > #hint {*/
/*color: #8a8b8d;*/
/*}*/
.scenario-btn {
text-align: center;
@ -241,4 +259,9 @@ export default {
.scenario-draggable {
background-color: #909399;
}
.disable-scenario >>> .el-collapse-item__header {
border-right: 2px solid #909399;
color: #8a8b8d;
}
</style>

View File

@ -113,6 +113,7 @@
<style scoped>
.el-collapse-item__header {
padding-left: 7px;
border-right: 2px solid #409eff;
}
.el-collapse-item__header.is-active {
@ -122,4 +123,5 @@
.el-collapse-item__content {
padding-bottom: 0;
}
</style>

View File

@ -2,7 +2,7 @@
<div class="request-container">
<draggable :list="this.scenario.requests" group="Request" class="request-draggable" ghost-class="request-ghost">
<div class="request-item" v-for="(request, index) in this.scenario.requests" :key="index" @click="select(request)"
:class="{'selected': isSelected(request)}">
:class="{'selected': isSelected(request), 'disable-request': !request.enable}">
<el-row type="flex" align="middle">
<div class="request-type">
{{request.showType()}}
@ -23,6 +23,12 @@
<el-dropdown-item :disabled="isReadOnly" :command="{type: 'delete', index: index}">
{{$t('api_test.request.delete')}}
</el-dropdown-item>
<el-dropdown-item v-if="request.enable" :disabled="isReadOnly" :command="{type: 'disable', index: index}">
{{$t('api_test.scenario.disable')}}
</el-dropdown-item>
<el-dropdown-item v-if="!request.enable" :disabled="isReadOnly" :command="{type: 'enable', index: index}">
{{$t('api_test.scenario.enable')}}
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
@ -70,7 +76,7 @@
computed: {
isSelected() {
return function (request) {
return this.selected.id === request.id;
return this.selected === request;
}
}
},
@ -89,6 +95,12 @@
let request = this.scenario.requests[index];
this.scenario.requests.push(new RequestFactory(request));
},
disableRequest: function (index) {
this.scenario.requests[index].enable = false;
},
enableRequest: function (index) {
this.scenario.requests[index].enable = true;
},
deleteRequest: function (index) {
this.scenario.requests.splice(index, 1);
if (this.scenario.requests.length === 0) {
@ -103,6 +115,12 @@
case "delete":
this.deleteRequest(command.index);
break;
case "disable":
this.disableRequest(command.index);
break;
case "enable":
this.enableRequest(command.index);
break;
}
},
select: function (request) {
@ -186,4 +204,17 @@
opacity: 0.5;
background-color: #909399;
}
.request-item.disable-request {
border-left-color: #909399;
}
.disable-request .request-type {
background-color: #909399;
}
.disable-request .request-method {
color: #909399;
}
</style>

View File

@ -207,6 +207,7 @@ export class Scenario extends BaseConfig {
this.dubboConfig = undefined;
this.environment = undefined;
this.enableCookieShare = false;
this.enable = true;
this.set(options);
this.sets({variables: KeyValue, headers: KeyValue, requests: RequestFactory}, options);
@ -304,6 +305,7 @@ export class HttpRequest extends Request {
this.debugReport = undefined;
this.beanShellPreProcessor = undefined;
this.beanShellPostProcessor = undefined;
this.enable = true;
this.set(options);
this.sets({parameters: KeyValue, headers: KeyValue}, options);
@ -383,6 +385,7 @@ export class DubboRequest extends Request {
this.debugReport = undefined;
this.beanShellPreProcessor = new BeanShellProcessor(options.beanShellPreProcessor);
this.beanShellPostProcessor = new BeanShellProcessor(options.beanShellPostProcessor);
this.enable = true;
this.sets({args: KeyValue, attachmentArgs: KeyValue}, options);
}
@ -807,44 +810,50 @@ class JMXGenerator {
addScenarios(testPlan, scenarios) {
scenarios.forEach(s => {
let scenario = s.clone();
let threadGroup = new ThreadGroup(scenario.name || "");
if (s.enable) {
let scenario = s.clone();
this.addScenarioVariables(threadGroup, scenario);
let threadGroup = new ThreadGroup(scenario.name || "");
this.addScenarioHeaders(threadGroup, scenario);
this.addScenarioVariables(threadGroup, scenario);
this.addScenarioCookieManager(threadGroup, scenario);
this.addScenarioHeaders(threadGroup, scenario);
scenario.requests.forEach(request => {
if (!request.isValid()) return;
let sampler;
this.addScenarioCookieManager(threadGroup, scenario);
if (request instanceof DubboRequest) {
sampler = new DubboSample(request.name || "", new JMXDubboRequest(request, scenario.dubboConfig));
}
scenario.requests.forEach(request => {
if (request.enable) {
if (!request.isValid()) return;
let sampler;
if (request instanceof HttpRequest) {
sampler = new HTTPSamplerProxy(request.name || "", new JMXHttpRequest(request, scenario.environment));
this.addRequestHeader(sampler, request);
if (request.method.toUpperCase() === 'GET') {
this.addRequestArguments(sampler, request);
} else {
this.addRequestBody(sampler, request);
if (request instanceof DubboRequest) {
sampler = new DubboSample(request.name || "", new JMXDubboRequest(request, scenario.dubboConfig));
}
if (request instanceof HttpRequest) {
sampler = new HTTPSamplerProxy(request.name || "", new JMXHttpRequest(request, scenario.environment));
this.addRequestHeader(sampler, request);
if (request.method.toUpperCase() === 'GET') {
this.addRequestArguments(sampler, request);
} else {
this.addRequestBody(sampler, request);
}
}
this.addBeanShellProcessor(sampler, request);
this.addRequestAssertion(sampler, request);
this.addRequestExtractor(sampler, request);
threadGroup.put(sampler);
}
}
})
this.addBeanShellProcessor(sampler, request);
testPlan.put(threadGroup);
}
this.addRequestAssertion(sampler, request);
this.addRequestExtractor(sampler, request);
threadGroup.put(sampler);
})
testPlan.put(threadGroup);
})
}

View File

@ -397,7 +397,9 @@ export default {
headers: "Headers",
kv_description: "Variables are available for all requests",
copy: "Copy scenario",
delete: "Delete scenario"
delete: "Delete scenario",
disable: "Disable",
enable: "Enable"
},
request: {
copy: "Copy request",

View File

@ -397,7 +397,9 @@ export default {
headers: "请求头",
kv_description: "所有请求可以使用自定义变量",
copy: "复制场景",
delete: "删除场景"
delete: "删除场景",
disable: "禁用",
enable: "启用"
},
request: {
copy: "复制请求",

View File

@ -396,7 +396,9 @@ export default {
headers: "請求頭",
kv_description: "所有請求可以使用自定義變數",
copy: "複製場景",
delete: "删除場景"
delete: "删除場景",
disable: "禁用",
enable: "啟用"
},
request: {
copy: "複製請求",