我希望你们能再一次帮助我!
我想出了如何在一个简单的场景中从REST响应中提取一个值,并将该值传递给前面的测试步骤,但是,现在我不知道如何从一个数组中提取一个值。 REST响应(如下所示),用于前面的测试步骤。
更具体地说,我试图提取其中一个" id" answerChoices中的值。
响应有效负载:
(GET) localhost/ws/portal/survey/question/${Create UX Survey Question#ResponseAsXml#//*:id}
{
"id": 589,
"isEnabled": true,
"type": "RADIO",
"wording": "SoapUI Test UX Survey Question",
"answerChoices": [
{
"id": 1546,
"order": 4,
"text": "Choice4"
},
{
"id": 1543,
"order": 2,
"text": "Choice2"
},
{
"id": 1544,
"order": 3,
"text": "Choice3"
},
{
"id": 1545,
"order": 1,
"text": "Choice1"
}
]
}
然后我尝试将其中一个answerChoices:id传递给下一个请求中的questionChoiceId值(如下所示)。
(POST) localhost/ws/portal/survey/alert
{
"questionChoiceId" : ${},
"restaurantId" : ${Create New Restaurant#ResponseAsXml#//*:id},
"alertProfileId" : ${#Project#emailAlertProfileId}
}
我无法理解,我已尝试在属性转移中声明命名空间,这件事让我感到困惑。你可以指出我的任何方向都将非常感激!
答案 0 :(得分:0)
我明白了!所以,我想确保我发布了答案,以防其他人遇到同样的问题!
我刚刚编写了一个groovy脚本并执行了以下操作:
negativeSurveyAnswer
和positiveSurveyAnswer
)添加Groovy测试步骤并添加以下代码:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def questionResponse = context.expand('${Get UX Survey Question Details by questionId#ResponseAsXml}')
def idVals = questionResponse.split("<id>", -1)
def Choice1Id = idVals[1].split("</id>", -1)[0]
def Choice4Id = idVals[2].split("</id>", -1)[0]
def prop2 = testRunner.testCase.testSuite.project.getProperty("positiveSurveyAnswer")
prop2.setValue(Choice1Id)
def prop3 = testRunner.testCase.testSuite.project.getProperty("negativeSurveyAnswer")
prop3.setValue(Choice4Id)
通过获取该值并将其转移到Project的属性,接下来的测试步骤是:
{
"questionChoiceId" : ${#Project#negativeSurveyAnswer},
"restaurantId" : ${Create New Restaurant#ResponseAsXml#//*:id},
"alertProfileId" : ${#Project#emailAlertProfileId}
}
希望这有助于其他人!