diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/MsAssertions.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/MsAssertions.java index 54f43eb9b6..fd6232ab54 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/MsAssertions.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/MsAssertions.java @@ -24,6 +24,7 @@ import java.util.List; @EqualsAndHashCode(callSuper = true) public class MsAssertions extends MsTestElement { private String clazzName = MsAssertions.class.getCanonicalName(); + private String xpathType; private boolean scenarioAss; private List regex; @@ -87,9 +88,15 @@ public class MsAssertions extends MsTestElement { } if (CollectionUtils.isNotEmpty(this.getXpath2())) { - this.getXpath2().stream().filter(MsAssertionXPath2::isValid).forEach(assertion -> - hashTree.add(xPath2Assertion(assertion)) - ); + if (StringUtils.equals("html", this.getXpathType())) { + this.getXpath2().stream().filter(MsAssertionXPath2::isValid).forEach(assertion -> + hashTree.add(xPathAssertion(assertion)) + ); + } else { + this.getXpath2().stream().filter(MsAssertionXPath2::isValid).forEach(assertion -> + hashTree.add(xPath2Assertion(assertion)) + ); + } } if (CollectionUtils.isNotEmpty(this.getJsr223())) { @@ -178,6 +185,23 @@ public class MsAssertions extends MsTestElement { return assertion; } + private XPathAssertion xPathAssertion(MsAssertionXPath2 assertionXPath) { + XPathAssertion assertion = new XPathAssertion(); + assertion.setEnabled(this.isEnable()); + assertion.setTolerant(true); + assertion.setValidating(false); + if (StringUtils.isNotEmpty(assertionXPath.getExpression())) { + assertion.setName(this.getName() + delimiter + assertionXPath.getExpression()); + } else { + assertion.setName(this.getName() + delimiter + "XPath2Assertion"); + } + assertion.setProperty(TestElement.TEST_CLASS, XPathAssertion.class.getName()); + assertion.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("XPathAssertionGui")); + assertion.setXPathString(assertionXPath.getExpression()); + assertion.setNegated(false); + return assertion; + } + private DurationAssertion durationAssertion(MsAssertionDuration assertionDuration) { DurationAssertion assertion = new DurationAssertion(); assertion.setEnabled(this.isEnable()); diff --git a/api-test/frontend/src/business/definition/components/assertion/ApiAssertions.vue b/api-test/frontend/src/business/definition/components/assertion/ApiAssertions.vue index 7cb7b85ccc..d887f87e72 100644 --- a/api-test/frontend/src/business/definition/components/assertion/ApiAssertions.vue +++ b/api-test/frontend/src/business/definition/components/assertion/ApiAssertions.vue @@ -68,11 +68,7 @@ :document="assertions.document" :callback="after" v-if="type === options.DOCUMENT" /> - + {{ $t('api_test.request.assertions.add') }} @@ -171,6 +167,11 @@ export default { deep: true, }, }, + created() { + if (!this.assertions.xpathType) { + this.assertions.xpathType = 'xml'; + } + }, methods: { computeStep() { let ruleSize = 0; diff --git a/api-test/frontend/src/business/definition/components/assertion/ApiAssertionsEdit.vue b/api-test/frontend/src/business/definition/components/assertion/ApiAssertionsEdit.vue index 6f7885ce3a..bfc27c236b 100644 --- a/api-test/frontend/src/business/definition/components/assertion/ApiAssertionsEdit.vue +++ b/api-test/frontend/src/business/definition/components/assertion/ApiAssertionsEdit.vue @@ -25,7 +25,18 @@
-
{{ 'XPath' }}
+
+ XPath + + + + +
+ {{ $t('api_test.request.assertions.assert_info') }} +
+ +
+