diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestBatchRequest.java b/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestBatchRequest.java index fae3495019..ab2788aae6 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestBatchRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestBatchRequest.java @@ -1,13 +1,10 @@ package io.metersphere.api.dto.definition; -import io.metersphere.base.domain.ApiDefinitionWithBLOBs; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.controller.request.OrderRequest; import lombok.Getter; import lombok.Setter; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -32,6 +29,10 @@ public class ApiTestBatchRequest extends ApiTestCaseWithBLOBs { private String name; + private String method; + + private String path; + private List moduleIds; private List unSelectIds; @@ -39,13 +40,4 @@ public class ApiTestBatchRequest extends ApiTestCaseWithBLOBs { private String protocol; private String status; - - public void cleanSelectParam() { - filters = new HashMap<>(); - name = null; - moduleIds = new ArrayList<>(); - protocol = null; - status = null; - } - } diff --git a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java index ad71231c14..79bb79e42d 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java @@ -324,7 +324,10 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl if (responseAssertionResult.isPass()) { requestResult.addPassAssertions(); } - responseResult.getAssertions().add(responseAssertionResult); + //xpath 提取错误会添加断言错误 + if (!responseAssertionResult.getMessage().contains("The required item type of the first operand of")) { + responseResult.getAssertions().add(responseAssertionResult); + } } responseResult.setConsole(getConsole()); diff --git a/backend/src/main/java/io/metersphere/api/jmeter/JMeterVars.java b/backend/src/main/java/io/metersphere/api/jmeter/JMeterVars.java index 84b1c089fd..5398e7e4cf 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/JMeterVars.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/JMeterVars.java @@ -1,5 +1,6 @@ package io.metersphere.api.jmeter; +import com.alibaba.fastjson.JSON; import io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample; import org.apache.jmeter.extractor.JSR223PostProcessor; import org.apache.jmeter.extractor.RegexExtractor; @@ -30,12 +31,29 @@ public class JMeterVars { * @param vars * @param extract */ - public static void addVars(Integer testId, JMeterVariables vars, String extract) { + public static void addVars(Integer testId, JMeterVariables vars, String extract) { JMeterVariables vs = new JMeterVariables(); - if (!StringUtils.isEmpty(extract) && vars != null) { List extracts = Arrays.asList(extract.split(";")); Optional.ofNullable(extracts).orElse(new ArrayList<>()).forEach(item -> { + + String nrKey = item + "_matchNr"; + Object nr = vars.get(nrKey); + if (nr != null) { + int nrv = 0; + try { + nrv = Integer.valueOf(String.valueOf(nr)); + } catch (Exception e) { + } + if (nrv > 0) { + List data = new ArrayList<>(); + for (int i = 1; i < nrv + 1; i++) { + data.add(vars.get(item + "_" + i)); + } + String array = JSON.toJSONString(data); + vars.put(item, array); + } + } vs.put(item, vars.get(item) == null ? "" : vars.get(item)); }); vs.remove("TESTSTART.MS"); // 标示变量移除 diff --git a/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java b/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java index 8d78614dad..d61d9af101 100644 --- a/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java +++ b/backend/src/main/java/io/metersphere/api/parse/Swagger2Parser.java @@ -97,8 +97,10 @@ public class Swagger2Parser extends ApiImportAbstractParser { String name = ""; if (StringUtils.isNotBlank(operation.getSummary())) { name = operation.getSummary(); - } else { + } else if (StringUtils.isNotBlank(operation.getOperationId())) { name = operation.getOperationId(); + } else { + name = path; } return buildApiDefinition(id, name, path, method); } diff --git a/backend/src/main/java/io/metersphere/api/parse/Swagger3Parser.java b/backend/src/main/java/io/metersphere/api/parse/Swagger3Parser.java index 3e8ab93dd9..92edcfddf1 100644 --- a/backend/src/main/java/io/metersphere/api/parse/Swagger3Parser.java +++ b/backend/src/main/java/io/metersphere/api/parse/Swagger3Parser.java @@ -129,8 +129,10 @@ public class Swagger3Parser extends ApiImportAbstractParser { String name = ""; if (StringUtils.isNotBlank(operation.getSummary())) { name = operation.getSummary(); - } else { + } else if (StringUtils.isNotBlank(operation.getOperationId())) { name = operation.getOperationId(); + } else { + name = path; } return buildApiDefinition(id, name, path, method); } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 9465a3caea..de677f4a50 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -24,6 +24,7 @@ import io.metersphere.base.mapper.ext.ExtTestPlanScenarioCaseMapper; import io.metersphere.commons.constants.*; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.DateUtils; +import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.ServiceUtils; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.i18n.Translator; @@ -316,8 +317,12 @@ public class ApiAutomationService { boolean isFirst = true; for (ApiScenarioWithBLOBs item : apiScenarios) { if (item.getStepTotal() == 0) { - MSException.throwException(item.getName() + "," + Translator.get("automation_exec_info")); - break; + // 只有一个场景且没有测试步骤,则提示 + if (apiScenarios.size() == 1) { + MSException.throwException((item.getName() + "," + Translator.get("automation_exec_info"))); + } + LogUtil.warn(item.getName() + "," + Translator.get("automation_exec_info")); + continue; } MsThreadGroup group = new MsThreadGroup(); group.setLabel(item.getName()); @@ -335,14 +340,12 @@ public class ApiAutomationService { // 多态JSON普通转换会丢失内容,需要通过 ObjectMapper 获取 if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) { LinkedList elements = mapper.readValue(element.getString("hashTree"), - new TypeReference>() { - }); + new TypeReference>() {}); scenario.setHashTree(elements); } if (StringUtils.isNotEmpty(element.getString("variables"))) { LinkedList variables = mapper.readValue(element.getString("variables"), - new TypeReference>() { - }); + new TypeReference>() {}); scenario.setVariables(variables); } group.setEnableCookieShare(scenario.isEnableCookieShare()); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java index 03f5b37b56..02b350949f 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -1,5 +1,6 @@ package io.metersphere.api.service; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -11,6 +12,8 @@ import io.metersphere.api.dto.definition.request.MsTestElement; import io.metersphere.api.dto.definition.request.MsTestPlan; import io.metersphere.api.dto.definition.request.MsThreadGroup; import io.metersphere.api.dto.definition.request.ParameterConfig; +import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; +import io.metersphere.api.dto.scenario.request.RequestType; import io.metersphere.api.jmeter.JMeterService; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.ApiDefinitionMapper; @@ -373,13 +376,33 @@ public class ApiTestCaseService { if (request.isSelectAllDate()) { ids = this.getAllApiCaseIdsByFontedSelect(request.getFilters(), request.getModuleIds(), request.getName(), request.getProjectId(), request.getProtocol(), request.getUnSelectIds(), request.getStatus()); } - request.cleanSelectParam(); ApiTestCaseExample apiDefinitionExample = new ApiTestCaseExample(); apiDefinitionExample.createCriteria().andIdIn(ids); - ApiTestCaseWithBLOBs apiDefinitionWithBLOBs = new ApiTestCaseWithBLOBs(); - BeanUtils.copyBean(apiDefinitionWithBLOBs, request); - apiDefinitionWithBLOBs.setUpdateTime(System.currentTimeMillis()); - apiTestCaseMapper.updateByExampleSelective(apiDefinitionWithBLOBs, apiDefinitionExample); + if (StringUtils.isNotEmpty(request.getPriority())) { + ApiTestCaseWithBLOBs apiDefinitionWithBLOBs = new ApiTestCaseWithBLOBs(); + apiDefinitionWithBLOBs.setPriority(request.getPriority()); + apiDefinitionWithBLOBs.setUpdateTime(System.currentTimeMillis()); + apiTestCaseMapper.updateByExampleSelective(apiDefinitionWithBLOBs, apiDefinitionExample); + } + if ((StringUtils.isNotEmpty(request.getMethod()) || StringUtils.isNotEmpty(request.getPath())) && request.getProtocol().equals(RequestType.HTTP)) { + List bloBs = apiTestCaseMapper.selectByExampleWithBLOBs(apiDefinitionExample); + SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); + ApiTestCaseMapper batchMapper = sqlSession.getMapper(ApiTestCaseMapper.class); + bloBs.forEach(apiTestCase -> { + MsHTTPSamplerProxy req = JSON.parseObject(apiTestCase.getRequest(), MsHTTPSamplerProxy.class); + if (StringUtils.isNotEmpty(request.getMethod())) { + req.setMethod(request.getMethod()); + } + if (StringUtils.isNotEmpty(request.getPath())) { + req.setPath(request.getPath()); + } + String requestStr = JSON.toJSONString(req); + apiTestCase.setRequest(requestStr); + batchMapper.updateByPrimaryKeySelective(apiTestCase); + }); + sqlSession.flushStatements(); + } + } private List getAllApiCaseIdsByFontedSelect(Map> filters, List moduleIds, String name, String projectId, String protocol, List unSelectIds, String status) { diff --git a/frontend/src/business/components/api/automation/scenario/Jsr233Processor.vue b/frontend/src/business/components/api/automation/scenario/Jsr233Processor.vue index 2bd2ca58a6..4f29002650 100644 --- a/frontend/src/business/components/api/automation/scenario/Jsr233Processor.vue +++ b/frontend/src/business/components/api/automation/scenario/Jsr233Processor.vue @@ -35,7 +35,7 @@ ref="codeEdit"/> - +
{{$t('api_test.request.processor.code_template')}}
{{template.title}} @@ -135,7 +135,7 @@ this.jsr223ProcessorData.script = ""; } this.jsr223ProcessorData.script += template.value; - if (this.jsr223ProcessorData.language === 'beanshell') { + if (this.jsr223ProcessorData.scriptLanguage === 'beanshell') { this.jsr223ProcessorData.script += ';'; } this.reload(); @@ -151,7 +151,7 @@ this.$nextTick(() => (this.isCodeEditAlive = true)); }, languageChange(language) { - this.jsr223ProcessorData.language = language; + this.jsr223ProcessorData.scriptLanguage = language; }, changeActive() { this.jsr223ProcessorData.active = !this.jsr223ProcessorData.active; diff --git a/frontend/src/business/components/api/automation/scenario/api/RelevanceApiList.vue b/frontend/src/business/components/api/automation/scenario/api/RelevanceApiList.vue index 70a5b457a4..43c32c3250 100644 --- a/frontend/src/business/components/api/automation/scenario/api/RelevanceApiList.vue +++ b/frontend/src/business/components/api/automation/scenario/api/RelevanceApiList.vue @@ -3,9 +3,10 @@ :is-api-list-enable="isApiListEnable" @isApiListEnableChange="isApiListEnableChange"> - + + + - - + + + +
diff --git a/frontend/src/business/components/api/definition/components/complete/EditCompleteHTTPApi.vue b/frontend/src/business/components/api/definition/components/complete/EditCompleteHTTPApi.vue index 1561e5484b..c2eb2dbeec 100644 --- a/frontend/src/business/components/api/definition/components/complete/EditCompleteHTTPApi.vue +++ b/frontend/src/business/components/api/definition/components/complete/EditCompleteHTTPApi.vue @@ -43,7 +43,8 @@
{{$t('api_test.definition.select_comp.no_data')}}, - {{$t('api_test.definition.select_comp.add_data')}} + + {{$t('api_test.definition.select_comp.add_data')}}
@@ -106,7 +107,6 @@ import {REQ_METHOD, API_STATUS} from "../../model/JsonData"; import MsJsr233Processor from "../processor/Jsr233Processor"; import {KeyValue} from "../../model/ApiTestModel"; - // import {append} from "./../../../../track/common/NodeTree"; export default { name: "MsAddCompleteHttpApi", @@ -172,7 +172,7 @@ } }) }, - createModules(){ + createModules() { this.$emit("createRootModelInTree"); }, getPath(id) { @@ -185,7 +185,7 @@ return path[0].path; }, urlChange() { - if (!this.httpForm.path) return; + if (!this.httpForm.path || this.httpForm.path.indexOf('?') === -1) return; let url = this.getURL(this.addProtocol(this.httpForm.path)); if (url) { this.httpForm.path = decodeURIComponent("/" + url.hostname + url.pathname); @@ -202,7 +202,6 @@ getURL(urlStr) { try { let url = new URL(urlStr); - console.log(urlStr) url.searchParams.forEach((value, key) => { if (key && value) { this.request.arguments.splice(0, 0, new KeyValue({name: key, required: false, value: value})); diff --git a/frontend/src/business/components/api/definition/components/jmeter/components/post-processors/jsr223-post-processor/index.js b/frontend/src/business/components/api/definition/components/jmeter/components/post-processors/jsr223-post-processor/index.js index 4513b66d0a..501c9e0592 100644 --- a/frontend/src/business/components/api/definition/components/jmeter/components/post-processors/jsr223-post-processor/index.js +++ b/frontend/src/business/components/api/definition/components/jmeter/components/post-processors/jsr223-post-processor/index.js @@ -15,7 +15,7 @@ export default class JSR223PostProcessor extends PostProcessor { constructor(options = DEFAULT_OPTIONS) { super(options); this.type = "JSR223PostProcessor"; - this.scriptLanguage = "java"; + this.scriptLanguage = "beanshell"; this.parameters = []; this.filename = undefined; this.cacheKey = true; diff --git a/frontend/src/business/components/api/definition/components/jmeter/components/pre-processors/jsr223-pre-processor/index.js b/frontend/src/business/components/api/definition/components/jmeter/components/pre-processors/jsr223-pre-processor/index.js index 7ea5082497..ef93344bb2 100644 --- a/frontend/src/business/components/api/definition/components/jmeter/components/pre-processors/jsr223-pre-processor/index.js +++ b/frontend/src/business/components/api/definition/components/jmeter/components/pre-processors/jsr223-pre-processor/index.js @@ -15,7 +15,7 @@ export default class JSR223PreProcessor extends PostProcessor { constructor(options = DEFAULT_OPTIONS) { super(options); this.type = "JSR223PreProcessor"; - this.scriptLanguage = "java"; + this.scriptLanguage = "beanshell"; this.parameters = []; this.filename = undefined; this.cacheKey = undefined; diff --git a/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue b/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue index dad5520ea2..125cce4b77 100644 --- a/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue +++ b/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue @@ -101,14 +101,12 @@ import MsBottomContainer from "../BottomContainer"; import ShowMoreBtn from "../../../../track/case/components/ShowMoreBtn"; import MsBatchEdit from "../basis/BatchEdit"; - import {API_METHOD_COLOUR, CASE_PRIORITY} from "../../model/JsonData"; + import {API_METHOD_COLOUR, CASE_PRIORITY, REQ_METHOD} from "../../model/JsonData"; import {getCurrentProjectID} from "@/common/js/utils"; import ApiListContainer from "./ApiListContainer"; import PriorityTableItem from "../../../../track/common/tableItems/planview/PriorityTableItem"; import ApiCaseList from "../case/ApiCaseList"; import {_filter, _sort} from "../../../../../../common/js/utils"; - import TestPlanCaseListHeader from "../../../../track/plan/view/comonents/api/TestPlanCaseListHeader"; - import MsEnvironmentSelect from "../case/MsEnvironmentSelect"; import {_handleSelect, _handleSelectAll} from "../../../../../../common/js/tableUtils"; export default { @@ -141,6 +139,8 @@ ], typeArr: [ {id: 'priority', name: this.$t('test_track.case.priority')}, + {id: 'method', name: this.$t('api_test.definition.api_type')}, + {id: 'path', name: this.$t('api_test.request.path')}, ], priorityFilters: [ {text: 'P0', value: 'P0'}, @@ -150,6 +150,7 @@ ], valueArr: { priority: CASE_PRIORITY, + method: REQ_METHOD, }, methodColorMap: new Map(API_METHOD_COLOUR), tableData: [], @@ -159,8 +160,8 @@ screenHeight: document.documentElement.clientHeight - 330,//屏幕高度 environmentId: undefined, selectAll: false, - unSelection:[], - selectDataCounts:0, + unSelection: [], + selectDataCounts: 0, } }, props: { @@ -233,7 +234,7 @@ this.condition.status = "Trash"; this.condition.moduleIds = []; } - this.selectAll = false; + this.selectAll = false; this.unSelection = []; this.selectDataCounts = 0; this.condition.projectId = getCurrentProjectID(); @@ -245,7 +246,7 @@ this.result = this.$post('/api/testcase/list/' + this.currentPage + "/" + this.pageSize, this.condition, response => { this.total = response.data.itemCount; this.tableData = response.data.listObject; - this.unSelection = response.data.listObject.map(s=>s.id); + this.unSelection = response.data.listObject.map(s => s.id); }); } }, @@ -312,24 +313,24 @@ }, handleDeleteBatch() { // if (this.trashEnable) { - this.$alert(this.$t('api_test.definition.request.delete_confirm') + "?", '', { - confirmButtonText: this.$t('commons.confirm'), - callback: (action) => { - if (action === 'confirm') { - let obj = {}; - obj.projectId = getCurrentProjectID(); - obj.selectAllDate = this.isSelectAllDate; - obj.unSelectIds = this.unSelection; - obj.ids = Array.from(this.selectRows).map(row => row.id); - obj = Object.assign(obj, this.condition); - this.$post('/api/testcase/deleteBatchByParam/', obj , () => { - this.selectRows.clear(); - this.initTable(); - this.$success(this.$t('commons.delete_success')); - }); - } + this.$alert(this.$t('api_test.definition.request.delete_confirm') + "?", '', { + confirmButtonText: this.$t('commons.confirm'), + callback: (action) => { + if (action === 'confirm') { + let obj = {}; + obj.projectId = getCurrentProjectID(); + obj.selectAllDate = this.isSelectAllDate; + obj.unSelectIds = this.unSelection; + obj.ids = Array.from(this.selectRows).map(row => row.id); + obj = Object.assign(obj, this.condition); + this.$post('/api/testcase/deleteBatchByParam/', obj, () => { + this.selectRows.clear(); + this.initTable(); + this.$success(this.$t('commons.delete_success')); + }); } - }); + } + }); // } else { // this.$alert(this.$t('api_test.definition.request.delete_confirm') + "?", '', { // confirmButtonText: this.$t('commons.confirm'), @@ -355,7 +356,6 @@ let param = {}; param[form.type] = form.value; param.ids = ids; - param.projectId = getCurrentProjectID(); param.selectAllDate = this.isSelectAllDate; param.unSelectIds = this.unSelection; @@ -367,11 +367,11 @@ }, handleDelete(apiCase) { // if (this.trashEnable) { - this.$get('/api/testcase/delete/' + apiCase.id, () => { - this.$success(this.$t('commons.delete_success')); - this.initTable(); - }); - return; + this.$get('/api/testcase/delete/' + apiCase.id, () => { + this.$success(this.$t('commons.delete_success')); + this.initTable(); + }); + return; // } // this.$alert(this.$t('api_test.definition.request.delete_confirm') + ' ' + apiCase.name + " ?", '', { // confirmButtonText: this.$t('commons.confirm'), @@ -389,16 +389,16 @@ setEnvironment(data) { this.environmentId = data.id; }, - selectRowsCount(selection){ + selectRowsCount(selection) { let selectedIDs = this.getIds(selection); - let allIDs = this.tableData.map(s=>s.id); + let allIDs = this.tableData.map(s => s.id); this.unSelection = allIDs.filter(function (val) { return selectedIDs.indexOf(val) === -1 }); - if(this.isSelectAllDate){ - this.selectDataCounts =this.total - this.unSelection.length; - }else { - this.selectDataCounts =selection.size; + if (this.isSelectAllDate) { + this.selectDataCounts = this.total - this.unSelection.length; + } else { + this.selectDataCounts = selection.size; } }, isSelectDataAll(dataType) { @@ -409,9 +409,9 @@ this.$refs.caseTable.toggleAllSelection(true); } }, - getIds(rowSets){ + getIds(rowSets) { let rowArray = Array.from(rowSets) - let ids = rowArray.map(s=>s.id); + let ids = rowArray.map(s => s.id); return ids; } }, diff --git a/frontend/src/business/components/api/definition/components/list/ApiList.vue b/frontend/src/business/components/api/definition/components/list/ApiList.vue index a4fe6c3e9a..d7afbd7483 100644 --- a/frontend/src/business/components/api/definition/components/list/ApiList.vue +++ b/frontend/src/business/components/api/definition/components/list/ApiList.vue @@ -80,6 +80,7 @@ diff --git a/frontend/src/business/components/api/definition/components/module/ApiModuleHeader.vue b/frontend/src/business/components/api/definition/components/module/ApiModuleHeader.vue index 510f7cad75..b6c49762be 100644 --- a/frontend/src/business/components/api/definition/components/module/ApiModuleHeader.vue +++ b/frontend/src/business/components/api/definition/components/module/ApiModuleHeader.vue @@ -122,7 +122,7 @@ export default { diff --git a/frontend/src/common/css/main.css b/frontend/src/common/css/main.css index f80a1b9976..c14a241985 100644 --- a/frontend/src/common/css/main.css +++ b/frontend/src/common/css/main.css @@ -142,9 +142,9 @@ html,body { border: 1px solid #DCDFE6; border-radius:5px; padding: 0px; - margin-top: 5px; + margin-top: 10px; display: inline-block; - margin-top: 25px; + /*margin-top: 25px;*/ width: 50px; } @@ -164,8 +164,8 @@ html,body { .ms-select-all .el-icon-arrow-down { position: absolute; display: inline-block; - top: -3px; - left: -40px; + top: -7px; + left: -38px; width: 30px; } /* 表格全选样式 --> */