feat(接口测试): 处理变量

This commit is contained in:
Captain.B 2020-08-13 15:26:11 +08:00
parent 9bad4b4a83
commit 01e22c9f1a
5 changed files with 55 additions and 55 deletions

View File

@ -36,7 +36,8 @@
<el-main class="scenario-main">
<div class="scenario-form">
<ms-api-scenario-form :is-read-only="isReadOnly" :scenario="selected" :project-id="projectId" v-if="isScenario"/>
<ms-api-request-form :debug-report-id="debugReportId" @runDebug="runDebug" :is-read-only="isReadOnly" :request="selected" v-if="isRequest"/>
<ms-api-request-form :debug-report-id="debugReportId" @runDebug="runDebug" :is-read-only="isReadOnly"
:request="selected" :scenario="currentScenario" v-if="isRequest"/>
</div>
</el-main>
</el-container>
@ -44,25 +45,25 @@
<script>
import MsApiCollapseItem from "./collapse/ApiCollapseItem";
import MsApiCollapse from "./collapse/ApiCollapse";
import MsApiRequestConfig from "./request/ApiRequestConfig";
import MsApiRequestForm from "./request/ApiRequestForm";
import MsApiScenarioForm from "./ApiScenarioForm";
import {Scenario, Request} from "../model/ScenarioModel";
import draggable from 'vuedraggable';
import MsApiCollapseItem from "./collapse/ApiCollapseItem";
import MsApiCollapse from "./collapse/ApiCollapse";
import MsApiRequestConfig from "./request/ApiRequestConfig";
import MsApiRequestForm from "./request/ApiRequestForm";
import MsApiScenarioForm from "./ApiScenarioForm";
import {Request, Scenario} from "../model/ScenarioModel";
import draggable from 'vuedraggable';
export default {
name: "MsApiScenarioConfig",
export default {
name: "MsApiScenarioConfig",
components: {
MsApiRequestConfig,
MsApiScenarioForm,
MsApiRequestForm,
MsApiCollapse,
MsApiCollapseItem,
draggable
},
components: {
MsApiRequestConfig,
MsApiScenarioForm,
MsApiRequestForm,
MsApiCollapse,
MsApiCollapseItem,
draggable
},
props: {
scenarios: Array,

View File

@ -79,8 +79,9 @@
<div v-if="environment">
<el-tree :data="environmentParams" :props="{ children: 'children', label: 'name'}"></el-tree>
</div>
场景
请求1
<div v-if="scenario">
<el-tree :data="scenarioParams" :props="{ children: 'children', label: 'name'}"></el-tree>
</div>
</el-col>
</el-row>
</el-tab-pane>
@ -109,7 +110,7 @@
</template>
<script>
import {KeyValue} from "../model/ScenarioModel";
import {KeyValue, Scenario} from "../model/ScenarioModel";
import {MOCKJS_FUNC} from "@/common/js/constants";
import {calculate} from "@/business/components/api/test/model/ScenarioModel";
@ -122,6 +123,7 @@ export default {
description: String,
items: Array,
environment: Object,
scenario: Scenario,
isReadOnly: {
type: Boolean,
default: false
@ -129,24 +131,23 @@ export default {
suggestions: Array
},
mounted() {
if (this.scenario) {
let variables = this.scenario.variables;
this.scenarioParams = [
{
name: this.scenario.name,
children: variables.filter(v => v.name),
}
];
}
if (this.environment) {
let variables = JSON.parse(this.environment.variables);
let headers = JSON.parse(this.environment.headers);
this.environmentParams = [
{
name: this.environment.name,
children: [
{
name: 'variables',
children: variables.filter(v => v.name)
},
{
name: 'headers',
children: headers.filter(v => v.name)
}
],
children: variables.filter(v => v.name),
}
]
];
}
},
data() {
@ -181,6 +182,7 @@ export default {
currentFunc: "",
mockFuncs: MOCKJS_FUNC,
environmentParams: [],
scenarioParams: [],
}
},

View File

@ -47,6 +47,7 @@
<el-tab-pane :label="$t('api_test.request.parameters')" name="parameters">
<ms-api-variable :is-read-only="isReadOnly" :items="request.parameters"
:environment="request.environment"
:scenario="scenario"
:description="$t('api_test.request.parameters_desc')"/>
</el-tab-pane>
<el-tab-pane :label="$t('api_test.request.headers')" name="headers">
@ -69,7 +70,7 @@
import MsApiKeyValue from "../ApiKeyValue";
import MsApiBody from "../ApiBody";
import MsApiAssertions from "../assertion/ApiAssertions";
import {HttpRequest, KeyValue} from "../../model/ScenarioModel";
import {HttpRequest, KeyValue, Scenario} from "../../model/ScenarioModel";
import MsApiExtract from "../extract/ApiExtract";
import ApiRequestMethodSelect from "../collapse/ApiRequestMethodSelect";
import {REQUEST_HEADERS} from "@/common/js/constants";
@ -80,6 +81,7 @@ export default {
components: {MsApiVariable, ApiRequestMethodSelect, MsApiExtract, MsApiAssertions, MsApiBody, MsApiKeyValue},
props: {
request: HttpRequest,
scenario: Scenario,
isReadOnly: {
type: Boolean,
default: false

View File

@ -1,27 +1,28 @@
<template>
<div class="request-form">
<component @runDebug="runDebug" :is="component" :is-read-only="isReadOnly" :request="request"/>
<component @runDebug="runDebug" :is="component" :is-read-only="isReadOnly" :request="request" :scenario="scenario"/>
<ms-scenario-results v-loading="debugReportLoading" v-if="isCompleted" :scenarios="isCompleted ? request.debugReport.scenarios : []"/>
</div>
</template>
<script>
import {Request, RequestFactory} from "../../model/ScenarioModel";
import MsApiHttpRequestForm from "./ApiHttpRequestForm";
import MsApiDubboRequestForm from "./ApiDubboRequestForm";
import MsScenarioResults from "../../../report/components/ScenarioResults";
import {Request, RequestFactory, Scenario} from "../../model/ScenarioModel";
import MsApiHttpRequestForm from "./ApiHttpRequestForm";
import MsApiDubboRequestForm from "./ApiDubboRequestForm";
import MsScenarioResults from "../../../report/components/ScenarioResults";
export default {
name: "MsApiRequestForm",
components: {MsScenarioResults, MsApiDubboRequestForm, MsApiHttpRequestForm},
props: {
request: Request,
isReadOnly: {
type: Boolean,
default: false
},
debugReportId: String
export default {
name: "MsApiRequestForm",
components: {MsScenarioResults, MsApiDubboRequestForm, MsApiHttpRequestForm},
props: {
scenario: Scenario,
request: Request,
isReadOnly: {
type: Boolean,
default: false
},
debugReportId: String
},
data() {
return {
reportId: "",

View File

@ -873,9 +873,6 @@ class JMXGenerator {
this.addEnvironments(environment.headers, scenario.headers)
}
let headers = this.filterKV(scenario.headers);
headers.forEach(h => {
h.value = calculate(h.value);
});
if (headers.length > 0) {
let name = scenario.name + " Headers"
threadGroup.put(new HeaderManager(name, headers));
@ -886,9 +883,6 @@ class JMXGenerator {
let name = request.name + " Headers";
this.addBodyFormat(request);
let headers = this.filterKV(request.headers);
headers.forEach(h => {
h.value = calculate(h.value);
});
if (headers.length > 0) {
httpSamplerProxy.put(new HeaderManager(name, headers));
}