From 6743dac777e1a17e9c7bd9f308886e6079019869 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Fri, 25 Jun 2021 19:06:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E8=8E=B7=E5=8F=96=E5=AE=9E=E6=97=B6=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E6=AD=A5=E9=AA=A4=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../APIScenarioReportController.java | 5 + .../api/service/MsResultService.java | 8 +- .../automation/scenario/EditApiScenario.vue | 365 +++++++----------- .../scenario/common/ApiBaseComponent.vue | 8 +- .../scenario/component/ApiComponent.vue | 96 +++-- .../component/ApiScenarioComponent.vue | 301 ++++++++------- .../scenario/component/IfController.vue | 25 ++ .../scenario/component/LoopController.vue | 25 ++ .../scenario/maximize/MaximizeScenario.vue | 20 + .../scenario/maximize/ScenarioHeader.vue | 362 +++++++++-------- .../api/automation/scenario/menu/Menu.js | 182 +++++++++ 11 files changed, 820 insertions(+), 577 deletions(-) create mode 100644 frontend/src/business/components/api/automation/scenario/menu/Menu.js diff --git a/backend/src/main/java/io/metersphere/api/controller/APIScenarioReportController.java b/backend/src/main/java/io/metersphere/api/controller/APIScenarioReportController.java index c3531f219b..ef9dd352a8 100644 --- a/backend/src/main/java/io/metersphere/api/controller/APIScenarioReportController.java +++ b/backend/src/main/java/io/metersphere/api/controller/APIScenarioReportController.java @@ -62,4 +62,9 @@ public class APIScenarioReportController { return resultService.getResult(reportId); } + @GetMapping("/remove/real/{reportId}") + public void removeRealReport(@PathVariable String reportId) { + resultService.delete(reportId); + } + } diff --git a/backend/src/main/java/io/metersphere/api/service/MsResultService.java b/backend/src/main/java/io/metersphere/api/service/MsResultService.java index 8d8eaa6cc2..50b6af79a0 100644 --- a/backend/src/main/java/io/metersphere/api/service/MsResultService.java +++ b/backend/src/main/java/io/metersphere/api/service/MsResultService.java @@ -38,8 +38,10 @@ public class MsResultService { if (testResult == null) { testResult = new TestResult(); } - if(result.getResponseCode().equals(MsResultCollector.TEST_END)){ - + if (result.getResponseCode().equals(MsResultCollector.TEST_END)) { + testResult.setEnd(true); + this.cache.put(key, testResult); + return; } testResult.setTestId(key); testResult.setConsole(getJmeterLogger(key, false)); @@ -50,7 +52,7 @@ public class MsResultService { testResult.getScenarios().addAll(scenarios.values()); testResult.getScenarios().sort(Comparator.comparing(ScenarioResult::getId)); - + System.out.println(key + "=======" + result.getURL()); this.cache.put(key, testResult); } diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 4b2abc9d1b..5ed072ee89 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -136,31 +136,29 @@ {{ $t('commons.failure_continues') }} - - - - - - - - - - - {{ $t('api_test.request.debug') }} - - - - - - - + +
+ + + {{ $t('api_test.request.debug') }} + + {{ $t('test_track.case.steps') }} + + + 执行中 + + + + + + +
@@ -179,7 +177,7 @@
- 354 ms 请求 10 成功 8 失败 2 + {{ reqTotalTime }} ms 请求 {{ reqTotal }} 成功 {{ reqSuccess }} 失败 {{ reqError }}
+ :req-error="reqError" :req-success="reqSuccess" :req-total="reqTotal" :req-total-time="reqTotalTime" + :currentScenario="currentScenario" :type="type" :debug="debug" :reloadDebug="reloadDebug" :stepReEnable="stepEnable" ref="maximizeScenario" @openScenario="openScenario"/> @@ -274,16 +274,7 @@ diff --git a/frontend/src/business/components/api/automation/scenario/component/IfController.vue b/frontend/src/business/components/api/automation/scenario/component/IfController.vue index d05bb14b16..6b54d488fe 100644 --- a/frontend/src/business/components/api/automation/scenario/component/IfController.vue +++ b/frontend/src/business/components/api/automation/scenario/component/IfController.vue @@ -23,6 +23,13 @@ + @@ -88,6 +95,16 @@ } }, methods: { + getCode() { + if (this.node && this.node.data.debug) { + if (this.node.data.code && this.node.data.code === 'error') { + return 'error'; + } else { + return 'success'; + } + } + return ''; + }, remove() { this.$emit('remove', this.controller, this.node); }, @@ -118,4 +135,12 @@ width: 15%; margin-left: 5px; } + + .ms-req-error { + color: #F56C6C; + } + + .ms-req-success { + color: #67C23A; + } diff --git a/frontend/src/business/components/api/automation/scenario/component/LoopController.vue b/frontend/src/business/components/api/automation/scenario/component/LoopController.vue index fc580719af..ad205602c8 100644 --- a/frontend/src/business/components/api/automation/scenario/component/LoopController.vue +++ b/frontend/src/business/components/api/automation/scenario/component/LoopController.vue @@ -69,6 +69,14 @@ ms + + @@ -151,6 +159,16 @@ }; }, methods: { + getCode() { + if (this.node && this.node.data.debug) { + if (this.node.data.code && this.node.data.code === 'error') { + return 'error'; + } else { + return 'success'; + } + } + return ''; + }, initResult() { if (this.controller) { switch (this.controller.loopType) { @@ -363,6 +381,13 @@ .icon.is-active { transform: rotate(90deg); } + .ms-req-error { + color: #F56C6C; + } + + .ms-req-success { + color: #67C23A; + } /deep/ .el-radio { margin-right: 5px; diff --git a/frontend/src/business/components/api/automation/scenario/maximize/MaximizeScenario.vue b/frontend/src/business/components/api/automation/scenario/maximize/MaximizeScenario.vue index bf3eeb7cfa..9ea098c485 100644 --- a/frontend/src/business/components/api/automation/scenario/maximize/MaximizeScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/maximize/MaximizeScenario.vue @@ -17,6 +17,10 @@ + + {{ reqTotalTime }} ms 请求 {{ reqTotal }} 成功 {{ reqSuccess }} 失败 {{ reqError }} + + diff --git a/frontend/src/business/components/api/automation/scenario/maximize/ScenarioHeader.vue b/frontend/src/business/components/api/automation/scenario/maximize/ScenarioHeader.vue index 7734c6a8bc..742d496bc6 100644 --- a/frontend/src/business/components/api/automation/scenario/maximize/ScenarioHeader.vue +++ b/frontend/src/business/components/api/automation/scenario/maximize/ScenarioHeader.vue @@ -5,15 +5,15 @@ - {{currentScenario.name}} + {{ currentScenario.name }} - {{$t('api_test.automation.step_total')}}:{{scenarioDefinition.length}} + {{ $t('api_test.automation.step_total') }}:{{ scenarioDefinition.length }} - {{$t('api_test.automation.scenario_total')}} - :{{varSize }} + {{ $t('api_test.automation.scenario_total') }} + :{{ varSize }} @@ -25,10 +25,13 @@ @showPopover="showPopover" :project-list="projectList" ref="envPopover" class="ms-right" :result="envResult"/> - {{ $t('api_test.request.debug') }} - - + + {{ $t('api_test.request.debug') }} + + {{ $t('test_track.case.steps') }} + + + 执行中 @@ -38,185 +41,206 @@ diff --git a/frontend/src/business/components/api/automation/scenario/menu/Menu.js b/frontend/src/business/components/api/automation/scenario/menu/Menu.js new file mode 100644 index 0000000000..0537eb126b --- /dev/null +++ b/frontend/src/business/components/api/automation/scenario/menu/Menu.js @@ -0,0 +1,182 @@ +import {ELEMENT_TYPE} from "@/business/components/api/automation/scenario/Setting"; +import {Assertions, ConstantTimer, Extract, IfController, JSR223Processor, LoopController, TransactionController} from "@/business/components/api/definition/model/ApiTestModel"; + +export function buttons() { + let buttons = [ + { + title: this.$t('api_test.definition.request.extract_param'), + show: this.showButton("Extract"), + titleColor: "#015478", + titleBgColor: "#E6EEF2", + icon: "colorize", + click: () => { + this.addComponent('Extract') + } + }, + { + title: this.$t('api_test.definition.request.post_script'), + show: this.showButton("JSR223PostProcessor"), + titleColor: "#783887", + titleBgColor: "#F2ECF3", + icon: "skip_next", + click: () => { + this.addComponent('JSR223PostProcessor') + } + }, + { + title: this.$t('api_test.definition.request.pre_script'), + show: this.showButton("JSR223PreProcessor"), + titleColor: "#B8741A", + titleBgColor: "#F9F1EA", + icon: "skip_previous", + click: () => { + this.addComponent('JSR223PreProcessor') + } + }, + { + title: this.$t('api_test.automation.customize_script'), + show: this.showButton("JSR223Processor"), + titleColor: "#7B4D12", + titleBgColor: "#F1EEE9", + icon: "code", + click: () => { + this.addComponent('JSR223Processor') + } + }, + { + title: this.$t('api_test.automation.if_controller'), + show: this.showButton("IfController"), + titleColor: "#E6A23C", + titleBgColor: "#FCF6EE", + icon: "alt_route", + click: () => { + this.addComponent('IfController') + } + }, + { + title: this.$t('api_test.automation.loop_controller'), + show: this.showButton("LoopController"), + titleColor: "#02A7F0", + titleBgColor: "#F4F4F5", + icon: "next_plan", + click: () => { + this.addComponent('LoopController') + } + }, + { + title: this.$t('api_test.automation.transcation_controller'), + show: this.showButton("TransactionController"), + titleColor: "#6D317C", + titleBgColor: "#F4F4F5", + icon: "alt_route", + click: () => { + this.addComponent('TransactionController') + } + }, + { + title: this.$t('api_test.automation.wait_controller'), + show: this.showButton("ConstantTimer"), + titleColor: "#67C23A", + titleBgColor: "#F2F9EE", + icon: "access_time", + click: () => { + this.addComponent('ConstantTimer') + } + }, + { + title: this.$t('api_test.definition.request.assertions_rule'), + show: this.showButton("Assertions"), + titleColor: "#A30014", + titleBgColor: "#F7E6E9", + icon: "next_plan", + click: () => { + this.addComponent('Assertions') + } + }, + { + title: this.$t('api_test.automation.customize_req'), + show: this.showButton("CustomizeReq"), + titleColor: "#008080", + titleBgColor: "#EBF2F2", + icon: "tune", + click: () => { + this.addComponent('CustomizeReq') + } + }, + { + title: this.$t('api_test.automation.scenario_import'), + show: this.showButton("scenario"), + titleColor: "#606266", + titleBgColor: "#F4F4F5", + icon: "movie", + click: () => { + this.addComponent('scenario') + } + }, + { + title: this.$t('api_test.automation.api_list_import'), + show: this.showButton("HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler"), + titleColor: "#F56C6C", + titleBgColor: "#FCF1F1", + icon: "api", + click: this.apiListImport + } + ]; + return buttons.filter(btn => btn.show); +} + +export function setComponent(type, _this) { + switch (type) { + case ELEMENT_TYPE.IfController: + _this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new IfController()) : + _this.scenarioDefinition.push(new IfController()); + break; + case ELEMENT_TYPE.ConstantTimer: + _this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new ConstantTimer()) : + _this.scenarioDefinition.push(new ConstantTimer()); + break; + case ELEMENT_TYPE.JSR223Processor: + _this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new JSR223Processor()) : + _this.scenarioDefinition.push(new JSR223Processor()); + break; + case ELEMENT_TYPE.JSR223PreProcessor: + _this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new JSR223Processor({type: "JSR223PreProcessor"})) : + _this.scenarioDefinition.push(new JSR223Processor({type: "JSR223PreProcessor"})); + break; + case ELEMENT_TYPE.JSR223PostProcessor: + _this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new JSR223Processor({type: "JSR223PostProcessor"})) : + _this.scenarioDefinition.push(new JSR223Processor({type: "JSR223PostProcessor"})); + break; + case ELEMENT_TYPE.Assertions: + _this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new Assertions()) : + _this.scenarioDefinition.push(new Assertions()); + break; + case ELEMENT_TYPE.Extract: + _this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new Extract()) : + _this.scenarioDefinition.push(new Extract()); + break; + case ELEMENT_TYPE.CustomizeReq: + _this.customizeRequest = {protocol: "HTTP", type: "API", hashTree: [], referenced: 'Created', active: false}; + _this.customizeVisible = true; + break; + case ELEMENT_TYPE.LoopController: + _this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new LoopController()) : + _this.scenarioDefinition.push(new LoopController()); + break; + case ELEMENT_TYPE.TransactionController: + _this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new TransactionController()) : + _this.scenarioDefinition.push(new TransactionController()); + break; + case ELEMENT_TYPE.scenario: + _this.isBtnHide = true; + _this.$refs.scenarioRelevance.open(); + break; + default: + _this.$refs.apiImport.open(); + break; + } + if (_this.selectedNode) { + _this.selectedNode.expanded = true; + } + _this.sort(); +}