SoapUI相关(财产转移)

时间:2015-06-11 10:46:02

标签: properties soapui correlation

我有一个REST请求,它响应以下内容:

{
   "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlQwWE8xNnAtMmZzMWxremV5",
   "expires_in": 2592000,
   "token_type": "Bearer"
}

我想取access_token的值,将其存储在属性中,并将其重新用于后续两个请求。

在完成一些教程here后,在运行获取access_token的请求时,我得到了一个:

  

解析目标属性时出错:错误意外元素CDATA

但为什么?

我的原始回复中没有CDATA。

1 个答案:

答案 0 :(得分:1)

如果您在使用qs = Item.objects.all() # 12 items count = len(qs) if count > 5: for item in qs[:5]: print item # now I need to display the rest(next 5 items and later 2 items) of results. # something like this: for item in qs[5:10] and next for item in qs[10:12] # BUT I don't know how many items will be in queryset. This is only example. 获取响应中的JSON值时遇到问题,可以使用transfer properties step来实现目标。

因此,请创建一个groovy test step来解析您的回复,获取您的值并将其设置为属性(例如在groovy test step级别),并使用以下代码:

testCase

然后在另一个import groovy.json.JsonSlurper // get response using the name of your test step def response = context.expand('${REST Test Request#Response}') // parse response def jsonResp = new JsonSlurper().parseText(response) // get the token an set as a property in the testCase testRunner.testCase.setPropertyValue('access_token',jsonResp.access_token) (REST或SOAP ...)中,您可以使用以下代码获取您在testSteps中设置的access_token值:

testCase

希望这有帮助,