fix(接口自动化): 1.8版本部分缺陷修复

This commit is contained in:
fit2-zhao 2021-04-12 17:48:13 +08:00
parent 2aca963926
commit 8423f59b9e
7 changed files with 80 additions and 50 deletions

View File

@ -76,8 +76,12 @@ public class MsIfController extends MsTestElement {
public String getCondition() {
String variable = "\"" + this.variable + "\"";
String operator = this.operator;
String value = "\"" + this.value + "\"";
String value;
if (StringUtils.equals(operator, "<") || StringUtils.equals(operator, ">")) {
value = this.value;
} else {
value = "\"" + this.value + "\"";
}
if (StringUtils.contains(operator, "~")) {
value = "\".*" + this.value + ".*\"";
}

View File

@ -56,7 +56,7 @@ public class MsLoopController extends MsTestElement {
}
final HashTree groupTree = controller(tree);
if (CollectionUtils.isNotEmpty(config.getVariables())) {
this.addCsvDataSet(groupTree, config.getVariables(),config);
this.addCsvDataSet(groupTree, config.getVariables(), config);
this.addCounter(groupTree, config.getVariables());
this.addRandom(groupTree, config.getVariables());
}
@ -111,7 +111,12 @@ public class MsLoopController extends MsTestElement {
private String getCondition() {
String variable = "\"" + this.whileController.getVariable() + "\"";
String operator = this.whileController.getOperator();
String value = "\"" + this.whileController.getValue() + "\"";
String value;
if (StringUtils.equals(operator, "<") || StringUtils.equals(operator, ">")) {
value = this.whileController.getValue();
} else {
value = "\"" + this.whileController.getValue() + "\"";
}
if (StringUtils.contains(operator, "~")) {
value = "\".*" + this.whileController.getValue() + ".*\"";

View File

@ -248,14 +248,6 @@ public class MsHTTPSamplerProxy extends MsTestElement {
LogUtil.error(e);
MSException.throwException(e.getMessage());
}
// REST参数
if (CollectionUtils.isNotEmpty(this.getRest())) {
sampler.setArguments(httpArguments(this.getRest()));
}
// 请求参数
if (CollectionUtils.isNotEmpty(this.getArguments())) {
sampler.setArguments(httpArguments(this.getArguments()));
}
// 请求体
if (!StringUtils.equals(this.getMethod(), "GET")) {
if (this.body != null) {

View File

@ -2,6 +2,7 @@ package io.metersphere.api.jmeter;
import com.alibaba.fastjson.JSON;
import io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample;
import org.apache.commons.collections.CollectionUtils;
import org.apache.jmeter.extractor.JSR223PostProcessor;
import org.apache.jmeter.extractor.RegexExtractor;
import org.apache.jmeter.extractor.XPath2Extractor;
@ -31,32 +32,36 @@ public class JMeterVars {
* @param vars
* @param extract
*/
public static void addVars(Integer testId, JMeterVariables vars, String extract) {
JMeterVariables vs = new JMeterVariables();
public static void addVars(Integer testId, JMeterVariables vars, String extract) {
JMeterVariables vs = variables.get(testId);
if (vs == null) {
vs = new JMeterVariables();
}
if (!StringUtils.isEmpty(extract) && vars != null) {
List<String> 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<Object> data = new ArrayList<>();
for (int i = 1; i < nrv + 1; i++) {
data.add(vars.get(item + "_" + i));
if (CollectionUtils.isNotEmpty(extracts)) {
for (String item : extracts) {
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<Object> 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);
}
String array = JSON.toJSONString(data);
vars.put(item, array);
}
vs.put(item, vars.get(item) == null ? "" : vars.get(item));
}
vs.put(item, vars.get(item) == null ? "" : vars.get(item));
});
vs.remove("TESTSTART.MS"); // 标示变量移除
vs.remove("TESTSTART.MS"); // 标示变量移除
}
}
variables.put(testId, vs);

View File

@ -533,7 +533,7 @@ public class ApiAutomationService {
}
public byte[] loadFileAsBytes(FileOperationRequest fileOperationRequest) {
File file = new File(FileUtils.BODY_FILE_DIR + fileOperationRequest.getId() + "_" + fileOperationRequest.getName());
File file = new File(FileUtils.BODY_FILE_DIR +"/"+ fileOperationRequest.getId() + "_" + fileOperationRequest.getName());
try (FileInputStream fis = new FileInputStream(file);
ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);) {
byte[] b = new byte[1000];

View File

@ -29,6 +29,7 @@
</template>
<script>
import MsRequestResult from "./components/RequestResult";
import MsRequestResultTail from "./components/RequestResultTail";
import MsScenarioResult from "./components/ScenarioResult";
@ -39,7 +40,8 @@
import MsApiReportExport from "./ApiReportExport";
import MsApiReportViewHeader from "./ApiReportViewHeader";
import {RequestFactory} from "../../definition/model/ApiTestModel";
import {windowPrint} from "@/common/js/utils";
import {windowPrint,getUUID} from "@/common/js/utils";
export default {
name: "MsApiReport",
components: {
@ -105,7 +107,7 @@
if (item && item.requestResults) {
item.requestResults.forEach(req => {
resMap.set(req.id, req);
req.name = item.name + "^@~@^" + req.name;
req.name = item.name + "^@~@^" + req.name+ "UUID="+getUUID();
array.push(req);
})
}
@ -122,51 +124,60 @@
let children = tree;
//
for (let i in nodeArray) {
if (!nodeArray[i]) {
continue;
}
let node = {
label: nodeArray[i],
value: item,
};
if (i != nodeArray.length) {
if (i !== nodeArray.length) {
node.children = [];
}
if (children.length == 0) {
if (children.length === 0) {
children.push(node);
}
let isExist = false;
for (let j in children) {
if (children[j].label == node.label) {
if (i != nodeArray.length - 1 && !children[j].children) {
if (children[j].label === node.label) {
if (i !== nodeArray.length - 1 && !children[j].children) {
children[j].children = [];
}
children = (i == nodeArray.length - 1 ? children : children[j].children);
children = (i === nodeArray.length - 1 ? children : children[j].children);
isExist = true;
break;
}
}
if (!isExist) {
children.push(node);
if (i != nodeArray.length - 1 && !children[children.length - 1].children) {
if (i !== nodeArray.length - 1 && !children[children.length - 1].children) {
children[children.length - 1].children = [];
}
children = (i == nodeArray.length - 1 ? children : children[children.length - 1].children);
children = (i === nodeArray.length - 1 ? children : children[children.length - 1].children);
}
}
})
},
recursiveSorting(arr) {
for (let i in arr) {
arr[i].index = Number(i) + 1;
if (arr[i].children != undefined && arr[i].children.length > 0) {
this.recursiveSorting(arr[i].children);
if (arr[i]) {
arr[i].index = Number(i) + 1;
if (arr[i].children && arr[i].children.length > 0) {
this.recursiveSorting(arr[i].children);
}
}
}
},
sort(scenarioDefinition) {
for (let i in scenarioDefinition) {
//
scenarioDefinition[i].index = Number(i) + 1;
if (scenarioDefinition[i].children != undefined && scenarioDefinition[i].children.length > 0) {
this.recursiveSorting(scenarioDefinition[i].children);
if (scenarioDefinition[i]) {
scenarioDefinition[i].index = Number(i) + 1;
if (scenarioDefinition[i].children && scenarioDefinition[i].children.length > 0) {
this.recursiveSorting(scenarioDefinition[i].children);
}
}
}
},
@ -216,7 +227,7 @@
if (!request.success) {
let failRequest = Object.assign({}, request);
failScenario.requestResults.push(failRequest);
array.push(request)
array.push(request);
}
})
}
@ -286,9 +297,11 @@
this.$router.go(0);
}
},
created() {
this.getReport();
},
computed: {
path() {
return "/api/test/edit?id=" + this.report.testId;
@ -309,30 +322,38 @@
</style>
<style scoped>
.report-container {
height: calc(100vh - 155px);
min-height: 600px;
overflow-y: auto;
}
.report-header {
font-size: 15px;
}
.report-header a {
text-decoration: none;
}
.report-header .time {
color: #909399;
margin-left: 10px;
}
.report-container .fail {
color: #F56C6C;
}
.report-container .is-active .fail {
color: inherit;
}
.export-button {
float: right;
}
.scenario-result .icon.is-active {
transform: rotate(90deg);
}

View File

@ -101,6 +101,9 @@
getName(name) {
if (name && name.indexOf("^@~@^") != -1) {
let arr = name.split("^@~@^");
if (arr[arr.length - 1].indexOf("UUID=")) {
return arr[arr.length - 1].split("UUID=")[0];
}
return arr[arr.length - 1];
}
return name;