2016-09-28 108 views
-1

我需要解析来自请求1的响应并将响应中的特定数值传递给请求2.以下是JSON响应。SoapUI REST响应会话令牌


HTTP/1.1 200 OK 日期:星期三,2016年9月28日19点42分35秒GMT 的Content-Length:61

{ "response":"New session Created with session Id 123456789101213" }


我应该怎么用 - 常规或物业转移? if groovy - 请让我知道我应该使用什么代码 如果属性传递 - 我应该使用什么样的解析消息?

回答

0

是的,它可以以任何方式完成,这是一个额外的步骤。

也可以在当前的测试步骤中使用Script Assertion而没有额外的步骤。那里的回应也可以断言。

伪指令:

  • 检索响应并解析它
  • 断言如果所需的值是存在于所述响应
  • 设定在测试情况下电平的值
  • 使用使用检索到的值在测试用例的其他测试步骤中进行属性扩展。

脚本断言

/** 
* This is a script assertion 
* which reads the response and asserts if there is response 
* reads response property and sets at test case level property SESSION_ID 
*/ 
def jsonString = context.response 
def json = new groovy.json.JsonSlurper().parseText(jsonString) 

//Check if the response is not empty or null 
assert json, "Response received is empty or null" 
def sessionId = json.response as String 

//Check if there is reponse property exists in response json 
assert sessionId, "response property is empty or null" 
log.info "Session id : ${sessionId}" 

//To set the value at test case level 
context.testCase.setPropertyValue('SESSION_ID', sessionId) 

如何使用检索到的会话ID的测试用例的其他测试步骤?

  • 如果步骤类型是Groovy脚本,请使用以下两种方法之一:context.expand('${#TestCase#SESSION_ID}')
    context.testCase.getPropertyValue('SESSION_ID')

  • 如果步骤类型是其他类型的,比如SOAP,REST,JDBC, HTTP等,然后使用:
    ${#TestCase#SESSION_ID}

注:当然,它也可以在浴室o设定值r项目级别,可以在套件或项目级别分别重用检索值