【问题标题】:How get value with soapui (groovy) from a xml with equals tags but differents attributes如何从具有等于标签但属性不同的xml中使用soapui(groovy)获取价值
【发布时间】:2019-09-05 12:52:12
【问题描述】:

我在 groovy 中制作了一个自动化脚本,它从 SOLR 获取数据,然后将该数据设置在属性中以供将来使用。 我正在使用脚本断言来执行此操作,因为减少了套装中的步骤数量。 问题是:从SOLR接收的XML在所有数据中都具有相同的名称,唯一的区别是属性“名称”。 我想通过属性获取值。

我尝试过使用 xmlSlurper 和 XmlHolder,但我不能只得到一个值,只能得到一组数据(SOLR 可以随机排序文档,所以我不能使用这个解决方案)。

SOLR的答案是这样的:

<response>
  <doc>
    <str name="Destination">6</str>
    <str name="BUS">0</str>
    <str name="Tax">N</str>
    <str name="Passage">N</str>
    <str name="Vendor">2301</str>
    <str name="id">1135XV942220</str>
  </doc>
</response>

我试过了:

def resp = new XmlSlurper().parseText(context.response)
def results = resp.response.doc.find {it.name()=="BUS"}?.text()

这让我一无所获。

def results = resp.response.doc.str.'@name'.text().equals('BUS')

给我取值 false (?)

例如,我想获取 id 并将其传输到测试套件级别的属性。 任何可能的解决方案?

【问题讨论】:

  • 找到了!!!!!!!!!!!!

标签: groovy xml-parsing soapui


【解决方案1】:

使用 XmlHolder...

import com.eviware.soapui.support.XmlHolder
resp = new XmlHolder(context.response)
log.info resp.getNodeValue("//response/doc/str[@name='BUS']")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-26
    • 1970-01-01
    • 2016-02-24
    相关资源
    最近更新 更多