fix(接口自动化): 1.8版本部分缺陷修复
This commit is contained in:
parent
2aca963926
commit
8423f59b9e
|
@ -76,8 +76,12 @@ public class MsIfController extends MsTestElement {
|
||||||
public String getCondition() {
|
public String getCondition() {
|
||||||
String variable = "\"" + this.variable + "\"";
|
String variable = "\"" + this.variable + "\"";
|
||||||
String operator = this.operator;
|
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, "~")) {
|
if (StringUtils.contains(operator, "~")) {
|
||||||
value = "\".*" + this.value + ".*\"";
|
value = "\".*" + this.value + ".*\"";
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class MsLoopController extends MsTestElement {
|
||||||
}
|
}
|
||||||
final HashTree groupTree = controller(tree);
|
final HashTree groupTree = controller(tree);
|
||||||
if (CollectionUtils.isNotEmpty(config.getVariables())) {
|
if (CollectionUtils.isNotEmpty(config.getVariables())) {
|
||||||
this.addCsvDataSet(groupTree, config.getVariables(),config);
|
this.addCsvDataSet(groupTree, config.getVariables(), config);
|
||||||
this.addCounter(groupTree, config.getVariables());
|
this.addCounter(groupTree, config.getVariables());
|
||||||
this.addRandom(groupTree, config.getVariables());
|
this.addRandom(groupTree, config.getVariables());
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,12 @@ public class MsLoopController extends MsTestElement {
|
||||||
private String getCondition() {
|
private String getCondition() {
|
||||||
String variable = "\"" + this.whileController.getVariable() + "\"";
|
String variable = "\"" + this.whileController.getVariable() + "\"";
|
||||||
String operator = this.whileController.getOperator();
|
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, "~")) {
|
if (StringUtils.contains(operator, "~")) {
|
||||||
value = "\".*" + this.whileController.getValue() + ".*\"";
|
value = "\".*" + this.whileController.getValue() + ".*\"";
|
||||||
|
|
|
@ -248,14 +248,6 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
LogUtil.error(e);
|
LogUtil.error(e);
|
||||||
MSException.throwException(e.getMessage());
|
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 (!StringUtils.equals(this.getMethod(), "GET")) {
|
||||||
if (this.body != null) {
|
if (this.body != null) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.api.jmeter;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample;
|
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.JSR223PostProcessor;
|
||||||
import org.apache.jmeter.extractor.RegexExtractor;
|
import org.apache.jmeter.extractor.RegexExtractor;
|
||||||
import org.apache.jmeter.extractor.XPath2Extractor;
|
import org.apache.jmeter.extractor.XPath2Extractor;
|
||||||
|
@ -31,32 +32,36 @@ public class JMeterVars {
|
||||||
* @param vars
|
* @param vars
|
||||||
* @param extract
|
* @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();
|
JMeterVariables vs = variables.get(testId);
|
||||||
|
if (vs == null) {
|
||||||
|
vs = new JMeterVariables();
|
||||||
|
}
|
||||||
if (!StringUtils.isEmpty(extract) && vars != null) {
|
if (!StringUtils.isEmpty(extract) && vars != null) {
|
||||||
List<String> extracts = Arrays.asList(extract.split(";"));
|
List<String> extracts = Arrays.asList(extract.split(";"));
|
||||||
Optional.ofNullable(extracts).orElse(new ArrayList<>()).forEach(item -> {
|
if (CollectionUtils.isNotEmpty(extracts)) {
|
||||||
|
for (String item : extracts) {
|
||||||
String nrKey = item + "_matchNr";
|
String nrKey = item + "_matchNr";
|
||||||
Object nr = vars.get(nrKey);
|
Object nr = vars.get(nrKey);
|
||||||
if (nr != null) {
|
if (nr != null) {
|
||||||
int nrv = 0;
|
int nrv = 0;
|
||||||
try {
|
try {
|
||||||
nrv = Integer.valueOf(String.valueOf(nr));
|
nrv = Integer.valueOf(String.valueOf(nr));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
if (nrv > 0) {
|
if (nrv > 0) {
|
||||||
List<Object> data = new ArrayList<>();
|
List<Object> data = new ArrayList<>();
|
||||||
for (int i = 1; i < nrv + 1; i++) {
|
for (int i = 1; i < nrv + 1; i++) {
|
||||||
data.add(vars.get(item + "_" + 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);
|
variables.put(testId, vs);
|
||||||
|
|
|
@ -533,7 +533,7 @@ public class ApiAutomationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] loadFileAsBytes(FileOperationRequest fileOperationRequest) {
|
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);
|
try (FileInputStream fis = new FileInputStream(file);
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);) {
|
ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);) {
|
||||||
byte[] b = new byte[1000];
|
byte[] b = new byte[1000];
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
import MsRequestResult from "./components/RequestResult";
|
import MsRequestResult from "./components/RequestResult";
|
||||||
import MsRequestResultTail from "./components/RequestResultTail";
|
import MsRequestResultTail from "./components/RequestResultTail";
|
||||||
import MsScenarioResult from "./components/ScenarioResult";
|
import MsScenarioResult from "./components/ScenarioResult";
|
||||||
|
@ -39,7 +40,8 @@
|
||||||
import MsApiReportExport from "./ApiReportExport";
|
import MsApiReportExport from "./ApiReportExport";
|
||||||
import MsApiReportViewHeader from "./ApiReportViewHeader";
|
import MsApiReportViewHeader from "./ApiReportViewHeader";
|
||||||
import {RequestFactory} from "../../definition/model/ApiTestModel";
|
import {RequestFactory} from "../../definition/model/ApiTestModel";
|
||||||
import {windowPrint} from "@/common/js/utils";
|
import {windowPrint,getUUID} from "@/common/js/utils";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "MsApiReport",
|
name: "MsApiReport",
|
||||||
components: {
|
components: {
|
||||||
|
@ -105,7 +107,7 @@
|
||||||
if (item && item.requestResults) {
|
if (item && item.requestResults) {
|
||||||
item.requestResults.forEach(req => {
|
item.requestResults.forEach(req => {
|
||||||
resMap.set(req.id, req);
|
resMap.set(req.id, req);
|
||||||
req.name = item.name + "^@~@^" + req.name;
|
req.name = item.name + "^@~@^" + req.name+ "UUID="+getUUID();
|
||||||
array.push(req);
|
array.push(req);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -122,51 +124,60 @@
|
||||||
let children = tree;
|
let children = tree;
|
||||||
// 循环构建子节点
|
// 循环构建子节点
|
||||||
for (let i in nodeArray) {
|
for (let i in nodeArray) {
|
||||||
|
if (!nodeArray[i]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let node = {
|
let node = {
|
||||||
label: nodeArray[i],
|
label: nodeArray[i],
|
||||||
value: item,
|
value: item,
|
||||||
};
|
};
|
||||||
if (i != nodeArray.length) {
|
if (i !== nodeArray.length) {
|
||||||
node.children = [];
|
node.children = [];
|
||||||
}
|
}
|
||||||
if (children.length == 0) {
|
|
||||||
|
if (children.length === 0) {
|
||||||
children.push(node);
|
children.push(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
let isExist = false;
|
let isExist = false;
|
||||||
for (let j in children) {
|
for (let j in children) {
|
||||||
if (children[j].label == node.label) {
|
if (children[j].label === node.label) {
|
||||||
if (i != nodeArray.length - 1 && !children[j].children) {
|
if (i !== nodeArray.length - 1 && !children[j].children) {
|
||||||
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;
|
isExist = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isExist) {
|
if (!isExist) {
|
||||||
children.push(node);
|
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[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) {
|
recursiveSorting(arr) {
|
||||||
for (let i in arr) {
|
for (let i in arr) {
|
||||||
arr[i].index = Number(i) + 1;
|
if (arr[i]) {
|
||||||
if (arr[i].children != undefined && arr[i].children.length > 0) {
|
arr[i].index = Number(i) + 1;
|
||||||
this.recursiveSorting(arr[i].children);
|
if (arr[i].children && arr[i].children.length > 0) {
|
||||||
|
this.recursiveSorting(arr[i].children);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
sort(scenarioDefinition) {
|
sort(scenarioDefinition) {
|
||||||
for (let i in scenarioDefinition) {
|
for (let i in scenarioDefinition) {
|
||||||
// 排序
|
// 排序
|
||||||
scenarioDefinition[i].index = Number(i) + 1;
|
if (scenarioDefinition[i]) {
|
||||||
if (scenarioDefinition[i].children != undefined && scenarioDefinition[i].children.length > 0) {
|
scenarioDefinition[i].index = Number(i) + 1;
|
||||||
this.recursiveSorting(scenarioDefinition[i].children);
|
if (scenarioDefinition[i].children && scenarioDefinition[i].children.length > 0) {
|
||||||
|
this.recursiveSorting(scenarioDefinition[i].children);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -216,7 +227,7 @@
|
||||||
if (!request.success) {
|
if (!request.success) {
|
||||||
let failRequest = Object.assign({}, request);
|
let failRequest = Object.assign({}, request);
|
||||||
failScenario.requestResults.push(failRequest);
|
failScenario.requestResults.push(failRequest);
|
||||||
array.push(request)
|
array.push(request);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -286,9 +297,11 @@
|
||||||
this.$router.go(0);
|
this.$router.go(0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.getReport();
|
this.getReport();
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
path() {
|
path() {
|
||||||
return "/api/test/edit?id=" + this.report.testId;
|
return "/api/test/edit?id=" + this.report.testId;
|
||||||
|
@ -309,30 +322,38 @@
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
||||||
.report-container {
|
.report-container {
|
||||||
height: calc(100vh - 155px);
|
height: calc(100vh - 155px);
|
||||||
min-height: 600px;
|
min-height: 600px;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.report-header {
|
.report-header {
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.report-header a {
|
.report-header a {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.report-header .time {
|
.report-header .time {
|
||||||
color: #909399;
|
color: #909399;
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.report-container .fail {
|
.report-container .fail {
|
||||||
color: #F56C6C;
|
color: #F56C6C;
|
||||||
}
|
}
|
||||||
|
|
||||||
.report-container .is-active .fail {
|
.report-container .is-active .fail {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
.export-button {
|
.export-button {
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
.scenario-result .icon.is-active {
|
.scenario-result .icon.is-active {
|
||||||
transform: rotate(90deg);
|
transform: rotate(90deg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,9 @@
|
||||||
getName(name) {
|
getName(name) {
|
||||||
if (name && name.indexOf("^@~@^") != -1) {
|
if (name && name.indexOf("^@~@^") != -1) {
|
||||||
let arr = name.split("^@~@^");
|
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 arr[arr.length - 1];
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
|
|
Loading…
Reference in New Issue