fix(接口自动化): 修复同名多个csv 执行问题
This commit is contained in:
parent
77879cd176
commit
a124268cb1
|
@ -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;
|
||||
|
|
|
@ -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,22 @@ 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 +89,7 @@ public class MsJmeterElement extends MsTestElement {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
|
|
@ -1173,6 +1173,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());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue