fix: 修复接口测试落干bug

This commit is contained in:
chenjianxing 2020-07-15 20:45:33 +08:00
parent ddf4d7f938
commit bfa01c09e9
6 changed files with 58 additions and 1180 deletions

File diff suppressed because one or more lines are too long

View File

@ -255,7 +255,7 @@
return this.test.isValid() && !this.change;
},
isDisabled() {
return !(this.test.isValid() && this.change)
return !(this.test.isValid())
}
},

View File

@ -90,14 +90,14 @@
activeName: "parameters",
rules: {
name: [
{max: 100, message: this.$t('commons.input_limit', [0, 100]), trigger: 'blur'}
{max: 100, message: this.$t('commons.input_limit', [1, 100]), trigger: 'blur'}
],
url: [
{max: 500, required: true, message: this.$t('commons.input_limit', [0, 500]), trigger: 'blur'},
{max: 500, required: true, message: this.$t('commons.input_limit', [1, 500]), trigger: 'blur'},
{validator: validateURL, trigger: 'blur'}
],
path: [
{max: 500, required: true, message: this.$t('commons.input_limit', [0, 500]), trigger: 'blur'},
{max: 500, required: true, message: this.$t('commons.input_limit', [1, 500]), trigger: 'blur'},
]
}
}
@ -143,6 +143,7 @@
this.$error(this.$t('api_test.request.please_add_environment_to_scenario'), 2000);
this.request.useEnvironment = false;
}
this.$refs["request"].clearValidate();
},
addProtocol(url) {
if (url) {

View File

@ -8,6 +8,11 @@
<el-select :disabled="isReadOnly" v-model="scenario.environmentId" class="environment-select" @change="environmentChange" clearable>
<el-option v-for="(environment, index) in environments" :key="index" :label="environment.name + ': ' + environment.protocol + '://' + environment.socket" :value="environment.id"/>
<el-button class="environment-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="environment-button" size="mini" type="primary" @click="openEnvironmentConfig">{{$t('api_test.environment.environment_config')}}</el-button>
</div>
</template>
</el-select>
</el-form-item>
@ -65,18 +70,32 @@
}
}
},
watch: {
projectId() {
this.getEnvironments();
}
},
methods: {
getEnvironments() {
if (this.projectId) {
this.result = this.$get('/api/environment/list/' + this.projectId, response => {
this.environments = response.data;
let hasEnvironment = false;
for (let i in this.environments) {
if (this.environments[i].id === this.scenario.environmentId) {
this.scenario.environment = this.environments[i];
hasEnvironment = true;
break;
}
}
if (!hasEnvironment) {
this.scenario.environmentId = '';
this.scenario.environment = undefined;
}
});
} else {
this.scenario.environmentId = '';
this.scenario.environment = undefined;
}
},
environmentChange(value) {
@ -97,6 +116,10 @@
}
},
openEnvironmentConfig() {
if (!this.projectId) {
this.$error(this.$t('api_test.select_project'));
return;
}
this.$refs.environmentConfig.open(this.projectId);
},
environmentConfigClose() {
@ -117,4 +140,8 @@
padding: 7px;
}
.empty-environment {
padding: 10px 0px;
}
</style>

View File

@ -61,7 +61,10 @@
return {
result: {},
rules: {
name :[{required: true, message: this.$t('commons.input_name'), trigger: 'blur'}],
name :[
{required: true, message: this.$t('commons.input_name'), trigger: 'blur'},
{max: 64, message: this.$t('commons.input_limit', [1, 64]), trigger: 'blur'}
],
socket :[{required: true, validator: socketValidator, trigger: 'blur'}],
},
}
@ -83,7 +86,9 @@
url = '/api/environment/update';
}
this.result = this.$post(url, param, response => {
this.environment.id = response.data;
if (!param.id) {
this.environment.id = response.data;
}
this.$success(this.$t('commons.save_success'));
});
},

View File

@ -169,9 +169,6 @@ export class Scenario extends BaseConfig {
return false;
}
}
if (!this.name) {
return false;
}
return true;
}
}
@ -396,8 +393,6 @@ class JMXRequest {
constructor(request) {
if (request && request instanceof Request && (request.url || request.path)) {
this.useEnvironment = request.useEnvironment;
this.environment = request.environment;
this.path = decodeURIComponent(request.path);
this.method = request.method;
if (!request.useEnvironment) {
let url = new URL(request.url);
@ -405,19 +400,28 @@ class JMXRequest {
this.pathname = decodeURIComponent(url.pathname);
this.port = url.port;
this.protocol = url.protocol.split(":")[0];
}
if (this.method.toUpperCase() !== "GET") {
// this.pathname += url.search.replace('&', '&amp;');
this.pathname += '?';
request.parameters.forEach(parameter => {
if (parameter.name) {
this.pathname += (parameter.name + '=' + parameter.value + '&');
}
});
this.pathname = this.getPostQueryParameters(request, this.pathname);
} else {
this.environment = request.environment;
this.port = request.environment.port;
this.path = decodeURIComponent(request.path);
this.path = this.getPostQueryParameters(request, this.path);
}
}
}
getPostQueryParameters(request, path) {
if (this.method.toUpperCase() !== "GET") {
path += '?';
request.parameters.forEach(parameter => {
if (parameter.name) {
path += (parameter.name + '=' + parameter.value + '&');
}
});
}
return path;
}
}
class JMeterTestPlan extends Element {