我使用XMLSlurper来定义XML来自JDBC查询结果,但是如何在结果的部分上断言?

发布于 2025-01-24 06:14:54 字数 161 浏览 3 评论 0原文

我有一串XML作为此脚本的响应, // 。

导入

groovy.json

返回 //

我想断言resp对象的长串联字符串的部分。
我刚刚询问,并从一个带有5列的数据库中恢复了记录(这5个文本是“任何内容”的示例文本),

谢谢!

I've got a string of xml as the response from this script,
//
import groovy.json.*

def resp = new XmlSlurper().parseText(messageExchange.getResponse().responseContent)

assert (resp == "whateverwhatever"), "ERROR: invalid result!!"

return
//

and I want to assert on pieces of the long concatenated string that the resp object is.
I just queried and am getting back a record(s) from a database with 5 columns (those 5 cols of text are the "whateverwhatever" example text)

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

李不 2025-01-31 06:14:54

您不能直接对您获得的XML对象上的断言,

可以在getAT和类似函数下使用,以从xml获取整体或一些特定的内容,然后

def content = context.expand('${Request#Request}')
def xml = new XmlSlurper().parseText(content)
def token = xml.getAt("Token")
log.info token

使用log.info尝试使用

ostert 。示例代码可以指导您

def parsedResponse = new XmlSlurper().parseText(response)
String convertedValue = parsedResponse.Body.ConversionRateResponse.
ConversionRateResult.text()
log.info(convertedValue)

从XML上在XML上实现主张,我们正在尝试与DOT操作员达到特定的节点,然后我们获得的文本我们正在断言它

You cannot directly apply assert on that XML object you get

you can use like below the getAt and similar function to get the whole or some specific content from XML and then apply the assert

def content = context.expand('${Request#Request}')
def xml = new XmlSlurper().parseText(content)
def token = xml.getAt("Token")
log.info token

Try using log.info to know the details at each step

Sharing some sample code which can guide you to achieve assertion on XML

def parsedResponse = new XmlSlurper().parseText(response)
String convertedValue = parsedResponse.Body.ConversionRateResponse.
ConversionRateResult.text()
log.info(convertedValue)

Here from the XML we are trying to reach a particular node with dot operator and then the text we get we are asserting it

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文