如何在SoapUI中使用属性传输从表响应传输属性值?

如何在SoapUI中使用属性传输从表响应传输属性值?,soapui,Soapui,下面是我的GetCountry请求的表格响应 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <GetCitiesByCountryRe

下面是我的GetCountry请求的表格响应

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <GetCitiesByCountryResponse xmlns="http://www.webserviceX.NET">
         <GetCitiesByCountryResult><![CDATA[<NewDataSet>
  <Table>
    <Country>British Indian Ocean Territory</Country>
    <City>Diego Garcia</City>
  </Table>
  <Table>
    <Country>India</Country>
    <City>Ahmadabad</City>
  </Table>
  <Table>
</NewDataSet>]]></GetCitiesByCountryResult>
      </GetCitiesByCountryResponse>
   </soap:Body>
</soap:Envelope>

英属印度洋领土
迭戈·加西亚
印度
艾哈迈达巴德
]]>

从这里,我必须将例如:
Country=India
City=Ahmadabad
的值复制到我的目标请求。如何使用属性传递方法传递这些值?有人能帮我修改一下格式吗?

我认为财产转移步骤是不可能的。 尝试使用下面的“脚本断言”来解决您的问题:

使用所需的国家/地区和城市名称在测试用例级别定义以下自定义属性

  • 属性名称-
    CountryName
    和值为
    India
  • 属性名称-
    CityName
    和值为
    Ahamadabad
  • 添加脚本断言。如何在SOAP UI中添加脚本断言,请参阅

    defsearchdata={data,element->
    def parsedData=new XmlSlurper().parseText(数据)
    parsedData.'**'。将{it.name()==element}作为字符串查找
    }
    //闭包来检查xpath
    def searchByXpath={data,xpath->
    def holder=new com.eviware.soapui.support.XmlHolder(数据)
    holder.getNodeValue(xpath)
    }
    assert context.response,“响应为空或null”
    //获取响应的CDATA部分
    def cdata=searchData(context.response,“GetCitiesByCountryResult”)
    //获取xpath结果
    def cityName=context.expand(“${#TestCaes#cityName}”)
    def countryName=context.expand(“${#TestCaes#countryName}”)
    def result=searchByXpath(cdata,“存在(//表[City='$cityName'和Country='$countryName']))
    log.info“是城市${cityName}和国家${countryName}在表中存在:${result}”
    assert result=='true',“${cityName}和${countryName}在结果表中不存在”
    
    现在,要在下一个请求中访问上述定义的属性,请参考以下定义(使用属性扩展)

    ${TestCase}CountryName}
    ${#TestCase#CityName}
    
    国家名称、城市名称值是否已固定?是的,国家名称和城市名称已固定。您是否知道是否可以使用Groovy脚本执行此操作?使用请求的信息更新答案。请检查一下,试试看。
    <web:CountryName>${#TestCase#CountryName}</web:CountryName>
    <web:CityName>${#TestCase#CityName}</web:CityName>