diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java index 8d4b315e3e..9ed70f74d7 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java @@ -413,6 +413,31 @@ public class ElementUtil { } } + + public static LinkedList mergeOrgAssertion(LinkedList orgAssertions) { + if (CollectionUtils.isNotEmpty(orgAssertions) && orgAssertions.size() > 1) { + //根据不同的类型,把所有的数据都合并到第一个上 + MsAssertions target = (MsAssertions) orgAssertions.get(0); + for (int i = 1; i < orgAssertions.size(); i++) { + MsAssertions target1 = (MsAssertions) orgAssertions.get(i); + mergeArrayAssertions(target.getJsonPath(), target1.getJsonPath()); + mergeArrayAssertions(target.getXpath2(), target1.getXpath2()); + mergeArrayAssertions(target.getJsr223(), target1.getJsr223()); + mergeArrayAssertions(target.getRegex(), target1.getRegex()); + } + LinkedList msTestElements = new LinkedList<>(); + msTestElements.add(target); + return msTestElements; + } + return orgAssertions; + } + + public static void mergeArrayAssertions(List org, List org1) { + if (CollectionUtils.isNotEmpty(org1)) { + org.addAll(org1); + } + } + public static void mergeHashTree(MsTestElement element, LinkedList targetHashTree) { try { Map> source = groupCase(element.getHashTree()); @@ -420,6 +445,8 @@ public class ElementUtil { List step = new LinkedList<>(); List pre = ElementUtil.mergeCaseHashTree(source.get(PRE), target.get(PRE)); List post = ElementUtil.mergeCaseHashTree(source.get(POST), target.get(POST)); + source.put(ASSERTIONS, mergeOrgAssertion(source.get(ASSERTIONS))); + target.put(ASSERTIONS, mergeOrgAssertion(target.get(ASSERTIONS))); List rules = MsHashTreeService.mergeCaseAssertions(source.get(ASSERTIONS), target.get(ASSERTIONS)); if (CollectionUtils.isNotEmpty(pre)) { step.addAll(pre);