refactor(接口自动化): 重构添加组件方法

This commit is contained in:
fit2-zhao 2021-01-18 12:44:02 +08:00
parent b0c158235c
commit 46a9600908
19 changed files with 152 additions and 73 deletions

View File

@ -145,31 +145,12 @@
@node-expand="nodeExpand" @node-expand="nodeExpand"
@node-collapse="nodeCollapse" @node-collapse="nodeCollapse"
:allow-drop="allowDrop" @node-drag-end="allowDrag" @node-click="nodeClick" v-if="!loading" draggable> :allow-drop="allowDrop" @node-drag-end="allowDrag" @node-click="nodeClick" v-if="!loading" draggable>
<span class="custom-tree-node father" slot-scope="{ node, data}" style="width: 96%"> <span class="custom-tree-node father" slot-scope="{ node, data}" style="width: 96%">
<template> <!-- 步骤组件-->
<!-- 场景 --> <ms-component-config :type="data.type" :scenario="data" :response="response" :currentScenario="currentScenario"
<ms-api-scenario-component v-if="data.type==='scenario'" :scenario="data" :node="node" @remove="remove" @copyRow="copyRow"/> :currentEnvironmentId="currentEnvironmentId" :node="node"
<!--条件控制器--> @remove="remove" @copyRow="copyRow" @suggestClick="suggestClick"/>
<ms-if-controller :controller="data" :node="node" v-if="data.type==='IfController'" @remove="remove" @copyRow="copyRow"/> </span>
<!--循环控制器-->
<ms-loop-controller :controller="data" :node="node" v-if="data.type==='LoopController'" @remove="remove" @copyRow="copyRow"/>
<!--等待控制器-->
<ms-constant-timer :timer="data" :node="node" v-if="data.type==='ConstantTimer'" @remove="remove" @copyRow="copyRow"/>
<!--自定义脚本-->
<ms-jsr233-processor :draggable="true" v-if="data.type==='JSR223Processor'" @remove="remove" @copyRow="copyRow" :title="$t('api_test.automation.customize_script')" :jsr223-processor="data" :node="node"/>
<!--前置脚本-->
<ms-jsr233-processor :draggable="true" v-if="data.type==='JSR223PreProcessor'" @remove="remove" @copyRow="copyRow" :title="$t('api_test.definition.request.pre_script')" :jsr223-processor="data" :node="node"/>
<!--后置脚本-->
<ms-jsr233-processor :draggable="true" v-if="data.type==='JSR223PostProcessor'" @remove="remove" @copyRow="copyRow" :title="$t('api_test.definition.request.post_script')" :jsr223-processor="data" :node="node"/>
<!--断言规则-->
<ms-api-assertions :draggable="true" @suggestClick="suggestClick(node)" :response="response" v-if="data.type==='Assertions'" @remove="remove" @copyRow="copyRow" :assertions="data" :node="node"/>
<!--提取规则-->
<ms-api-extract :draggable="true" @suggestClick="suggestClick(node)" :response="response" @remove="remove" @copyRow="copyRow" v-if="data.type==='Extract'" :extract="data" :node="node"/>
<!--API 导入 -->
<ms-api-component :request="data" :currentScenario="currentScenario" :currentEnvironmentId="currentEnvironmentId" @remove="remove" @copyRow="copyRow"
v-if="data.type==='HTTPSamplerProxy'||data.type==='DubboSampler'||data.type==='JDBCSampler'||data.type==='TCPSampler'" :node="node"/>
</template>
</span>
</el-tree> </el-tree>
</div> </div>
</el-col> </el-col>
@ -227,21 +208,13 @@
import {API_STATUS, PRIORITY} from "../../definition/model/JsonData"; import {API_STATUS, PRIORITY} from "../../definition/model/JsonData";
import {WORKSPACE_ID} from '@/common/js/constants'; import {WORKSPACE_ID} from '@/common/js/constants';
import {Assertions, Extract, IfController, JSR223Processor, ConstantTimer, LoopController} from "../../definition/model/ApiTestModel"; import {Assertions, Extract, IfController, JSR223Processor, ConstantTimer, LoopController} from "../../definition/model/ApiTestModel";
import MsJsr233Processor from "./Jsr233Processor";
import {parseEnvironment} from "../../definition/model/EnvironmentModel"; import {parseEnvironment} from "../../definition/model/EnvironmentModel";
import MsConstantTimer from "./ConstantTimer";
import MsIfController from "./IfController";
import MsApiAssertions from "../../definition/components/assertion/ApiAssertions";
import MsApiExtract from "../../definition/components/extract/ApiExtract";
import MsApiComponent from "./ApiComponent";
import {ELEMENTS, ELEMENT_TYPE} from "./Setting"; import {ELEMENTS, ELEMENT_TYPE} from "./Setting";
import MsApiCustomize from "./ApiCustomize"; import MsApiCustomize from "./ApiCustomize";
import {getUUID, getCurrentProjectID} from "@/common/js/utils"; import {getUUID, getCurrentProjectID} from "@/common/js/utils";
import ApiEnvironmentConfig from "../../definition/components/environment/ApiEnvironmentConfig"; import ApiEnvironmentConfig from "../../definition/components/environment/ApiEnvironmentConfig";
import MsInputTag from "./MsInputTag"; import MsInputTag from "./MsInputTag";
import MsRun from "./DebugRun"; import MsRun from "./DebugRun";
import MsLoopController from "./LoopController";
import MsApiScenarioComponent from "./ApiScenarioComponent";
import MsApiReportDetail from "../report/ApiReportDetail"; import MsApiReportDetail from "../report/ApiReportDetail";
import MsVariableList from "./variable/VariableList"; import MsVariableList from "./variable/VariableList";
import ApiImport from "../../definition/components/import/ApiImport"; import ApiImport from "../../definition/components/import/ApiImport";
@ -250,6 +223,7 @@
import OutsideClick from "@/common/js/outside-click"; import OutsideClick from "@/common/js/outside-click";
import ScenarioApiRelevance from "./api/ApiRelevance"; import ScenarioApiRelevance from "./api/ApiRelevance";
import ScenarioRelevance from "./api/ScenarioRelevance"; import ScenarioRelevance from "./api/ScenarioRelevance";
import MsComponentConfig from "./component/ComponentConfig";
export default { export default {
name: "EditApiScenario", name: "EditApiScenario",
@ -264,17 +238,10 @@
ApiEnvironmentConfig, ApiEnvironmentConfig,
MsApiReportDetail, MsApiReportDetail,
MsInputTag, MsRun, MsInputTag, MsRun,
MsApiScenarioComponent,
MsJsr233Processor,
MsConstantTimer,
MsIfController,
MsApiAssertions,
MsApiExtract,
MsApiComponent,
MsApiCustomize, MsApiCustomize,
ApiImport, ApiImport,
InputTag, InputTag,
MsLoopController, MsComponentConfig,
}, },
data() { data() {
return { return {

View File

@ -63,15 +63,15 @@
</template> </template>
<script> <script>
import MsSqlBasisParameters from "../../definition/components/request/database/BasisParameters"; import MsSqlBasisParameters from "../../../definition/components/request/database/BasisParameters";
import MsTcpBasisParameters from "../../definition/components/request/tcp/TcpBasisParameters"; import MsTcpBasisParameters from "../../../definition/components/request/tcp/TcpBasisParameters";
import MsDubboBasisParameters from "../../definition/components/request/dubbo/BasisParameters"; import MsDubboBasisParameters from "../../../definition/components/request/dubbo/BasisParameters";
import MsApiRequestForm from "../../definition/components/request/http/ApiRequestForm"; import MsApiRequestForm from "../../../definition/components/request/http/ApiRequestForm";
import {REQ_METHOD} from "../../definition/model/JsonData"; import {REQ_METHOD} from "../../../definition/model/JsonData";
import MsRequestResultTail from "../../definition/components/response/RequestResultTail"; import MsRequestResultTail from "../../../definition/components/response/RequestResultTail";
import MsRun from "../../definition/components/Run"; import MsRun from "../../../definition/components/Run";
import {getUUID} from "@/common/js/utils"; import {getUUID} from "@/common/js/utils";
import ApiBaseComponent from "./common/ApiBaseComponent"; import ApiBaseComponent from "../common/ApiBaseComponent";
export default { export default {
name: "MsApiComponent", name: "MsApiComponent",
props: { props: {

View File

@ -28,11 +28,11 @@
</template> </template>
<script> <script>
import MsSqlBasisParameters from "../../definition/components/request/database/BasisParameters"; import MsSqlBasisParameters from "../../../definition/components/request/database/BasisParameters";
import MsTcpBasisParameters from "../../definition/components/request/tcp/TcpBasisParameters"; import MsTcpBasisParameters from "../../../definition/components/request/tcp/TcpBasisParameters";
import MsDubboBasisParameters from "../../definition/components/request/dubbo/BasisParameters"; import MsDubboBasisParameters from "../../../definition/components/request/dubbo/BasisParameters";
import MsApiRequestForm from "../../definition/components/request/http/ApiRequestForm"; import MsApiRequestForm from "../../../definition/components/request/http/ApiRequestForm";
import ApiBaseComponent from "./common/ApiBaseComponent"; import ApiBaseComponent from "../common/ApiBaseComponent";
export default { export default {
name: "ApiScenarioComponent", name: "ApiScenarioComponent",

View File

@ -0,0 +1,113 @@
<template>
<div class="request-form">
<component :is="component" :scenario="scenario" :controller="scenario" :timer="scenario" :assertions="scenario" :extract="scenario" :jsr223-processor="scenario" :request="scenario" :currentScenario="currentScenario" :currentEnvironmentId="currentEnvironmentId" :node="node"
:draggable="true" :title="title" @suggestClick="suggestClick(node)" :response="response"
@remove="remove" @copyRow="copyRow"/>
</div>
</template>
<script>
import MsConstantTimer from "./ConstantTimer";
import MsIfController from "./IfController";
import {ELEMENT_TYPE} from "../Setting";
import MsJsr233Processor from "./Jsr233Processor";
import MsApiAssertions from "../../../definition/components/assertion/ApiAssertions";
import MsApiExtract from "../../../definition/components/extract/ApiExtract";
import MsApiComponent from "./ApiComponent";
import MsLoopController from "./LoopController";
import MsApiScenarioComponent from "./ApiScenarioComponent";
import {getUUID} from "@/common/js/utils";
export default {
name: "ComponentConfig",
components: {MsConstantTimer, MsIfController, MsJsr233Processor, MsApiAssertions, MsApiExtract, MsApiComponent, MsLoopController, MsApiScenarioComponent},
props: {
type: String,
scenario: {},
currentScenario: {},
currentEnvironmentId: String,
response: {},
node: {},
},
data() {
return {
title: this.$t('api_test.automation.customize_script'),
}
},
computed: {
component({type}) {
let name;
switch (type) {
case ELEMENT_TYPE.IfController:
name = "MsIfController";
break;
case ELEMENT_TYPE.ConstantTimer:
name = "MsConstantTimer";
break;
case ELEMENT_TYPE.JSR223Processor:
name = this.getComponent(ELEMENT_TYPE.JSR223Processor);
break;
case ELEMENT_TYPE.JSR223PreProcessor:
name = this.getComponent(ELEMENT_TYPE.JSR223PreProcessor);
break;
case ELEMENT_TYPE.JSR223PostProcessor:
name = this.getComponent(ELEMENT_TYPE.JSR223PostProcessor);
break;
case ELEMENT_TYPE.Assertions:
name = "MsApiAssertions";
break;
case ELEMENT_TYPE.Extract:
name = "MsApiExtract";
break;
case ELEMENT_TYPE.CustomizeReq:
name = "MsApiComponent";
break;
case ELEMENT_TYPE.LoopController:
name = "MsLoopController";
break;
case ELEMENT_TYPE.scenario:
name = "MsApiScenarioComponent";
break;
default:
name = "MsApiComponent";
break;
}
return name;
}
},
methods: {
getComponent(type) {
if (type === ELEMENT_TYPE.JSR223PreProcessor) {
this.title = this.$t('api_test.definition.request.pre_script');
return "MsJsr233Processor";
} else if (type === ELEMENT_TYPE.JSR223PostProcessor) {
this.title = this.$t('api_test.definition.request.post_script');
return "MsJsr233Processor";
} else {
this.title = this.$t('api_test.automation.customize_script');
return "MsJsr233Processor";
}
},
remove(row, node) {
this.$emit('remove',row,node);
},
copyRow(row, node) {
this.$emit('copyRow',row,node);
},
suggestClick(node) {
this.$emit('suggestClick',node);
},
}
}
</script>
<style scoped>
.request-form >>> .debug-button {
margin-left: auto;
display: block;
margin-right: 10px;
}
</style>

View File

@ -17,7 +17,7 @@
</template> </template>
<script> <script>
import ApiBaseComponent from "./common/ApiBaseComponent"; import ApiBaseComponent from "../common/ApiBaseComponent";
export default { export default {
name: "MsConstantTimer", name: "MsConstantTimer",
components: {ApiBaseComponent}, components: {ApiBaseComponent},

View File

@ -25,7 +25,7 @@
</template> </template>
<script> <script>
import ApiBaseComponent from "./common/ApiBaseComponent"; import ApiBaseComponent from "../common/ApiBaseComponent";
export default { export default {
name: "MsIfController", name: "MsIfController",
components: {ApiBaseComponent}, components: {ApiBaseComponent},

View File

@ -35,10 +35,10 @@
</template> </template>
<script> <script>
import MsCodeEdit from "../../../common/components/MsCodeEdit"; import MsCodeEdit from "../../../../common/components/MsCodeEdit";
import MsInstructionsIcon from "../../../common/components/MsInstructionsIcon"; import MsInstructionsIcon from "../../../../common/components/MsInstructionsIcon";
import MsDropdown from "../../../common/components/MsDropdown"; import MsDropdown from "../../../../common/components/MsDropdown";
import ApiBaseComponent from "./common/ApiBaseComponent"; import ApiBaseComponent from "../common/ApiBaseComponent";
export default { export default {
name: "MsJsr233Processor", name: "MsJsr233Processor",

View File

@ -70,7 +70,7 @@
</template> </template>
<script> <script>
import ApiBaseComponent from "./common/ApiBaseComponent"; import ApiBaseComponent from "../common/ApiBaseComponent";
export default { export default {
name: "MsLoopController", name: "MsLoopController",

View File

@ -57,7 +57,7 @@
<script> <script>
import {AssertionJSR223} from "../../model/ApiTestModel"; import {AssertionJSR223} from "../../model/ApiTestModel";
import MsDialogFooter from "@/business/components/common/components/MsDialogFooter"; import MsDialogFooter from "@/business/components/common/components/MsDialogFooter";
import MsJsr233Processor from "../../../automation/scenario/Jsr233Processor"; import MsJsr233Processor from "../../../automation/scenario/component/Jsr233Processor";
export default { export default {
name: "MsApiAssertionJsr223", name: "MsApiAssertionJsr223",

View File

@ -55,7 +55,7 @@
import MsApiAssertionText from "./ApiAssertionText"; import MsApiAssertionText from "./ApiAssertionText";
import MsApiAssertionRegex from "./ApiAssertionRegex"; import MsApiAssertionRegex from "./ApiAssertionRegex";
import MsApiAssertionDuration from "./ApiAssertionDuration"; import MsApiAssertionDuration from "./ApiAssertionDuration";
import {ASSERTION_TYPE, JSONPath, Scenario} from "../../model/ApiTestModel"; import {ASSERTION_TYPE, JSONPath} from "../../model/ApiTestModel";
import MsApiAssertionsEdit from "./ApiAssertionsEdit"; import MsApiAssertionsEdit from "./ApiAssertionsEdit";
import MsApiAssertionJsonPath from "./ApiAssertionJsonPath"; import MsApiAssertionJsonPath from "./ApiAssertionJsonPath";
import MsApiAssertionJsr223 from "./ApiAssertionJsr223"; import MsApiAssertionJsr223 from "./ApiAssertionJsr223";
@ -91,7 +91,6 @@
type: String, type: String,
default: "margin-top: 10px" default: "margin-top: 10px"
}, },
scenario: Scenario,
isReadOnly: { isReadOnly: {
type: Boolean, type: Boolean,
default: false default: false

View File

@ -114,7 +114,7 @@ import {WORKSPACE_ID} from '../../../../../../common/js/constants';
import {API_STATUS, REQ_METHOD} from "../../model/JsonData"; import {API_STATUS, REQ_METHOD} from "../../model/JsonData";
import {KeyValue} from "../../model/ApiTestModel"; import {KeyValue} from "../../model/ApiTestModel";
import MsInputTag from "@/business/components/api/automation/scenario/MsInputTag"; import MsInputTag from "@/business/components/api/automation/scenario/MsInputTag";
import MsJsr233Processor from "../../../automation/scenario/Jsr233Processor"; import MsJsr233Processor from "../../../automation/scenario/component/Jsr233Processor";
export default { export default {
name: "MsAddCompleteHttpApi", name: "MsAddCompleteHttpApi",

View File

@ -112,7 +112,7 @@
import ApiEnvironmentConfig from "../../environment/ApiEnvironmentConfig"; import ApiEnvironmentConfig from "../../environment/ApiEnvironmentConfig";
import {getCurrentProjectID} from "@/common/js/utils"; import {getCurrentProjectID} from "@/common/js/utils";
import {getUUID} from "@/common/js/utils"; import {getUUID} from "@/common/js/utils";
import MsJsr233Processor from "../../../../automation/scenario/Jsr233Processor"; import MsJsr233Processor from "../../../../automation/scenario/component/Jsr233Processor";
export default { export default {
name: "MsDatabaseConfig", name: "MsDatabaseConfig",

View File

@ -89,7 +89,7 @@
import MsDubboConfigCenter from "../../request/dubbo/ConfigCenter"; import MsDubboConfigCenter from "../../request/dubbo/ConfigCenter";
import MsDubboConsumerService from "../../request/dubbo/ConsumerAndService"; import MsDubboConsumerService from "../../request/dubbo/ConsumerAndService";
import {getUUID} from "@/common/js/utils"; import {getUUID} from "@/common/js/utils";
import MsJsr233Processor from "../../../../automation/scenario/Jsr233Processor"; import MsJsr233Processor from "../../../../automation/scenario/component/Jsr233Processor";
export default { export default {
name: "MsDatabaseConfig", name: "MsDatabaseConfig",

View File

@ -115,7 +115,7 @@
import {getUUID} from "@/common/js/utils"; import {getUUID} from "@/common/js/utils";
import BatchAddParameter from "../../basis/BatchAddParameter"; import BatchAddParameter from "../../basis/BatchAddParameter";
import MsApiAdvancedConfig from "./ApiAdvancedConfig"; import MsApiAdvancedConfig from "./ApiAdvancedConfig";
import MsJsr233Processor from "../../../../automation/scenario/Jsr233Processor"; import MsJsr233Processor from "../../../../automation/scenario/component/Jsr233Processor";
export default { export default {
name: "MsApiHttpRequestForm", name: "MsApiHttpRequestForm",

View File

@ -57,7 +57,7 @@
<script> <script>
import {AssertionJSR223} from "../../model/ScenarioModel"; import {AssertionJSR223} from "../../model/ScenarioModel";
import MsDialogFooter from "@/business/components/common/components/MsDialogFooter"; import MsDialogFooter from "@/business/components/common/components/MsDialogFooter";
import MsJsr233Processor from "../../../automation/scenario/Jsr233Processor"; import MsJsr233Processor from "../../../automation/scenario/component/Jsr233Processor";
export default { export default {
name: "MsApiAssertionJsr223", name: "MsApiAssertionJsr223",

View File

@ -65,7 +65,7 @@
import MsDubboRegistryCenter from "@/business/components/api/test/components/request/dubbo/RegistryCenter"; import MsDubboRegistryCenter from "@/business/components/api/test/components/request/dubbo/RegistryCenter";
import MsDubboConfigCenter from "@/business/components/api/test/components/request/dubbo/ConfigCenter"; import MsDubboConfigCenter from "@/business/components/api/test/components/request/dubbo/ConfigCenter";
import MsDubboConsumerService from "@/business/components/api/test/components/request/dubbo/ConsumerAndService"; import MsDubboConsumerService from "@/business/components/api/test/components/request/dubbo/ConsumerAndService";
import MsJsr233Processor from "../../../automation/scenario/Jsr233Processor"; import MsJsr233Processor from "../../../automation/scenario/component/Jsr233Processor";
export default { export default {
name: "MsApiDubboRequestForm", name: "MsApiDubboRequestForm",

View File

@ -94,7 +94,7 @@ import ApiRequestMethodSelect from "../collapse/ApiRequestMethodSelect";
import {REQUEST_HEADERS} from "@/common/js/constants"; import {REQUEST_HEADERS} from "@/common/js/constants";
import MsApiVariable from "@/business/components/api/test/components/ApiVariable"; import MsApiVariable from "@/business/components/api/test/components/ApiVariable";
import MsApiAdvancedConfig from "../ApiAdvancedConfig"; import MsApiAdvancedConfig from "../ApiAdvancedConfig";
import MsJsr233Processor from "../../../automation/scenario/Jsr233Processor"; import MsJsr233Processor from "../../../automation/scenario/component/Jsr233Processor";
export default { export default {
name: "MsApiHttpRequestForm", name: "MsApiHttpRequestForm",

View File

@ -78,7 +78,7 @@
import MsDubboConsumerService from "@/business/components/api/test/components/request/dubbo/ConsumerAndService"; import MsDubboConsumerService from "@/business/components/api/test/components/request/dubbo/ConsumerAndService";
import MsCodeEdit from "../../../../common/components/MsCodeEdit"; import MsCodeEdit from "../../../../common/components/MsCodeEdit";
import MsApiScenarioVariables from "../ApiScenarioVariables"; import MsApiScenarioVariables from "../ApiScenarioVariables";
import MsJsr233Processor from "../../../automation/scenario/Jsr233Processor"; import MsJsr233Processor from "../../../automation/scenario/component/Jsr233Processor";
export default { export default {
name: "MsApiSqlRequestForm", name: "MsApiSqlRequestForm",

View File

@ -120,7 +120,7 @@ import {Scenario, TCPConfig, TCPRequest} from "@/business/components/api/test/mo
import MsApiAssertions from "@/business/components/api/test/components/assertion/ApiAssertions"; import MsApiAssertions from "@/business/components/api/test/components/assertion/ApiAssertions";
import MsApiExtract from "@/business/components/api/test/components/extract/ApiExtract"; import MsApiExtract from "@/business/components/api/test/components/extract/ApiExtract";
import MsCodeEdit from "@/business/components/common/components/MsCodeEdit"; import MsCodeEdit from "@/business/components/common/components/MsCodeEdit";
import MsJsr233Processor from "../../../automation/scenario/Jsr233Processor"; import MsJsr233Processor from "../../../automation/scenario/component/Jsr233Processor";
export default { export default {
name: "MsApiTcpRequestForm", name: "MsApiTcpRequestForm",