feat(接口测试): 处理变量
This commit is contained in:
parent
9bad4b4a83
commit
01e22c9f1a
|
@ -36,7 +36,8 @@
|
||||||
<el-main class="scenario-main">
|
<el-main class="scenario-main">
|
||||||
<div class="scenario-form">
|
<div class="scenario-form">
|
||||||
<ms-api-scenario-form :is-read-only="isReadOnly" :scenario="selected" :project-id="projectId" v-if="isScenario"/>
|
<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>
|
</div>
|
||||||
</el-main>
|
</el-main>
|
||||||
</el-container>
|
</el-container>
|
||||||
|
@ -49,7 +50,7 @@
|
||||||
import MsApiRequestConfig from "./request/ApiRequestConfig";
|
import MsApiRequestConfig from "./request/ApiRequestConfig";
|
||||||
import MsApiRequestForm from "./request/ApiRequestForm";
|
import MsApiRequestForm from "./request/ApiRequestForm";
|
||||||
import MsApiScenarioForm from "./ApiScenarioForm";
|
import MsApiScenarioForm from "./ApiScenarioForm";
|
||||||
import {Scenario, Request} from "../model/ScenarioModel";
|
import {Request, Scenario} from "../model/ScenarioModel";
|
||||||
import draggable from 'vuedraggable';
|
import draggable from 'vuedraggable';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
|
@ -79,8 +79,9 @@
|
||||||
<div v-if="environment">
|
<div v-if="environment">
|
||||||
<el-tree :data="environmentParams" :props="{ children: 'children', label: 'name'}"></el-tree>
|
<el-tree :data="environmentParams" :props="{ children: 'children', label: 'name'}"></el-tree>
|
||||||
</div>
|
</div>
|
||||||
场景
|
<div v-if="scenario">
|
||||||
请求1
|
<el-tree :data="scenarioParams" :props="{ children: 'children', label: 'name'}"></el-tree>
|
||||||
|
</div>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
|
@ -109,7 +110,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {KeyValue} from "../model/ScenarioModel";
|
import {KeyValue, Scenario} from "../model/ScenarioModel";
|
||||||
import {MOCKJS_FUNC} from "@/common/js/constants";
|
import {MOCKJS_FUNC} from "@/common/js/constants";
|
||||||
import {calculate} from "@/business/components/api/test/model/ScenarioModel";
|
import {calculate} from "@/business/components/api/test/model/ScenarioModel";
|
||||||
|
|
||||||
|
@ -122,6 +123,7 @@ export default {
|
||||||
description: String,
|
description: String,
|
||||||
items: Array,
|
items: Array,
|
||||||
environment: Object,
|
environment: Object,
|
||||||
|
scenario: Scenario,
|
||||||
isReadOnly: {
|
isReadOnly: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
|
@ -129,24 +131,23 @@ export default {
|
||||||
suggestions: Array
|
suggestions: Array
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
if (this.scenario) {
|
||||||
|
let variables = this.scenario.variables;
|
||||||
|
this.scenarioParams = [
|
||||||
|
{
|
||||||
|
name: this.scenario.name,
|
||||||
|
children: variables.filter(v => v.name),
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
if (this.environment) {
|
if (this.environment) {
|
||||||
let variables = JSON.parse(this.environment.variables);
|
let variables = JSON.parse(this.environment.variables);
|
||||||
let headers = JSON.parse(this.environment.headers);
|
|
||||||
this.environmentParams = [
|
this.environmentParams = [
|
||||||
{
|
{
|
||||||
name: this.environment.name,
|
name: this.environment.name,
|
||||||
children: [
|
children: variables.filter(v => v.name),
|
||||||
{
|
|
||||||
name: 'variables',
|
|
||||||
children: variables.filter(v => v.name)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'headers',
|
|
||||||
children: headers.filter(v => v.name)
|
|
||||||
}
|
}
|
||||||
],
|
];
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
|
@ -181,6 +182,7 @@ export default {
|
||||||
currentFunc: "",
|
currentFunc: "",
|
||||||
mockFuncs: MOCKJS_FUNC,
|
mockFuncs: MOCKJS_FUNC,
|
||||||
environmentParams: [],
|
environmentParams: [],
|
||||||
|
scenarioParams: [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
<el-tab-pane :label="$t('api_test.request.parameters')" name="parameters">
|
<el-tab-pane :label="$t('api_test.request.parameters')" name="parameters">
|
||||||
<ms-api-variable :is-read-only="isReadOnly" :items="request.parameters"
|
<ms-api-variable :is-read-only="isReadOnly" :items="request.parameters"
|
||||||
:environment="request.environment"
|
:environment="request.environment"
|
||||||
|
:scenario="scenario"
|
||||||
:description="$t('api_test.request.parameters_desc')"/>
|
:description="$t('api_test.request.parameters_desc')"/>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
<el-tab-pane :label="$t('api_test.request.headers')" name="headers">
|
<el-tab-pane :label="$t('api_test.request.headers')" name="headers">
|
||||||
|
@ -69,7 +70,7 @@
|
||||||
import MsApiKeyValue from "../ApiKeyValue";
|
import MsApiKeyValue from "../ApiKeyValue";
|
||||||
import MsApiBody from "../ApiBody";
|
import MsApiBody from "../ApiBody";
|
||||||
import MsApiAssertions from "../assertion/ApiAssertions";
|
import MsApiAssertions from "../assertion/ApiAssertions";
|
||||||
import {HttpRequest, KeyValue} from "../../model/ScenarioModel";
|
import {HttpRequest, KeyValue, Scenario} from "../../model/ScenarioModel";
|
||||||
import MsApiExtract from "../extract/ApiExtract";
|
import MsApiExtract from "../extract/ApiExtract";
|
||||||
import ApiRequestMethodSelect from "../collapse/ApiRequestMethodSelect";
|
import ApiRequestMethodSelect from "../collapse/ApiRequestMethodSelect";
|
||||||
import {REQUEST_HEADERS} from "@/common/js/constants";
|
import {REQUEST_HEADERS} from "@/common/js/constants";
|
||||||
|
@ -80,6 +81,7 @@ export default {
|
||||||
components: {MsApiVariable, ApiRequestMethodSelect, MsApiExtract, MsApiAssertions, MsApiBody, MsApiKeyValue},
|
components: {MsApiVariable, ApiRequestMethodSelect, MsApiExtract, MsApiAssertions, MsApiBody, MsApiKeyValue},
|
||||||
props: {
|
props: {
|
||||||
request: HttpRequest,
|
request: HttpRequest,
|
||||||
|
scenario: Scenario,
|
||||||
isReadOnly: {
|
isReadOnly: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="request-form">
|
<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 : []"/>
|
<ms-scenario-results v-loading="debugReportLoading" v-if="isCompleted" :scenarios="isCompleted ? request.debugReport.scenarios : []"/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {Request, RequestFactory} from "../../model/ScenarioModel";
|
import {Request, RequestFactory, Scenario} from "../../model/ScenarioModel";
|
||||||
import MsApiHttpRequestForm from "./ApiHttpRequestForm";
|
import MsApiHttpRequestForm from "./ApiHttpRequestForm";
|
||||||
import MsApiDubboRequestForm from "./ApiDubboRequestForm";
|
import MsApiDubboRequestForm from "./ApiDubboRequestForm";
|
||||||
import MsScenarioResults from "../../../report/components/ScenarioResults";
|
import MsScenarioResults from "../../../report/components/ScenarioResults";
|
||||||
|
@ -15,6 +15,7 @@
|
||||||
name: "MsApiRequestForm",
|
name: "MsApiRequestForm",
|
||||||
components: {MsScenarioResults, MsApiDubboRequestForm, MsApiHttpRequestForm},
|
components: {MsScenarioResults, MsApiDubboRequestForm, MsApiHttpRequestForm},
|
||||||
props: {
|
props: {
|
||||||
|
scenario: Scenario,
|
||||||
request: Request,
|
request: Request,
|
||||||
isReadOnly: {
|
isReadOnly: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
|
|
@ -873,9 +873,6 @@ class JMXGenerator {
|
||||||
this.addEnvironments(environment.headers, scenario.headers)
|
this.addEnvironments(environment.headers, scenario.headers)
|
||||||
}
|
}
|
||||||
let headers = this.filterKV(scenario.headers);
|
let headers = this.filterKV(scenario.headers);
|
||||||
headers.forEach(h => {
|
|
||||||
h.value = calculate(h.value);
|
|
||||||
});
|
|
||||||
if (headers.length > 0) {
|
if (headers.length > 0) {
|
||||||
let name = scenario.name + " Headers"
|
let name = scenario.name + " Headers"
|
||||||
threadGroup.put(new HeaderManager(name, headers));
|
threadGroup.put(new HeaderManager(name, headers));
|
||||||
|
@ -886,9 +883,6 @@ class JMXGenerator {
|
||||||
let name = request.name + " Headers";
|
let name = request.name + " Headers";
|
||||||
this.addBodyFormat(request);
|
this.addBodyFormat(request);
|
||||||
let headers = this.filterKV(request.headers);
|
let headers = this.filterKV(request.headers);
|
||||||
headers.forEach(h => {
|
|
||||||
h.value = calculate(h.value);
|
|
||||||
});
|
|
||||||
if (headers.length > 0) {
|
if (headers.length > 0) {
|
||||||
httpSamplerProxy.put(new HeaderManager(name, headers));
|
httpSamplerProxy.put(new HeaderManager(name, headers));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue