2017-03-04 108 views
0

可一些解释上的SOAP UI免费的最好的方式来实现以下场景SOAP UI:使用XML格式的值的服务请求

负载从一个测试用例Web服务的响应值作为第二请求值测试用例Web服务。

在测试用例脚本1断言

import com.eviware.soapui.support.XmlHolder 
def respXmlHolder = new XmlHolder(messageExchange.getResponseContentAsXml()) 
respXmlHolder.declareNamespace("ns1","http://www.moj.com/api/services/checkout") 
def finsess = respXmlHolder.getNodeValue("//ns1:sessresp/ns1:sessionId") 
log.info finsess 

日志信息

示出了下面70c8a6f80b6ff0c72502

现在,如下所示的sessionid以上如何自动加载这个到测试案例2的Web服务。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://www.moj.com/api/services/final"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <typ:FinSessionRequest> 
     <typ:correlationId>1234</typ:correlationId> 
     <typ:sessionId>70c8a6f80b6ff0c72502</typ:sessionId> 
     <typ:username>abcd</typ:username> 
     <typ:password>1234</typ:password> 
     </typ:FinSessionRequest> 
    </soapenv:Body> 
</soapenv:Envelope> 

回答

0

您可以使用房产转让测试步骤这个任务,没有Groovy脚本。请参阅SoapUI docs。您只需使用XPath选择源XML元素,并选择相似的目标元素。当您执行测试步骤(或测试用例)时,SoapUI将执行替换。我建议使用这种方式,因为它是透明的。

如果你真的需要的价值与Groovy脚本调用,你可以设置你的断言脚本测试套件属性值:

def testSuite = context.getTestCase().getTestSuite() 
testSuite.setPropertyValue("MyId", finsess) 

,然后将身份识别码到您请求消息:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://www.moj.com/api/services/final"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <typ:FinSessionRequest> 
     <typ:correlationId>1234</typ:correlationId> 
     <typ:sessionId>${#TestSuite#MyId}</typ:sessionId> 
     <typ:username>abcd</typ:username> 
     <typ:password>1234</typ:password> 
     </typ:FinSessionRequest> 
    </soapenv:Body> 
</soapenv:Envelope> 

只要两个测试用例属于同一个测试套件,这就可以工作。

Karel