我们需要查找当前国家/地区的经销商数量。在下面的 xml 请求中,每个请求的键值对都会有所不同。 Soap 请求的输入将在 .txt 文件中给出。根据 .txt 文件中的输入数量,我需要动态生成键值对 xml 标签。
**Format of Input.txt**
1.key1=Fruit,value1=Carrot,Key2=Vegetable,value2=Carrot
2.key1=Vegetable,value1=Potato
3.key1=Fruit,value1=Apple,key2=Fruit,value2=Orange,key3=Fruit,value3=Mango
SoapUI 请求
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET">
<soapenv:Header/>
<soapenv:Body>
<web:GetCitiesByCountry>
<web:CountryName>Ind</web:CountryName>
<web:queryParameters>
<web:key>Fruits</web:key>
<web:value>Mango</web:value>
</web:queryParameters>
<web:queryParameters>
<web:key>Vegetables</web:key>
<web:value>Carrot</web:value>
</web:queryParameters>
</web:GetCitiesByCountry>
</soapenv:Body>
</soapenv:Envelope>
您说您已对输入记录的读取进行了排序,因此我只是将一些记录放入地图中以用于演示目的。然后,如果您的请求有效负载开始看起来像:
<soap:Envelope xmlns:soap="w3.org/2003/05/soap-envelope">
<soap:Header/>
<soap:Body>
<web:GetCitiesByCountry xmlns:web="webserviceX.NET">
<web:CountryName>hello</web:CountryName>
</web:GetCitiesByCountry>
</soap:Body>
</soap:Envelope>
您可以循环遍历输入记录并将它们附加到请求中:
import groovy.xml.XmlUtil
// Assuming the input document has been read into a HashMap
def map = ['Fruits': 'Banana',
'Vegetable': 'Potato'
]
// Get testStep by it's name
def testStep = context.testCase.getTestStepByName('soapRequest')
// Parse the request
def xml = new XmlSlurper().parseText(testStep.getPropertyValue('request'))
// Loop through the map and append the key/value pairs
xml.Body.appendNode {
map.each {k, v ->
Parameters {
Key(k)
Value(v)
}
}
}
// Check the output
log.info(XmlUtil.serialize( xml ))
// Update the request
testStep.setPropertyValue('request',groovy.xml.XmlUtil.serialize( xml ))
之后,您的请求将如下所示:
<soap:Envelope xmlns:soap="w3.org/2003/05/soap-envelope">
<soap:Header/>
<soap:Body>
<web:GetCitiesByCountry xmlns:web="webserviceX.NET">
<web:CountryName>hello</web:CountryName>
</web:GetCitiesByCountry>
<Parameters>
<Key>Fruits</Key>
<Value>Banana</Value>
</Parameters>
<Parameters>
<Key>Vegetable</Key>
<Value>Potato</Value>
</Parameters>
</soap:Body>
</soap:Envelope>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)