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 :span="7" class="ms-col-one ms-font">
<el-link type="primary" @click="handleEnv">环境配置</el-link>
<!-- <el-select v-model="currentEnvironmentId" size="small" class="ms-htt-width"-->
<!-- :placeholder="$t('api_test.definition.request.run_env')"-->
<!-- clearable>-->
<!-- <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) : '')"-->
<!-- :value="environment.id"/>-->
<!-- <el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig">-->
<!-- {{ $t('api_test.environment.environment_config') }}-->
<!-- </el-button>-->
<!-- <template v-slot:empty>-->
<!-- <div class="empty-environment">-->
<!-- <el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig">-->
<!-- {{ $t('api_test.environment.environment_config') }}-->
<!-- </el-button>-->
<!-- </div>-->
<!-- </template>-->
<!-- </el-select>-->
<!-- <el-select v-model="currentEnvironmentId" size="small" class="ms-htt-width"-->
<!-- :placeholder="$t('api_test.definition.request.run_env')"-->
<!-- clearable>-->
<!-- <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) : '')"-->
<!-- :value="environment.id"/>-->
<!-- <el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig">-->
<!-- {{ $t('api_test.environment.environment_config') }}-->
<!-- </el-button>-->
<!-- <template v-slot:empty>-->
<!-- <div class="empty-environment">-->
<!-- <el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig">-->
<!-- {{ $t('api_test.environment.environment_config') }}-->
<!-- </el-button>-->
<!-- </div>-->
<!-- </template>-->
<!-- </el-select>-->
</el-col>
<el-col :span="2">
@ -208,47 +208,47 @@
</template>
<script>
import {API_STATUS, PRIORITY} from "../../definition/model/JsonData";
import {WORKSPACE_ID} from '@/common/js/constants';
import {
Assertions,
ConstantTimer,
Extract,
IfController,
JSR223Processor,
LoopController
} from "../../definition/model/ApiTestModel";
import {parseEnvironment} from "../../definition/model/EnvironmentModel";
import {ELEMENT_TYPE, ELEMENTS} from "./Setting";
import MsApiCustomize from "./ApiCustomize";
import {getCurrentProjectID, getUUID, objToStrMap, strMapToObj} from "@/common/js/utils";
import ApiEnvironmentConfig from "../../definition/components/environment/ApiEnvironmentConfig";
import MsInputTag from "./MsInputTag";
import MsRun from "./DebugRun";
import MsApiReportDetail from "../report/ApiReportDetail";
import MsVariableList from "./variable/VariableList";
import ApiImport from "../../definition/components/import/ApiImport";
import "@/common/css/material-icons.css"
import OutsideClick from "@/common/js/outside-click";
import ScenarioApiRelevance from "./api/ApiRelevance";
import ScenarioRelevance from "./api/ScenarioRelevance";
import MsComponentConfig from "./component/ComponentConfig";
import {handleCtrlSEvent} from "../../../../../common/js/utils";
import {getProject} from "@/business/components/api/automation/scenario/event";
import ApiScenarioEnv from "@/business/components/api/automation/scenario/ApiScenarioEnv";
import {API_STATUS, PRIORITY} from "../../definition/model/JsonData";
import {WORKSPACE_ID} from '@/common/js/constants';
import {
Assertions,
ConstantTimer,
Extract,
IfController,
JSR223Processor,
LoopController
} from "../../definition/model/ApiTestModel";
import {parseEnvironment} from "../../definition/model/EnvironmentModel";
import {ELEMENT_TYPE, ELEMENTS} from "./Setting";
import MsApiCustomize from "./ApiCustomize";
import {getCurrentProjectID, getUUID, objToStrMap, strMapToObj} from "@/common/js/utils";
import ApiEnvironmentConfig from "../../definition/components/environment/ApiEnvironmentConfig";
import MsInputTag from "./MsInputTag";
import MsRun from "./DebugRun";
import MsApiReportDetail from "../report/ApiReportDetail";
import MsVariableList from "./variable/VariableList";
import ApiImport from "../../definition/components/import/ApiImport";
import "@/common/css/material-icons.css"
import OutsideClick from "@/common/js/outside-click";
import ScenarioApiRelevance from "./api/ApiRelevance";
import ScenarioRelevance from "./api/ScenarioRelevance";
import MsComponentConfig from "./component/ComponentConfig";
import {handleCtrlSEvent} from "../../../../../common/js/utils";
import {getProject} from "@/business/components/api/automation/scenario/event";
import ApiScenarioEnv from "@/business/components/api/automation/scenario/ApiScenarioEnv";
export default {
name: "EditApiScenario",
props: {
moduleOptions: Array,
currentScenario: {},
},
components: {
ApiScenarioEnv,
MsVariableList,
ScenarioRelevance,
ScenarioApiRelevance,
ApiEnvironmentConfig,
export default {
name: "EditApiScenario",
props: {
moduleOptions: Array,
currentScenario: {},
},
components: {
ApiScenarioEnv,
MsVariableList,
ScenarioRelevance,
ScenarioApiRelevance,
ApiEnvironmentConfig,
MsApiReportDetail,
MsInputTag, MsRun,
MsApiCustomize,
@ -321,7 +321,7 @@ export default {
// this.projectEnvMap.set(projectId, projectEnv);
})
},
directives: {OutsideClick},
directives: {OutsideClick},
computed: {
buttons() {
let buttons = [
@ -543,8 +543,10 @@ export default {
}
},
showAll() {
this.operatingElements = ELEMENTS.get("ALL");
this.selectedTreeNode = undefined;
if (!this.customizeVisible) {
this.operatingElements = ELEMENTS.get("ALL");
this.selectedTreeNode = undefined;
}
//this.reload();
},
apiListImport() {

View File

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

View File

@ -2,7 +2,7 @@
<span></span>
</template>
<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 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')"
class="quick-script-block"/>
<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">
<ms-dialog-footer
@cancel="close"
@ -145,7 +145,7 @@
}
this.quickScript();
},
quickScript() {
beanShellOrGroovyScript() {
if (this.assertion.variable && this.assertion.operator) {
let variable = this.assertion.variable;
let operator = this.assertion.operator;
@ -184,7 +184,7 @@
script += "result = value != void && value.length() > 0;\n";
break;
}
let msg = "assertion [" + desc + "]: false;"
let msg = (operator != "is empty" && operator != "is not empty") ? "assertion [" + desc + "]: false;" : "value " + operator
script += "if (!result){\n" +
"\tmsg = \"" + 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() {
this.visible = true;
},

View File

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

View File

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