[英]How to transfer the ArrayList value from Script Assertion to Groovy Script test step?
I'm getting array of values from the XML data and I need to store that value in a custom property and then I have to make use of it in the Groovy script. 我从XML数据中获取值数组,我需要将该值存储在自定义属性中,然后必须在Groovy脚本中使用它。
When I try to write a script like this: 当我尝试编写这样的脚本时:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def responseHolder = groovyUtils.getXmlHolder( messageExchange.responseContent )
def results = new XmlSlurper().parseText( messageExchange.response.responseContent )
if (results != null)
{
List rowset = results?.ResultSet?.Row?.collect{"${it.OBJ_ID} ${it.REL_OBJ_ID} ${it.CUST_MODEL_CD} ${it.TYPE_CD}"}
log.info(rowset)
context.testCase.setPropertyValue("RowData", rowset)
}
I'm getting the following error in the console: 我在控制台中收到以下错误:
No signature of method: com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.setPropertyValue() is applicable for argument types: (java.lang.String, java.util.ArrayList) values: [RowData, [18144046 5276601 CI DRVD, 18144050 5276601 CI DRVD, ...]]
Possible solutions: setPropertyValue(java.lang.String, java.lang.String), getPropertyValue(java.lang.String)
How can I transfer these values from Script Assertion to Groovy Script ? 如何将这些值从“ 脚本断言”传输到“ Groovy脚本” ?
According to exception that is being thrown: 根据抛出的异常:
No signature of method: com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.setPropertyValue() is applicable for argument types: (java.lang.String, java.util.ArrayList) values: [RowData, [18144046 5276601 CI DRVD, 18144050 5276601 CI DRVD, ...]]
Possible solutions: setPropertyValue(java.lang.String, java.lang.String), getPropertyValue(java.lang.String)
setPropertyValue
method expects two String
parameters. setPropertyValue
方法需要两个String
参数。
You can try serializing rowset
list to JSON string and passing this string to setPropertyValue
. 您可以尝试将
rowset
列表序列化为JSON字符串,然后将此字符串传递给setPropertyValue
。 Next, when you need to read it as list all you have to do is to deserialize this JSON string to a List<String>
object. 接下来,当您需要将其读取为列表时,您要做的就是将该JSON字符串反序列化为
List<String>
对象。 Here is how you can do serialization and deserialization using Groovy's classes JsonOutput
and JsonSlurper
: 这是使用Groovy的类
JsonOutput
和JsonSlurper
进行序列化和反序列化的JsonSlurper
:
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
List<String> rowset = ['18144046 5276601 CI DRVD', '18144050 5276601 CI DRVD']
String json = JsonOutput.toJson(rowset)
List<String> fromJson = new JsonSlurper().parseText(json)
assert rowset == fromJson
Your updated part could look like this: 您更新的部分可能如下所示:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def responseHolder = groovyUtils.getXmlHolder( messageExchange.responseContent )
def results = new XmlSlurper().parseText( messageExchange.response.responseContent )
if (results != null)
{
List rowset = results?.ResultSet?.Row?.collect{"${it.OBJ_ID} ${it.REL_OBJ_ID} ${it.CUST_MODEL_CD} ${it.TYPE_CD}"}
log.info(rowset)
context.testCase.setPropertyValue("RowData", groovy.json.JsonOutput.toJson(rowset))
}
And when you load the data later on you could do: 当您稍后加载数据时,您可以执行以下操作:
List<String> rowset = new groovy.json.JsonSlurper().parseText(context.testCase.getPropertyValue("RowData"))
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.