有没有办法可以使用groovy脚本将属性值从soap测试用例响应转移到另一个soap测试步骤?请找到响应结构
<NS1:Envelope xmlns:NS1="http://schemas.xmlsoap.org/soap/envelope/">
<NS1:Body>
<NS2:processRequestResponse xmlns:NS2="http://bussinessfacade.fawryswitch.ebpp.fawryis.com/">
<return>
<Response>
<SignonRs>
<ClientDt>2016-04-19T16:58:12.141</ClientDt>
<CustLangPref>ar-eg</CustLangPref>
<ServerDt>2016-11-02T13:58:09</ServerDt>
<Language>en-gb</Language>
<SignonProfile>
<Sender>FAWRY</Sender>
<Receiver>FAWRYRTL</Receiver>
<MsgCode>BillInqRs</MsgCode>
<Version>V1.0</Version>
</SignonProfile>
</SignonRs>
<PresSvcRs>
<RqUID>0045d98c-e81c-43fd-b887-b0b1a1b1641d</RqUID>
<AsyncRqUID>1a50b367-4aca-4d90-9f95-ddca99e8639d</AsyncRqUID>
<MsgRqHdr>
<NetworkTrnInfo>
<OriginatorCode>FAWRYRTL</OriginatorCode>
<TerminalId>11427</TerminalId>
</NetworkTrnInfo>
</MsgRqHdr>
<Status>
<StatusCode>200</StatusCode>
<Severity>Info</Severity>
<StatusDesc>Success.</StatusDesc>
</Status>
<BillInqRs>
<DeliveryMethod>POS</DeliveryMethod>
<BillRec>
<BillingAcct>0120000200</BillingAcct>
<BillTypeCode>111</BillTypeCode>
<BillRefNumber>2feeccae-8fd2-4d41-903a-df2ef96d5264</BillRefNumber>
<BillInfo>
<BillSummAmt>
<BillSummAmtCode>TotalAmtDue</BillSummAmtCode>
<CurAmt>
<Amt>370</Amt>
<CurCode>EGP</CurCode>
</CurAmt>
</BillSummAmt>
<IssueDt>2016-08-01</IssueDt>
</BillInfo>
</BillRec>
</BillInqRs>
</PresSvcRs>
</Response>
</return>
</NS2:processRequestResponse>
</NS1:Body>
</NS1:Envelope>
&#13;
ack.imgur.com/Z7UwT.png
答案 0 :(得分:2)
您可以将Script Assertion
用于收到回复的同一请求步骤。可以使用单独的Groovy Script
步骤来避免。因此,在将它们保存为属性之前,请检查响应中所需的值。
脚本断言:
/**
* This is script assertion
* retrieves specified values from currest step response
* and stores at test case level
**/
//Closure to search the data
def searchData = { data, item ->
data?.'**'.find { it.name() == item} as String
}
//Assert the response.
assert context.response, "Response is empty or null"
def parsedData = new XmlSlurper().parseText(context.response)
//Get Amount
def amt = searchData(parsedData, 'Amt')
log.info "Amount from response: ${amt}"
//Check the value amt
assert amt, "Amount is empty or not present"
//Store Amount at test case level
context.testCase.setPropertyValue('AMOUNT', amt)
//Get AsyncRqUID
def rqUid = searchData(parsedData, 'AsyncRqUID')
log.info "AsyncRqUID from response: ${rqUid}"
//Check the value rqUid
assert rqUid, "AsyncRqUID is empty or not present"
//Store RqUid at test case level
context.testCase.setPropertyValue('AsyncRqUID', rqUid)
以上内容会将值370
作为数量,1a50b367-4aca-4d90-9f95-ddca99e8639d
作为AsyncRqUID。
在您需要检索这些值的其他测试请求步骤中,请按照以下说明使用:
${#TestCase#AMOUNT}
。示例<amount>${#TestCase#AMOUNT}</amount>
${#TestCase#AsyncRqUID}
。示例<rquid>${#TestCase#AsyncRqUID}</rquid>