使用 groovy 在 soapui 中传输属性
Properties transfer in soapui using groovy
有什么方法可以使用 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>
您可以在收到响应的同一请求步骤中使用 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。
在其他需要这些检索值的测试请求步骤中,请按以下方式使用:
- 对于金额 (Amt),
${#TestCase#AMOUNT}
。示例 <amount>${#TestCase#AMOUNT}</amount>
- 对于 RqUID,
${#TestCase#AsyncRqUID}
。示例 <rquid>${#TestCase#AsyncRqUID}</rquid>
有什么方法可以使用 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>
您可以在收到响应的同一请求步骤中使用 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。
在其他需要这些检索值的测试请求步骤中,请按以下方式使用:
- 对于金额 (Amt),
${#TestCase#AMOUNT}
。示例<amount>${#TestCase#AMOUNT}</amount>
- 对于 RqUID,
${#TestCase#AsyncRqUID}
。示例<rquid>${#TestCase#AsyncRqUID}</rquid>