fix(接口自动化): 修复同名多个csv 执行问题

This commit is contained in:
fit2-zhao 2021-05-19 16:56:56 +08:00 committed by fit2-zhao
parent 961f764874
commit 4aa5185997
3 changed files with 28 additions and 14 deletions

View File

@ -7,6 +7,7 @@ import io.metersphere.commons.utils.ScriptEngineUtils;
import lombok.Data;
import org.apache.jmeter.config.Arguments;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -39,6 +40,9 @@ public class ParameterConfig {
*/
private String projectId;
private List<String> csvFilePaths = new ArrayList<>();
public boolean isEffective(String projectId) {
if (this.config != null && this.config.get(projectId) != null) {
return true;

View File

@ -52,16 +52,8 @@ public class MsJmeterElement extends MsTestElement {
((TestElement) scriptWrapper).setName(this.getName());
((TestElement) scriptWrapper).setEnabled(this.isEnable());
}
if (config.isOperating()) {
elementTree = tree.add(scriptWrapper);
} else if (!(scriptWrapper instanceof TestPlan) && !(scriptWrapper instanceof ThreadGroup)) {
elementTree = tree.add(scriptWrapper);
}
if (!config.isOperating() && scriptWrapper instanceof ThreadGroup && !((ThreadGroup) scriptWrapper).isEnabled()) {
LogUtil.info(((ThreadGroup) scriptWrapper).getName() + "是被禁用线程组不加入执行");
} else {
// CSV数据检查文件路径是否还存在
if (!config.isOperating() && scriptWrapper instanceof CSVDataSet) {
// csv 检查处理
if (!config.isOperating() && scriptWrapper instanceof CSVDataSet && ((CSVDataSet) scriptWrapper).isEnabled()) {
String path = ((CSVDataSet) scriptWrapper).getPropertyAsString("filename");
if (!new File(path).exists()) {
// 检查场景变量中的csv文件是否存在
@ -73,7 +65,23 @@ public class MsJmeterElement extends MsTestElement {
MSException.throwException(StringUtils.isEmpty(((CSVDataSet) scriptWrapper).getName()) ? "CSVDataSet" : ((CSVDataSet) scriptWrapper).getName() + "[ CSV文件不存在 ]");
}
}
String csvPath = ((CSVDataSet) scriptWrapper).getPropertyAsString("filename");
if (config.getCsvFilePaths().contains(csvPath)) {
return;
} else {
config.getCsvFilePaths().add(csvPath);
}
}
if (config.isOperating()) {
elementTree = tree.add(scriptWrapper);
} else if (!(scriptWrapper instanceof TestPlan) && !(scriptWrapper instanceof ThreadGroup)) {
elementTree = tree.add(scriptWrapper);
}
if (!config.isOperating() && scriptWrapper instanceof ThreadGroup && !((ThreadGroup) scriptWrapper).isEnabled()) {
LogUtil.info(((ThreadGroup) scriptWrapper).getName() + "是被禁用线程组不加入执行");
} else {
if (CollectionUtils.isNotEmpty(hashTree)) {
for (MsTestElement el : hashTree) {
// 给所有孩子加一个父亲标志
@ -82,6 +90,7 @@ public class MsJmeterElement extends MsTestElement {
}
}
}
}
} catch (Exception ex) {
ex.printStackTrace();

View File

@ -1261,6 +1261,7 @@ public class ApiAutomationService {
HashTree hashTree = null;
try {
hashTree = request.getTestElement().generateHashTree(config);
LogUtil.info(request.getTestElement().getJmx(hashTree));
} catch (Exception e) {
MSException.throwException(e.getMessage());
}