admin管理员组文章数量:1415491
i use this script groovy in my soap test , i want to ignore the result of this attribut in my reponse
ns4:Period ns4:firstDate2020-09-22T13:12:23</ns4:firstDate> </ns4:Period>``
**Script Assertion : **
import groovy.xml.XmlUtil
import groovy.xml.XmlParser
import .xmlunit.builder.DiffBuilder
import .xmlunit.builder.Input
import .xmlunit.diff.DefaultNodeMatcher
import .xmlunit.diff.Diff
import .xmlunit.diff.ElementSelectors
import .xmlunit.diff.MultiLevelByNameAndTextSelector
def anonymize(String current, List<String> fieldsToAnonymize) {
Node node = new XmlParser().parseText(current)
anonymizeField(node, fieldsToAnonymize, null)
return XmlUtil.serialize(node)
}
def anonymizeField(Node node, List<String> fieldsToAnonymize, String previousLevel) {
String currentLevel = previousLevel == null ? node.name() : previousLevel + "/" + node.name()
NodeList children = (NodeList) node.value()
for (def child : children) {
if (child instanceof Node) {
anonymizeField((Node) child, fieldsToAnonymize, currentLevel)
} else if (fieldsToAnonymize.contains(currentLevel)) {
log.info("contentAnonymize for: " + currentLevel)
node.setValue("")
}
}
}
def compare(String current, String expected) {
Diff myDiff = DiffBuilderpare(Input.fromString(current))
.withTest(Input.fromString(expected))
.checkForSimilar()
.normalizeWhitespace()
.withNodeMatcher(new DefaultNodeMatcher(new MultiLevelByNameAndTextSelector(2), ElementSelectors.byNameAndAllAttributes))
.build()
if (myDiff.hasDifferences()) {
log.info(myDiff.toString())
}
assert !myDiff.hasDifferences()
}
String expected = context.expand('${#TestCase#Request-2')
String fieldsToAnonymize = context.expand('${#TestCase#Request-2_fieldsToAnonymize}')
String current = messageExchange.getResponseContentAsXml()
String currentAnonymize = anonymize(current, Arrays.asList(fieldsToAnonymize.split(",")))
String expectedAnonymize = anonymize(expected, Arrays.asList(fieldsToAnonymize.split(",")))
log.info("actual : " + currentAnonymize)
log.info("expected: " + expectedAnonymize)
compare(currentAnonymize, expectedAnonymize)
I have test to add this code in my script to ignore the attribut result , but does not work:
import com.eviware.soapui.support.XmlHolder
xmlHolder["//ns4:startDateTime"] = ""
when i execute the test i want to ignore the result of this attribut :
<ns4:Period>
<ns4:firstDate>2020-09-22T13:12:23</ns4:firstDate>
</ns4:Period>``
any idea !!
本文标签: javaSOAPUITNRIgnore the result of an attribut in my response soapStack Overflow
版权声明:本文标题:java - SOAP-UI-TNR : Ignore the result of an attribut in my response soap - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745154741a2645099.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论