提前感谢您的帮助。我被困在下面的场景中一段时间了。由于我不熟悉编码/编程,因此我很难理解代码中的错误。任何帮助将不胜感激。再次感谢。我试图以推荐的方式提出问题。如果您仍然难以理解问题,请道歉。由于这是Stack溢出的第一篇文章,我将在你给我反馈时学习。谢谢
情境:
1)我有一个REST服务,可以让我回复多个节点。
例如:
[
{
"Namespace": "dbo",
"ObjectName": "WorkOrder",
"IsCustomQuery": false,
"CustomQuery": null,
"Name": "[dbo].[WorkOrder]",
"Description": "",
"Fields": []
},
{
"Namespace": "dbo",
"ObjectName": "sysdiagrams",
"IsCustomQuery": false,
"CustomQuery": null,
"Name": "[dbo].[sysdiagrams]",
"Description": "",
"Fields": []
},
{
"Namespace": "Maintenance",
"ObjectName": "Configuration",
"IsCustomQuery": false,
"CustomQuery": null,
"Name": "[Maintenance].[Configuration]",
"Description": "",
"Fields": []
}
]
等等......
我的理解是,这可以使用set property(),get property()和groovy脚本中的FOR循环来实现。
伪代码:
1)将响应中的每个节点存储为数组中的项目。
2)使用sizeof()
查找节点数3)使用节点数作为最大限制,使用FOR循环中的POST循环,使用数组中的每个项作为属性。
使用的代码:
import groovy.json.JsonSlurper
def response = context.expand( '${GET schema#Response}' ) /*GET schema is the GET request which returns the response with 12 nodes*/
def r = new JsonSlurper().parseText(response)
def n = r.size()
//log.info(r[1])
def i=0
for (i=0;i<n;i++)
{
testRunner.testCase.setValue("lists", r[i] as String)
def getLocalPropValue = testRunner.testCase.getPropertyValue("lists")
log.info(getLocalPropValue) /* to verify that each item is retrieved*/
testRunner.runTestStepByName("REST Request") /*REST request is the POST service which should be run once for each of the nodes*/
}
最常见的错误消息: - 错误位于第9行。
groovy.lang.MissingMethodException:没有方法签名: com.eviware.soapui.impl.wsdl.WsdlTestCasePro.setValue()适用 对于参数类型:(java.lang.String,java.lang.String)值: [lists,[CustomQuery:null,Description:,Fields:[], IsCustomQuery:false,Name:[dbo]。[WorkOrder],命名空间:dbo, ObjectName:WorkOrder]]可能的解决方案:setName(java.lang.String), 第4行的setName(java.lang.String),getName(),getClass()错误