This commit is contained in:
chenjianxing 2020-12-15 16:25:21 +08:00
commit 43a7912fc9
38 changed files with 292 additions and 215 deletions

View File

@ -373,6 +373,12 @@
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
<!-- 反射工具包 -->
<dependency>
<groupId>net.oneandone.reflections8</groupId>
<artifactId>reflections8</artifactId>
<version>0.11.7</version>
</dependency>
</dependencies>
<build>

View File

@ -4,6 +4,7 @@ import io.metersphere.api.dto.definition.ApiTestCaseRequest;
import io.metersphere.api.dto.definition.ApiTestCaseResult;
import io.metersphere.api.dto.definition.SaveApiTestCaseRequest;
import io.metersphere.api.service.ApiTestCaseService;
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.SessionUtils;
import org.apache.shiro.authz.annotation.Logical;
@ -43,4 +44,9 @@ public class ApiTestCaseController {
apiTestCaseService.delete(id);
}
@GetMapping("/get/{id}")
public ApiTestCaseWithBLOBs get(@PathVariable String id) {
return apiTestCaseService.get(id);
}
}

View File

@ -32,16 +32,16 @@ import java.util.List;
public class MsScenario extends MsTestElement {
private String type = "scenario";
@JSONField(ordinal = 10)
@JSONField(ordinal = 20)
private String name;
@JSONField(ordinal = 11)
@JSONField(ordinal = 21)
private String referenced;
@JSONField(ordinal = 12)
@JSONField(ordinal = 22)
private String environmentId;
@JSONField(ordinal = 13)
@JSONField(ordinal = 23)
private List<KeyValue> variables;
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {

View File

@ -76,8 +76,9 @@ public abstract class MsTestElement {
private String index;
@JSONField(ordinal = 8)
private boolean enable = true;
@JSONField(ordinal = 9)
private String refType ;
@JSONField(ordinal = 10)
private LinkedList<MsTestElement> hashTree;
// 公共环境逐层传递如果自身有环境 以自身引用环境为准否则以公共环境作为请求环境

View File

@ -24,31 +24,31 @@ import java.util.List;
@JSONType(typeName = "AuthManager")
public class MsAuthManager extends MsTestElement {
private String type = "AuthManager";
@JSONField(ordinal = 10)
@JSONField(ordinal = 20)
private String username;
@JSONField(ordinal = 11)
@JSONField(ordinal = 21)
private String password;
@JSONField(ordinal = 12)
@JSONField(ordinal = 22)
private String url;
@JSONField(ordinal = 13)
@JSONField(ordinal = 23)
private String realm;
@JSONField(ordinal = 14)
@JSONField(ordinal = 24)
private String verification;
@JSONField(ordinal = 15)
@JSONField(ordinal = 25)
private String mechanism;
@JSONField(ordinal = 16)
@JSONField(ordinal = 26)
private String encrypt;
@JSONField(ordinal = 17)
@JSONField(ordinal = 27)
private String domain;
@JSONField(ordinal = 18)
@JSONField(ordinal = 28)
private String environment;
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {

View File

@ -22,7 +22,7 @@ import java.util.List;
public class MsHeaderManager extends MsTestElement {
private String type = "HeaderManager";
@JSONField(ordinal = 10)
@JSONField(ordinal = 20)
private List<KeyValue> headers;
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {

View File

@ -20,10 +20,10 @@ import java.util.List;
public class MsJSR223Processor extends MsTestElement {
private String type = "JSR223Processor";
@JSONField(ordinal = 10)
@JSONField(ordinal = 20)
private String script;
@JSONField(ordinal = 11)
@JSONField(ordinal = 21)
private String scriptLanguage;
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {

View File

@ -20,10 +20,10 @@ import java.util.List;
public class MsJSR223PostProcessor extends MsTestElement {
private String type = "JSR223PostProcessor";
@JSONField(ordinal = 10)
@JSONField(ordinal = 20)
private String script;
@JSONField(ordinal = 11)
@JSONField(ordinal = 21)
private String scriptLanguage;

View File

@ -20,10 +20,10 @@ import java.util.List;
public class MsJSR223PreProcessor extends MsTestElement {
private String type = "JSR223PreProcessor";
@JSONField(ordinal = 10)
@JSONField(ordinal = 20)
private String script;
@JSONField(ordinal = 11)
@JSONField(ordinal = 21)
private String scriptLanguage;
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {

View File

@ -51,6 +51,9 @@ public class MsDubboSampler extends MsTestElement {
@JSONField(ordinal = 59)
private List<KeyValue> attachmentArgs;
@JSONField(ordinal = 60)
private Object requestResult;
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) {
return;

View File

@ -40,51 +40,54 @@ import java.util.regex.Pattern;
public class MsHTTPSamplerProxy extends MsTestElement {
private String type = "HTTPSamplerProxy";
@JSONField(ordinal = 10)
@JSONField(ordinal = 20)
private String protocol;
@JSONField(ordinal = 11)
@JSONField(ordinal = 21)
private String domain;
@JSONField(ordinal = 12)
@JSONField(ordinal = 22)
private String port;
@JSONField(ordinal = 13)
@JSONField(ordinal = 23)
private String method;
@JSONField(ordinal = 14)
@JSONField(ordinal = 24)
private String path;
@JSONField(ordinal = 15)
@JSONField(ordinal = 25)
private String connectTimeout;
@JSONField(ordinal = 16)
@JSONField(ordinal = 26)
private String responseTimeout;
@JSONField(ordinal = 17)
@JSONField(ordinal = 27)
private List<KeyValue> headers;
@JSONField(ordinal = 18)
@JSONField(ordinal = 28)
private Body body;
@JSONField(ordinal = 19)
@JSONField(ordinal = 29)
private List<KeyValue> rest;
@JSONField(ordinal = 20)
@JSONField(ordinal = 30)
private String url;
@JSONField(ordinal = 21)
@JSONField(ordinal = 31)
private boolean followRedirects;
@JSONField(ordinal = 22)
@JSONField(ordinal = 32)
private boolean doMultipartPost;
@JSONField(ordinal = 23)
@JSONField(ordinal = 33)
private String useEnvironment;
@JSONField(ordinal = 24)
@JSONField(ordinal = 34)
private List<KeyValue> arguments;
@JSONField(ordinal = 35)
private Object requestResult;
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) {
return;

View File

@ -24,20 +24,22 @@ import java.util.List;
public class MsJDBCSampler extends MsTestElement {
// type 必须放最前面以便能够转换正确的类
private String type = "JDBCSampler";
@JSONField(ordinal = 10)
@JSONField(ordinal = 20)
private DatabaseConfig dataSource;
@JSONField(ordinal = 11)
@JSONField(ordinal = 21)
private String query;
@JSONField(ordinal = 12)
@JSONField(ordinal = 22)
private long queryTimeout;
@JSONField(ordinal = 13)
@JSONField(ordinal = 23)
private String resultVariable;
@JSONField(ordinal = 14)
@JSONField(ordinal = 24)
private String variableNames;
@JSONField(ordinal = 15)
@JSONField(ordinal = 25)
private List<KeyValue> variables;
@JSONField(ordinal = 16)
@JSONField(ordinal = 26)
private String environmentId;
@JSONField(ordinal = 27)
private Object requestResult;
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) {

View File

@ -20,34 +20,36 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
@JSONType(typeName = "TCPSampler")
public class MsTCPSampler extends MsTestElement {
@JSONField(ordinal = 10)
private String type = "TCPSampler";
@JSONField(ordinal = 11)
private String classname = "";
@JSONField(ordinal = 12)
private String server = "";
@JSONField(ordinal = 13)
private String port = "";
@JSONField(ordinal = 14)
private String ctimeout = "";
@JSONField(ordinal = 15)
private String timeout = "";
@JSONField(ordinal = 16)
private boolean reUseConnection = true;
@JSONField(ordinal = 17)
private boolean nodelay;
@JSONField(ordinal = 18)
private boolean closeConnection;
@JSONField(ordinal = 19)
private String soLinger = "";
@JSONField(ordinal = 20)
private String eolByte = "";
private String type = "TCPSampler";
@JSONField(ordinal = 21)
private String username = "";
private String classname = "";
@JSONField(ordinal = 22)
private String password = "";
private String server = "";
@JSONField(ordinal = 23)
private String port = "";
@JSONField(ordinal = 24)
private String ctimeout = "";
@JSONField(ordinal = 25)
private String timeout = "";
@JSONField(ordinal = 26)
private boolean reUseConnection = true;
@JSONField(ordinal = 27)
private boolean nodelay;
@JSONField(ordinal = 28)
private boolean closeConnection;
@JSONField(ordinal = 29)
private String soLinger = "";
@JSONField(ordinal = 30)
private String eolByte = "";
@JSONField(ordinal = 31)
private String username = "";
@JSONField(ordinal = 32)
private String password = "";
@JSONField(ordinal = 33)
private String request;
@JSONField(ordinal = 34)
private Object requestResult;
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) {

View File

@ -19,9 +19,9 @@ import java.util.List;
@JSONType(typeName = "ConstantTimer")
public class MsConstantTimer extends MsTestElement {
private String type = "ConstantTimer";
@JSONField(ordinal = 10)
@JSONField(ordinal = 20)
private String id;
@JSONField(ordinal = 11)
@JSONField(ordinal = 21)
private String delay;
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {

View File

@ -52,7 +52,7 @@ public class ApiTestCaseService {
return extApiTestCaseMapper.list(request);
}
public ApiTestCase get(String id) {
public ApiTestCaseWithBLOBs get(String id) {
return apiTestCaseMapper.selectByPrimaryKey(id);
}

View File

@ -58,7 +58,8 @@ public abstract class AbstractEngine implements Engine {
if (resourcePool == null) {
MSException.throwException("Resource Pool is empty");
}
if (!ResourcePoolTypeEnum.NODE.name().equals(resourcePool.getType())) {
if (!ResourcePoolTypeEnum.K8S.name().equals(resourcePool.getType())
&& !ResourcePoolTypeEnum.NODE.name().equals(resourcePool.getType())) {
MSException.throwException("Invalid Resource Pool type.");
}
this.resourceList = testResourceService.getResourcesByPoolId(resourcePool.getId());

View File

@ -2,6 +2,7 @@ package io.metersphere.performance.engine;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.Application;
import io.metersphere.base.domain.FileContent;
import io.metersphere.base.domain.FileMetadata;
import io.metersphere.base.domain.LoadTestWithBLOBs;
@ -16,17 +17,17 @@ import io.metersphere.performance.engine.docker.DockerTestEngine;
import io.metersphere.performance.parse.EngineSourceParser;
import io.metersphere.performance.parse.EngineSourceParserFactory;
import io.metersphere.service.FileService;
import io.metersphere.service.KubernetesTestEngine;
import io.metersphere.service.TestResourcePoolService;
import org.apache.commons.beanutils.ConstructorUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.reflections8.Reflections;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@Service
@ -34,6 +35,17 @@ public class EngineFactory {
private static FileService fileService;
private static TestResourcePoolService testResourcePoolService;
private static KafkaProperties kafkaProperties;
private static Class<? extends KubernetesTestEngine> kubernetesTestEngineClass;
static {
Reflections reflections = new Reflections(Application.class.getPackage().getName());
Set<Class<? extends KubernetesTestEngine>> implClass = reflections.getSubTypesOf(KubernetesTestEngine.class);
for (Class<? extends KubernetesTestEngine> aClass : implClass) {
kubernetesTestEngineClass = aClass;
// 第一个
break;
}
}
public static Engine createEngine(LoadTestWithBLOBs loadTest) {
String resourcePoolId = loadTest.getTestResourcePoolId();
@ -51,6 +63,14 @@ public class EngineFactory {
if (type == ResourcePoolTypeEnum.NODE) {
return new DockerTestEngine(loadTest);
}
if (type == ResourcePoolTypeEnum.K8S) {
try {
return ConstructorUtils.invokeConstructor(kubernetesTestEngineClass, loadTest);
} catch (Exception e) {
LogUtil.error(e);
return null;
}
}
return null;
}

View File

@ -0,0 +1,6 @@
package io.metersphere.service;
import io.metersphere.performance.engine.Engine;
public interface KubernetesTestEngine extends Engine {
}

@ -1 +1 @@
Subproject commit bb494fc68a2367359c9048fa7250c7618de4afb6
Subproject commit 1fe20ba15a7ca3fe9f77ddf866021e7c7dfe5969

View File

@ -1,3 +1,3 @@
for file in ${TESTS_DIR}/*.jmx; do
jmeter -n -t ${file} -Jserver.rmi.ssl.disable=${SSL_DISABLED} -l ${TESTS_DIR}/${REPORT_ID}.jtl
jmeter -n -t ${file} -Jserver.rmi.ssl.disable=${SSL_DISABLED}
done

View File

@ -11,12 +11,12 @@
<div>
<ms-scenario-results :scenarios="content.scenarios" v-on:requestResult="requestResult"/>
</div>
<el-collapse-transition>
<div v-show="isActive" style="width: 99%">
<ms-request-result-tail v-if="isRequestResult" :request-type="requestType" :request="request"
:scenario-name="scenarioName"/>
</div>
</el-collapse-transition>
<!--<el-collapse-transition>-->
<!--<div v-show="isActive" style="width: 99%">-->
<!--<ms-request-result-tail v-if="isRequestResult" :request-type="requestType" :request="request"-->
<!--:scenario-name="scenarioName"/>-->
<!--</div>-->
<!--</el-collapse-transition>-->
<ms-api-report-export v-if="reportExportVisible" id="apiTestReport" :title="report.testName"
:content="content" :total-time="totalTime"/>
</main>

View File

@ -36,6 +36,13 @@
</el-col>
</el-row>
</div>
<el-collapse-transition>
<div v-show="isActive" style="width: 99%">
<ms-request-result-tail v-if="isActive" :request-type="requestType" :request="request"
:scenario-name="scenarioName"/>
</div>
</el-collapse-transition>
</div>
</template>
@ -44,21 +51,23 @@
import MsAssertionResults from "./AssertionResults";
import MsRequestText from "./RequestText";
import MsResponseText from "./ResponseText";
import MsRequestResultTail from "./RequestResultTail";
export default {
name: "MsRequestResult",
components: {MsResponseText, MsRequestText, MsAssertionResults, MsRequestMetric},
components: {MsResponseText, MsRequestText, MsAssertionResults, MsRequestMetric, MsRequestResultTail},
props: {
request: Object,
scenarioName: String,
indexNumber: Number,
},
data() {
return {}
return {isActive: false, requestType: undefined,}
},
methods: {
active() {
this.$emit("requestResult", {request: this.request, scenarioName: this.scenarioName});
this.isActive = !this.isActive;
//this.$emit("requestResult", {request: this.request, scenarioName: this.scenarioName});
}
},
}

View File

@ -1,5 +1,5 @@
<template>
<el-dialog :close-on-click-modal="false" :title="$t('api_test.definition.request.title')" :visible.sync="visible"
<el-dialog :close-on-click-modal="false" :title="$t('api_test.automation.create_tag')" :visible.sync="visible"
width="45%"
:destroy-on-close="true">
<el-form :model="tagForm" label-position="right" label-width="80px" size="small" :rules="rule" ref="tagForm">
@ -16,11 +16,11 @@
</el-form>
<el-table :data="tagData" row-key="id">
<el-table-column prop="name" :label="$t('api_test.definition.api_name')" show-overflow-tooltip/>
<el-table-column prop="name" :label="$t('commons.name')" show-overflow-tooltip/>
<el-table-column :label="$t('commons.operating')" min-width="130" align="center">
<template v-slot:default="scope">
<el-button type="text" @click="editApi(scope.row)">编辑</el-button>
<el-button type="text" @click="handleDelete(scope.row)" style="color: #F56C6C">删除</el-button>
<el-button type="text" @click="editApi(scope.row)">{{$t('commons.edit')}}</el-button>
<el-button type="text" @click="handleDelete(scope.row)" style="color: #F56C6C">{{$t('commons.delete')}}</el-button>
</template>
</el-table-column>
</el-table>

View File

@ -24,8 +24,10 @@
<el-tag size="mini" style="margin-left: 20px" v-if="request.referenced ==='REF'">{{ $t('api_test.scenario.reference') }}</el-tag>
<div style="margin-right: 20px; float: right">
<i class="icon el-icon-arrow-right" :class="{'is-active': request.active}"
@click="active(request)" v-if="request.referenced!=undefined && request.referenced!='Deleted' && request.referenced!='REF'"/>
@click="active(request)"/>
<el-switch v-model="request.enable" style="margin-left: 10px"/>
<el-button @click="run" :tip="$t('api_test.run')" icon="el-icon-video-play"
style="background-color: #409EFF;color: white;margin-left: 10px" size="mini" circle/>
<el-button size="mini" icon="el-icon-copy-document" circle @click="copyRow" style="margin-left: 10px"/>
<el-button size="mini" icon="el-icon-delete" type="danger" circle @click="remove" style="margin-left: 10px"/>
</div>
@ -45,6 +47,10 @@
<ms-tcp-basis-parameters :request="request" v-if="request.protocol==='TCP'"/>
<ms-sql-basis-parameters :request="request" v-if="request.protocol==='SQL'"/>
<ms-dubbo-basis-parameters :request="request" v-if="request.protocol==='DUBBO' || request.protocol==='dubbo://'"/>
<p class="tip">{{$t('api_test.definition.request.res_param')}} </p>
<ms-request-result-tail :response="request.requestResult" ref="runResult"/>
<!-- 保存操作 -->
<el-button type="primary" size="small" style="margin: 20px; float: right" @click="saveTestCase(item)" v-if="!request.referenced">
{{$t('commons.save')}}
@ -52,6 +58,9 @@
</div>
</el-collapse-transition>
</el-card>
<!-- 执行组件 -->
<ms-run :debug="false" :reportId="reportId" :run-data="runData"
@runRefresh="runRefresh" ref="runTest"/>
</div>
</template>
@ -61,29 +70,27 @@
import MsDubboBasisParameters from "../../definition/components/request/dubbo/BasisParameters";
import MsApiRequestForm from "../../definition/components/request/http/ApiRequestForm";
import {REQ_METHOD} from "../../definition/model/JsonData";
import MsRequestResultTail from "../../definition/components/response/RequestResultTail";
import MsRun from "../../definition/components/Run";
import {getUUID} from "@/common/js/utils";
export default {
name: "MsApiComponent",
props: {
request: {},
node: {},
currentEnvironmentId: String,
},
components: {MsSqlBasisParameters, MsTcpBasisParameters, MsDubboBasisParameters, MsApiRequestForm},
components: {MsSqlBasisParameters, MsTcpBasisParameters, MsDubboBasisParameters, MsApiRequestForm, MsRequestResultTail, MsRun},
data() {
return {loading: false, reqOptions: REQ_METHOD,}
return {loading: false, reqOptions: REQ_METHOD, reportId: "", runData: []}
},
created() {
if (this.request.id && this.request.referenced === 'REF') {
this.$get("/api/definition/get/" + this.request.id, response => {
if (response.data) {
this.request.name = response.data.name;
this.reload();
} else {
this.request.referenced = "Deleted";
if (!this.request.requestResult) {
this.request.requestResult = {responseResult: {}};
}
})
}
//
this.getApiInfo();
if (this.request.protocol === 'HTTP') {
try {
let urlObject = new URL(this.request.url);
@ -105,10 +112,47 @@
copyRow() {
this.$emit('copyRow', this.request, this.node);
},
getApiInfo() {
if (this.request.id && this.request.referenced === 'REF') {
let requestResult = this.request.requestResult;
let url = this.request.refType && this.request.refType === 'CASE' ? "/api/testcase/get/" : "/api/definition/get/";
this.$get(url + this.request.id, response => {
if (response.data) {
Object.assign(this.request, JSON.parse(response.data.request));
this.request.name = response.data.name;
this.request.path = response.data.path;
this.request.method = response.data.method;
this.request.url = response.data.path;
this.request.requestResult = requestResult;
this.request.id = response.data.id;
this.reload();
} else {
this.request.referenced = "Deleted";
}
})
}
},
active(item) {
item.active = !item.active;
this.reload();
},
run() {
if (!this.currentEnvironmentId) {
this.$error(this.$t('api_test.environment.select_environment'));
return;
}
this.loading = true;
this.runData = [];
this.request.useEnvironment = this.currentEnvironmentId;
this.runData.push(this.request);
/*触发执行操作*/
this.reportId = getUUID().substring(0, 8);
},
runRefresh(data) {
this.request.requestResult = data;
this.loading = false;
},
reload() {
this.loading = true
this.$nextTick(() => {

View File

@ -186,7 +186,7 @@
<!--提取规则-->
<ms-api-extract @remove="remove" @copyRow="copyRow" v-if="data.type==='Extract'" customizeStyle="margin-top: 0px" :extract="data" :node="node"/>
<!--API 导入 -->
<ms-api-component :request="data" @remove="remove" @copyRow="copyRow" v-if="data.type==='HTTPSamplerProxy'||data.type==='DubboSampler'||data.type==='JDBCSampler'||data.type==='TCPSampler'" :node="node"/>
<ms-api-component :request="data" :currentEnvironmentId="currentEnvironmentId" @remove="remove" @copyRow="copyRow" v-if="data.type==='HTTPSamplerProxy'||data.type==='DubboSampler'||data.type==='JDBCSampler'||data.type==='TCPSampler'" :node="node"/>
</template>
</span>
</el-tree>
@ -238,8 +238,8 @@
<!--接口列表-->
<el-drawer :visible.sync="apiListVisible" :destroy-on-close="true" direction="ltr" :withHeader="false" :title="$t('api_test.automation.api_list_import')" :modal="false" size="90%">
<ms-api-definition :visible="visibleRef" :currentRow="currentRow"/>
<el-button style="float: right;margin: 0px 20px 0px" type="primary" @click="copyApi('REF')">{{$t('api_test.scenario.reference')}}</el-button>
<el-button style="float: right;" type="primary" @click="copyApi('Copy')">{{ $t('commons.copy') }}</el-button>
<el-button style="float: right;margin: 0px 20px 0px" type="primary" @click="pushApiOrCase('REF')">{{$t('api_test.scenario.reference')}}</el-button>
<el-button style="float: right;" type="primary" @click="pushApiOrCase('Copy')">{{ $t('commons.copy') }}</el-button>
</el-drawer>
<!--自定义接口-->
@ -467,50 +467,39 @@
this.reload();
this.scenarioVisible = false;
},
copyApi(referenced) {
setApiParameter(item, refType, referenced) {
let request = {};
if (Object.prototype.toString.call(item.request).indexOf("String") > 0) {
request = JSON.parse(item.request);
} else {
request = item.request;
}
request.id = item.id;
request.name = item.name;
request.refType = refType;
request.referenced = referenced;
request.enable === undefined ? request.enable = true : request.enable;
request.active = false;
request.resourceId = getUUID();
if (referenced === 'REF' || !request.hashTree) {
request.hashTree = [];
}
if (this.selectedTreeNode != undefined) {
this.selectedTreeNode.hashTree.push(request);
} else {
this.scenarioDefinition.push(request);
}
},
pushApiOrCase(referenced) {
if (this.currentRow.cases.length === 0 && this.currentRow.apis.length === 0) {
this.$warning(this.$t('api_test.automation.reference_info'));
return;
}
this.currentRow.cases.forEach(item => {
let request = {};
if (Object.prototype.toString.call(item.request).indexOf("String") > 0) {
request = JSON.parse(item.request);
} else {
request = item.request;
}
request.referenced = referenced;
request.enable === undefined ? request.enable = true : request.enable;
request.active = false;
request.resourceId = getUUID();
if (referenced === 'REF' || !request.hashTree) {
request.hashTree = [];
}
if (this.selectedTreeNode != undefined) {
this.selectedTreeNode.hashTree.push(request);
} else {
this.scenarioDefinition.push(request);
}
this.setApiParameter(item, "CASE", referenced);
})
this.currentRow.apis.forEach(item => {
let request = {};
if (Object.prototype.toString.call(item.request).indexOf("String") > 0) {
request = JSON.parse(item.request);
} else {
request = item.request;
}
request.referenced = referenced;
request.enable === undefined ? request.enable = true : request.enable;
request.active = false;
request.resourceId = getUUID();
if (referenced === 'REF' || !request.hashTree) {
request.hashTree = [];
}
if (this.selectedTreeNode != undefined) {
this.selectedTreeNode.hashTree.push(request);
} else {
this.scenarioDefinition.push(request);
}
this.setApiParameter(item, "API", referenced);
})
this.apiListVisible = false;
this.currentRow.cases = [];

View File

@ -104,11 +104,6 @@
threadGroup.hashTree = [];
testPlan.hashTree = [threadGroup];
this.runData.forEach(item => {
if (!item.useEnvironment) {
this.$error(this.$t("api_test.environment.select_environment"));
this.$emit('runRefresh', {});
return;
}
threadGroup.hashTree.push(item);
})
let reqObj = {id: this.reportId, testElement: testPlan};

View File

@ -95,6 +95,10 @@
saveApi(saveAs) {
this.$refs['httpForm'].validate((valid) => {
if (valid) {
if(this.httpForm.path.match(/\s/)!=null){
this.$error(this.$t("api_test.definition.request.path_valid_info"));
return false;
}
let bodyFiles = [];
let path = "/api/definition/create";
this.setParameter();

View File

@ -124,6 +124,10 @@
runTest() {
this.$refs['httpForm'].validate((valid) => {
if (valid) {
if(this.httpForm.path.match(/\s/)!=null){
this.$error(this.$t("api_test.definition.request.path_valid_info"));
return false;
}
this.setParameter();
this.$emit('runTest', this.httpForm);
} else {
@ -146,6 +150,10 @@
saveApi() {
this.$refs['httpForm'].validate((valid) => {
if (valid) {
if(this.httpForm.path.match(/\s/)!=null){
this.$error(this.$t("api_test.definition.request.path_valid_info"));
return false;
}
this.setParameter();
this.$emit('saveApi', this.httpForm);
}

View File

@ -186,7 +186,7 @@
copyRow(row) {
let obj = {};
Object.assign(obj, row);
row.id = getUUID();
obj.id = getUUID();
this.request.hashTree.push(obj);
this.reload();
},

View File

@ -90,30 +90,30 @@
</el-form>
</div>
<div v-for="row in request.hashTree" :key="row.id" v-loading="isReloadData" style="margin-left: 20px;width: 100%">
<!-- 前置脚本 -->
<ms-jsr233-processor v-if="row.label ==='JSR223 PreProcessor'" @copyRow="copyRow" @remove="remove" :is-read-only="false" :title="$t('api_test.definition.request.pre_script')" style-type="color: #B8741A;background-color: #F9F1EA"
:jsr223-processor="row"/>
<!--后置脚本-->
<ms-jsr233-processor v-if="row.label ==='JSR223 PostProcessor'" @copyRow="copyRow" @remove="remove" :is-read-only="false" :title="$t('api_test.definition.request.post_script')" style-type="color: #783887;background-color: #F2ECF3"
:jsr223-processor="row"/>
<!--断言规则-->
<ms-api-assertions v-if="row.type==='Assertions'" @copyRow="copyRow" @remove="remove" :is-read-only="isReadOnly" :assertions="row"/>
<!--提取规则-->
<ms-api-extract :is-read-only="isReadOnly" @copyRow="copyRow" @remove="remove" v-if="row.type==='Extract'" :extract="row"/>
<!--<div v-for="row in request.hashTree" :key="row.id" v-loading="isReloadData" style="margin-left: 20px;width: 100%">-->
<!--&lt;!&ndash; 前置脚本 &ndash;&gt;-->
<!--<ms-jsr233-processor v-if="row.label ==='JSR223 PreProcessor'" @copyRow="copyRow" @remove="remove" :is-read-only="false" :title="$t('api_test.definition.request.pre_script')" style-type="color: #B8741A;background-color: #F9F1EA"-->
<!--:jsr223-processor="row"/>-->
<!--&lt;!&ndash;后置脚本&ndash;&gt;-->
<!--<ms-jsr233-processor v-if="row.label ==='JSR223 PostProcessor'" @copyRow="copyRow" @remove="remove" :is-read-only="false" :title="$t('api_test.definition.request.post_script')" style-type="color: #783887;background-color: #F2ECF3"-->
<!--:jsr223-processor="row"/>-->
<!--&lt;!&ndash;断言规则&ndash;&gt;-->
<!--<ms-api-assertions v-if="row.type==='Assertions'" @copyRow="copyRow" @remove="remove" :is-read-only="isReadOnly" :assertions="row"/>-->
<!--&lt;!&ndash;提取规则&ndash;&gt;-->
<!--<ms-api-extract :is-read-only="isReadOnly" @copyRow="copyRow" @remove="remove" v-if="row.type==='Extract'" :extract="row"/>-->
</div>
<!--</div>-->
</el-col>
<el-col :span="3" class="ms-left-cell">
<el-button class="ms-left-buttion" size="small" style="color: #B8741A;background-color: #F9F1EA" @click="addPre">+{{$t('api_test.definition.request.pre_script')}}</el-button>
<br/>
<el-button class="ms-left-buttion" size="small" style="color: #783887;background-color: #F2ECF3" @click="addPost">+{{$t('api_test.definition.request.post_script')}}</el-button>
<br/>
<el-button class="ms-left-buttion" size="small" style="color: #A30014;background-color: #F7E6E9" @click="addAssertions">+{{$t('api_test.definition.request.assertions_rule')}}</el-button>
<br/>
<el-button class="ms-left-buttion" size="small" style="color: #015478;background-color: #E6EEF2" @click="addExtract">+{{$t('api_test.definition.request.extract_param')}}</el-button>
</el-col>
<!--<el-col :span="3" class="ms-left-cell">-->
<!--<el-button class="ms-left-buttion" size="small" style="color: #B8741A;background-color: #F9F1EA" @click="addPre">+{{$t('api_test.definition.request.pre_script')}}</el-button>-->
<!--<br/>-->
<!--<el-button class="ms-left-buttion" size="small" style="color: #783887;background-color: #F2ECF3" @click="addPost">+{{$t('api_test.definition.request.post_script')}}</el-button>-->
<!--<br/>-->
<!--<el-button class="ms-left-buttion" size="small" style="color: #A30014;background-color: #F7E6E9" @click="addAssertions">+{{$t('api_test.definition.request.assertions_rule')}}</el-button>-->
<!--<br/>-->
<!--<el-button class="ms-left-buttion" size="small" style="color: #015478;background-color: #E6EEF2" @click="addExtract">+{{$t('api_test.definition.request.extract_param')}}</el-button>-->
<!--</el-col>-->
</el-row>
</div>
</template>

View File

@ -9,9 +9,9 @@
<ms-sql-result-table v-if="isSqlType" :body="response.responseResult.body"/>
<ms-code-edit v-if="!isSqlType" :mode="mode" :read-only="true" :modes="modes" :data.sync="response.responseResult.body" ref="codeEdit"/>
</el-tab-pane>
<el-tab-pane label="Cookie" name="cookie" class="pane cookie">
<pre>{{response.cookies}}</pre>
</el-tab-pane>
<!--<el-tab-pane label="Cookie" name="cookie" class="pane cookie">-->
<!--<pre>{{response.cookies}}</pre>-->
<!--</el-tab-pane>-->
<el-tab-pane :label="$t('api_test.definition.request.console')" name="console" class="pane">
<pre>{{response.responseResult.console}}</pre>

View File

@ -8,10 +8,7 @@
<el-input :disabled="isReadOnly" class="test-name" v-model="test.name" maxlength="60"
:placeholder="$t('api_test.input_name')"
show-word-limit>
<el-select filterable class="test-project" v-model="test.projectId" slot="prepend"
:placeholder="$t('api_test.select_project')">
<el-option v-for="project in projects" :key="project.id" :label="project.name" :value="project.id"/>
</el-select>
<template slot="prepend">测试名称</template>
</el-input>
<el-tooltip :content="'Ctrl + S'"
@ -80,7 +77,7 @@ import MsApiScenarioConfig from "./components/ApiScenarioConfig";
import {Scenario, Test} from "./model/ScenarioModel"
import MsApiReportStatus from "../report/ApiReportStatus";
import MsApiReportDialog from "./ApiReportDialog";
import {checkoutTestManagerOrTestUser, downloadFile, getUUID} from "@/common/js/utils";
import {checkoutTestManagerOrTestUser, downloadFile, getCurrentProjectID, getUUID} from "@/common/js/utils";
import MsScheduleConfig from "../../common/components/MsScheduleConfig";
import ApiImport from "./components/import/ApiImport";
import {ApiEvent, LIST_CHANGE} from "@/business/components/common/head/ListEvent";
@ -124,8 +121,6 @@ export default {
methods: {
init() {
let projectId;
this.isReadOnly = !checkoutTestManagerOrTestUser();
if (this.id) {
@ -137,14 +132,8 @@ export default {
if (this.$refs.config) {
this.$refs.config.reset();
}
//
projectId = this.$store.state.common.projectId;
}
this.result = this.$get("/project/listAll", response => {
this.projects = response.data;
//
if (projectId) this.test.projectId = projectId;
})
this.test.projectId = getCurrentProjectID();
},
updateReference() {
let updateIds = [];
@ -318,7 +307,6 @@ export default {
break;
case "performance":
this.$store.commit('setTest', {
projectId: this.test.projectId,
name: this.test.name,
jmx: this.test.toJMX()
})

View File

@ -8,10 +8,10 @@
<el-dropdown-item command="personal">{{ $t('commons.personal_information') }}</el-dropdown-item>
<el-dropdown-item command="about">{{ $t('commons.about_us') }} <i class="el-icon-info"/></el-dropdown-item>
<el-dropdown-item command="help">{{ $t('commons.help_documentation') }}</el-dropdown-item>
<el-dropdown-item command="old" :disabled=isReadOnly @click.native="changeBar('old')">
<el-dropdown-item command="old" v-show=isReadOnly @click.native="changeBar('old')">
{{ $t('commons.cut_back_old_version') }}
</el-dropdown-item>
<el-dropdown-item command="new" :disabled=!isReadOnly @click.native="changeBar('new')">
<el-dropdown-item command="new" v-show=!isReadOnly @click.native="changeBar('new')">
{{ $t('commons.cut_back_new_version') }}
</el-dropdown-item>
<el-dropdown-item command="logout">{{ $t('commons.exit_system') }}</el-dropdown-item>
@ -77,6 +77,7 @@
this.isReadOnly = !this.isReadOnly
this.$store.commit('setFlag', this.isReadOnly);
this.$store.commit('setValue', item);
window.location.href = "/#/api/home";
}
}
}

View File

@ -8,17 +8,7 @@
class="input-with-select"
maxlength="30" show-word-limit
>
<template v-slot:prepend>
<el-select filterable v-model="test.projectId"
:placeholder="$t('load_test.select_project')">
<el-option
v-for="item in projects"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</template>
<template slot="prepend">测试名称</template>
</el-input>
</el-col>
<el-col :span="12" :offset="2">
@ -59,7 +49,7 @@ import PerformancePressureConfig from "./components/PerformancePressureConfig";
import PerformanceAdvancedConfig from "./components/PerformanceAdvancedConfig";
import MsContainer from "../../common/components/MsContainer";
import MsMainContainer from "../../common/components/MsMainContainer";
import {checkoutTestManagerOrTestUser} from "@/common/js/utils";
import {checkoutTestManagerOrTestUser, getCurrentProjectID} from "@/common/js/utils";
import MsScheduleConfig from "../../common/components/MsScheduleConfig";
import {LIST_CHANGE, PerformanceEvent} from "@/business/components/common/head/ListEvent";
@ -77,7 +67,6 @@ export default {
return {
result: {},
test: {schedule: {}},
listProjectPath: "/project/listAll",
savePath: "/performance/save",
editPath: "/performance/edit",
runPath: "/performance/run",
@ -127,9 +116,6 @@ export default {
}
this.getTest(this.$route.params.testId);
},
activated() {
this.listProjects();
},
mounted() {
this.importAPITest();
},
@ -137,7 +123,6 @@ export default {
importAPITest() {
let apiTest = this.$store.state.api.test;
if (apiTest && apiTest.name) {
this.$set(this.test, "projectId", apiTest.projectId);
this.$set(this.test, "name", apiTest.name);
let blob = new Blob([apiTest.jmx.xml], {type: "application/octet-stream"});
let file = new File([blob], apiTest.jmx.name);
@ -160,11 +145,6 @@ export default {
});
}
},
listProjects() {
this.result = this.$get(this.listProjectPath, response => {
this.projects = response.data;
})
},
save() {
if (!this.validTest()) {
return;
@ -237,6 +217,9 @@ export default {
this.$router.push({path: '/performance/test/all'})
},
validTest() {
let currentProjectId = getCurrentProjectID();
this.test.projectId = currentProjectId;
if (!this.test.name) {
this.$error(this.$t('load_test.test_name_is_null'));
return false;

@ -1 +1 @@
Subproject commit a22a3005d9bd254793fcf634d72539cbdf31be3a
Subproject commit 29a8fc09602fde5708af06582ac972d98eb69836

View File

@ -1,5 +1,6 @@
export default {
commons: {
please_fill_in_the_template: 'Please fill in the template',
cut_back_old_version: 'Cut back to old version',
cut_back_new_version: 'Switch back to new version',
comment: 'comment',
@ -541,6 +542,7 @@ export default {
create_info: 'Create',
update_info: 'Update',
batch_edit: "Batch edit",
path_valid_info: "The request address cannot contain spaces",
}
},
automation: {

View File

@ -1,5 +1,6 @@
export default {
commons: {
please_fill_in_the_template: '请填写模版内容',
cut_back_old_version: '切回旧版',
cut_back_new_version: '切回新版',
comment: '评论',
@ -540,6 +541,7 @@ export default {
create_info: '创建',
update_info: '更新',
batch_edit: "批量编辑",
path_valid_info: "请求地址不能包含空格",
}
},
automation: {

View File

@ -1,5 +1,6 @@
export default {
commons: {
please_fill_in_the_template: '請填寫模版內容',
cut_back_old_version: '切回舊版',
cut_back_new_version: '切回新版',
comment: '評論',
@ -540,6 +541,7 @@ export default {
create_info: '創建',
update_info: '更新',
batch_edit: "批量編輯",
path_valid_info: "請求地址不能包含空格",
}
},
automation: {