Anonymous
SOAP-UI-TNR: Ignorieren Sie das Ergebnis eines Attributs in meiner Antwortseife
Post
by Anonymous » 23 Feb 2025, 13:46
Ich benutze dieses Skript in meinem Seifentest Groovy, ich möchte das Ergebnis dieses Attributs in meiner Antwort ignorieren. : 12: 23
``
** Skript Behauptung: ** < /p>
Code: Select all
import groovy.xml.XmlUtil
import groovy.xml.XmlParser
import org.xmlunit.builder.DiffBuilder
import org.xmlunit.builder.Input
import org.xmlunit.diff.DefaultNodeMatcher
import org.xmlunit.diff.Diff
import org.xmlunit.diff.ElementSelectors
import org.xmlunit.diff.MultiLevelByNameAndTextSelector
def anonymize(String current, List fieldsToAnonymize) {
Node node = new XmlParser().parseText(current)
anonymizeField(node, fieldsToAnonymize, null)
return XmlUtil.serialize(node)
}
def anonymizeField(Node node, List 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 = DiffBuilder.compare(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)
< /code>
Ich habe Test, um diesen Code in meinem Skript hinzuzufügen, um das Attribut -Ergebnis zu ignorieren, funktioniert jedoch nicht: < /p>
import com.eviware.soapui.support.XmlHolder
xmlHolder["//ns4:startDateTime"] = ""
< /code>
Wenn ich den Test ausführe, möchte ich das Ergebnis dieses Attributs ignorieren: < /p>
2020-09-22T13:12:23
``
Jede Idee !!
1740314771
Anonymous
Ich benutze dieses Skript in meinem Seifentest Groovy, ich möchte das Ergebnis dieses Attributs in meiner Antwort ignorieren. : 12: 23 `` ** Skript Behauptung: ** < /p> [code]import groovy.xml.XmlUtil import groovy.xml.XmlParser import org.xmlunit.builder.DiffBuilder import org.xmlunit.builder.Input import org.xmlunit.diff.DefaultNodeMatcher import org.xmlunit.diff.Diff import org.xmlunit.diff.ElementSelectors import org.xmlunit.diff.MultiLevelByNameAndTextSelector def anonymize(String current, List fieldsToAnonymize) { Node node = new XmlParser().parseText(current) anonymizeField(node, fieldsToAnonymize, null) return XmlUtil.serialize(node) } def anonymizeField(Node node, List 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 = DiffBuilder.compare(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) < /code> Ich habe Test, um diesen Code in meinem Skript hinzuzufügen, um das Attribut -Ergebnis zu ignorieren, funktioniert jedoch nicht: < /p> import com.eviware.soapui.support.XmlHolder xmlHolder["//ns4:startDateTime"] = "" < /code> Wenn ich den Test ausführe, möchte ich das Ergebnis dieses Attributs ignorieren: < /p> 2020-09-22T13:12:23 `` [/code] Jede Idee !!