Conflicts:
	frontend/src/business/components/api/definition/components/Run.vue
This commit is contained in:
shiziyuan9527 2021-03-01 10:27:46 +08:00
commit b7ddf4194a
6 changed files with 139 additions and 70 deletions

View File

@ -113,23 +113,23 @@
</el-col> </el-col>
<el-col :span="7" class="ms-col-one ms-font"> <el-col :span="7" class="ms-col-one ms-font">
<el-link type="primary" @click="handleEnv">环境配置</el-link> <el-link type="primary" @click="handleEnv">环境配置</el-link>
<!-- <el-select v-model="currentEnvironmentId" size="small" class="ms-htt-width"--> <!-- <el-select v-model="currentEnvironmentId" size="small" class="ms-htt-width"-->
<!-- :placeholder="$t('api_test.definition.request.run_env')"--> <!-- :placeholder="$t('api_test.definition.request.run_env')"-->
<!-- clearable>--> <!-- clearable>-->
<!-- <el-option v-for="(environment, index) in environments" :key="index"--> <!-- <el-option v-for="(environment, index) in environments" :key="index"-->
<!-- :label="environment.name + (environment.config.httpConfig.socket ? (': ' + environment.config.httpConfig.protocol + '://' + environment.config.httpConfig.socket) : '')"--> <!-- :label="environment.name + (environment.config.httpConfig.socket ? (': ' + environment.config.httpConfig.protocol + '://' + environment.config.httpConfig.socket) : '')"-->
<!-- :value="environment.id"/>--> <!-- :value="environment.id"/>-->
<!-- <el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig">--> <!-- <el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig">-->
<!-- {{ $t('api_test.environment.environment_config') }}--> <!-- {{ $t('api_test.environment.environment_config') }}-->
<!-- </el-button>--> <!-- </el-button>-->
<!-- <template v-slot:empty>--> <!-- <template v-slot:empty>-->
<!-- <div class="empty-environment">--> <!-- <div class="empty-environment">-->
<!-- <el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig">--> <!-- <el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig">-->
<!-- {{ $t('api_test.environment.environment_config') }}--> <!-- {{ $t('api_test.environment.environment_config') }}-->
<!-- </el-button>--> <!-- </el-button>-->
<!-- </div>--> <!-- </div>-->
<!-- </template>--> <!-- </template>-->
<!-- </el-select>--> <!-- </el-select>-->
</el-col> </el-col>
<el-col :span="2"> <el-col :span="2">
@ -208,36 +208,36 @@
</template> </template>
<script> <script>
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 { import {
Assertions, Assertions,
ConstantTimer, ConstantTimer,
Extract, Extract,
IfController, IfController,
JSR223Processor, JSR223Processor,
LoopController LoopController
} from "../../definition/model/ApiTestModel"; } from "../../definition/model/ApiTestModel";
import {parseEnvironment} from "../../definition/model/EnvironmentModel"; import {parseEnvironment} from "../../definition/model/EnvironmentModel";
import {ELEMENT_TYPE, ELEMENTS} from "./Setting"; import {ELEMENT_TYPE, ELEMENTS} from "./Setting";
import MsApiCustomize from "./ApiCustomize"; import MsApiCustomize from "./ApiCustomize";
import {getCurrentProjectID, getUUID, objToStrMap, strMapToObj} from "@/common/js/utils"; import {getCurrentProjectID, getUUID, objToStrMap, strMapToObj} 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 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";
import "@/common/css/material-icons.css" import "@/common/css/material-icons.css"
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"; import MsComponentConfig from "./component/ComponentConfig";
import {handleCtrlSEvent} from "../../../../../common/js/utils"; import {handleCtrlSEvent} from "../../../../../common/js/utils";
import {getProject} from "@/business/components/api/automation/scenario/event"; import {getProject} from "@/business/components/api/automation/scenario/event";
import ApiScenarioEnv from "@/business/components/api/automation/scenario/ApiScenarioEnv"; import ApiScenarioEnv from "@/business/components/api/automation/scenario/ApiScenarioEnv";
export default { export default {
name: "EditApiScenario", name: "EditApiScenario",
props: { props: {
moduleOptions: Array, moduleOptions: Array,
@ -543,8 +543,10 @@ export default {
} }
}, },
showAll() { showAll() {
if (!this.customizeVisible) {
this.operatingElements = ELEMENTS.get("ALL"); this.operatingElements = ELEMENTS.get("ALL");
this.selectedTreeNode = undefined; this.selectedTreeNode = undefined;
}
//this.reload(); //this.reload();
}, },
apiListImport() { apiListImport() {

View File

@ -124,6 +124,7 @@
}, },
languageChange(language) { languageChange(language) {
this.jsr223ProcessorData.scriptLanguage = language; this.jsr223ProcessorData.scriptLanguage = language;
this.$emit("languageChange");
}, },
} }
} }

View File

@ -2,7 +2,7 @@
<span></span> <span></span>
</template> </template>
<script> <script>
import {getUUID, getBodyUploadFiles, getCurrentProjectID, strMapToObj} from "@/common/js/utils"; import {getUUID, getBodyUploadFiles, getCurrentProjectID, strMapToObj} from "@/common/js/utils";
import ThreadGroup from "./jmeter/components/thread-group"; import ThreadGroup from "./jmeter/components/thread-group";
import TestPlan from "./jmeter/components/test-plan"; import TestPlan from "./jmeter/components/test-plan";

View File

@ -44,7 +44,7 @@
<el-input size="small" v-model="assertion.desc" :placeholder="$t('api_test.request.assertions.script_name')" <el-input size="small" v-model="assertion.desc" :placeholder="$t('api_test.request.assertions.script_name')"
class="quick-script-block"/> class="quick-script-block"/>
<ms-jsr233-processor ref="jsr233" :is-read-only="isReadOnly" :jsr223-processor="assertion" :templates="templates" <ms-jsr233-processor ref="jsr233" :is-read-only="isReadOnly" :jsr223-processor="assertion" :templates="templates"
:height="300"/> :height="300" @languageChange="quickScript"/>
<template v-slot:footer v-if="!edit"> <template v-slot:footer v-if="!edit">
<ms-dialog-footer <ms-dialog-footer
@cancel="close" @cancel="close"
@ -145,7 +145,7 @@
} }
this.quickScript(); this.quickScript();
}, },
quickScript() { beanShellOrGroovyScript() {
if (this.assertion.variable && this.assertion.operator) { if (this.assertion.variable && this.assertion.operator) {
let variable = this.assertion.variable; let variable = this.assertion.variable;
let operator = this.assertion.operator; let operator = this.assertion.operator;
@ -184,7 +184,7 @@
script += "result = value != void && value.length() > 0;\n"; script += "result = value != void && value.length() > 0;\n";
break; break;
} }
let msg = "assertion [" + desc + "]: false;" let msg = (operator != "is empty" && operator != "is not empty") ? "assertion [" + desc + "]: false;" : "value " + operator
script += "if (!result){\n" + script += "if (!result){\n" +
"\tmsg = \"" + msg + "\";\n" + "\tmsg = \"" + msg + "\";\n" +
"\tAssertionResult.setFailureMessage(msg);\n" + "\tAssertionResult.setFailureMessage(msg);\n" +
@ -197,6 +197,68 @@
} }
}, },
pythonScript() {
if (this.assertion.variable && this.assertion.operator) {
let variable = this.assertion.variable;
let operator = this.assertion.operator;
let value = this.assertion.value || "";
let desc = "${" + variable + "} " + operator + " '" + value + "'";
let msg = "";
let script = "value = vars.get(\"" + variable + "\");\n"
switch (this.assertion.operator) {
case "==":
script += "if value != \"" + value + "\" :\n";
break;
case "!=":
script += "if value == \"" + value + "\" :\n";
break;
case "contains":
script += "if value.find(\"" + value + "\") != -1:\n";
msg = "value " + operator + " " + value + ": false;";
break;
case "not contains":
script += "if value.find(\"" + value + "\") == -1:\n";
msg = "value " + operator + " " + ": false;";
break;
case ">":
desc = "${" + variable + "} " + operator + " " + value;
script += "if value is None or int(value) < " + value + ":\n";
msg = "value " + operator + " " + value + ": false;";
break;
case "<":
desc = "${" + variable + "} " + operator + " " + value;
script += "if value is None or int(value) > " + value + ":\n";
msg = "value " + operator + " " + value + ": false;";
break;
case "is empty":
desc = "${" + variable + "} " + operator
script += "if value is not None:\n";
msg = "value " + operator + ": false;";
break;
case "is not empty":
desc = "${" + variable + "} " + operator
script += "if value is None:\n";
msg = "value " + operator + ": false;";
break;
}
script +=
"\tmsg = \" " + msg + "\";" +
"\tAssertionResult.setFailureMessage(msg);" +
"\tAssertionResult.setFailure(true);";
this.assertion.desc = desc;
this.assertion.script = script;
this.$refs.jsr233.reload();
}
},
quickScript() {
if (this.assertion.scriptLanguage == 'beanshell' || this.assertion.scriptLanguage == 'groovy' || this.assertion.scriptLanguage == 'javascript') {
this.beanShellOrGroovyScript();
} else {
this.pythonScript();
}
},
detail() { detail() {
this.visible = true; this.visible = true;
}, },

View File

@ -132,7 +132,7 @@ export default {
filterNode(value, data) { filterNode(value, data) {
if (!value) return true; if (!value) return true;
if (data.label) { if (data.label) {
return data.label.indexOf(value) !== -1; return data.label.indexOf(value.toLowerCase()) !== -1;
} }
return false; return false;
}, },

View File

@ -319,6 +319,7 @@ export function _getBodyUploadFiles(request, bodyUploadFiles, obj) {
} }
} }
} }
export function handleCtrlSEvent(event, func) { export function handleCtrlSEvent(event, func) {
if (event.keyCode === 83 && event.ctrlKey) { if (event.keyCode === 83 && event.ctrlKey) {
// console.log('拦截到 ctrl + s');//ctrl+s // console.log('拦截到 ctrl + s');//ctrl+s
@ -329,12 +330,15 @@ export function handleCtrlSEvent(event, func) {
} }
} }
export function strMapToObj(strMap){ export function strMapToObj(strMap) {
let obj= Object.create(null); if (strMap) {
for (let[k,v] of strMap) { let obj = Object.create(null);
for (let [k, v] of strMap) {
obj[k] = v; obj[k] = v;
} }
return obj; return obj;
}
return null;
} }
export function objToStrMap(obj) { export function objToStrMap(obj) {