2014-01-22 2 views
3

Так что я хочу, чтобы автоматически добавлять заголовок SOAP для каждого запроса, который генерируется в SoapUI, поскольку у меня есть сотни из них, и это вручную раздражает.SoapUI - автоматически добавлять пользовательские заголовки SOAP к исходящему запросу

Позволяет сказать, что это мой пример запроса генерируется из WSDL, который выглядит так:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pol="http://something"> 
    <soapenv:Header> 
    </soapenv:Header> 
    <soapenv:Body> 
     <pol:GetSomething> 
     <tag1>3504</tag1> 
     <tag2>ALL</tag2> 
     </pol:GetSomething> 
    </soapenv:Body> 
</soapenv:Envelope> 

и когда я делаю запрос я хочу SoapUI изменить его, чтобы выглядеть:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pol="http://something"> 
    <soapenv:Header> 
     <token xmlns="ns1">${TOKEN}</token> 
     <user xmlns="ns2">user</user> 
     <system xmlns="ns3">system</system> 
    </soapenv:Header> 
    <soapenv:Body> 
     <pol:GetSomething> 
     <tag1>3504</tag1> 
     <tag2>ALL</tag2> 
     </pol:GetSomething> 
    </soapenv:Body> 
</soapenv:Envelope> 

Возможно ли это в SoapUI?

ответ

4

В вашем TestCase вы можете добавить первый шаг типа Groovy Script, в этом сценарии вы можете манипулировать каждый запрос на добавление необходимых элементов на <soap:Header>, я дам вам пример, который работает для меня:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context); 
def tcase = testRunner.testCase ; 
// get total number of testSteps 
def countTestSteps = tcase.getTestStepList().size(); 
// start with 1 to avoid groovy script testStep 
for(i=1;i<countTestSteps;i++){ 

// get testStep 
def testStep = tcase.getTestStepAt(i); 
// get request 
def request = testStep.getProperty('Request').getValue(); 
// get XML 
def xmlReq = groovyUtils.getXmlHolder(request); 
// get SOAPHEADER 
def soapHeader = xmlReq.getDomNode("declare namespace soap='http://schemas.xmlsoap.org/soap/envelope/'; //soap:Header") 
// document to create new elements 
def requestDoc = soapHeader.getOwnerDocument() 
// create new element 
def newElem = requestDoc.createElementNS(null, "element"); 
// insert in header 
soapHeader.insertBefore(newElem, soapHeader.getFirstChild()); 
// now put your new request in testStep 
log.info xmlReq.getXml(); 
testStep.setPropertyValue('Request', xmlReq.getXml()); 
} 

Этот примерный код добавляет только один новый элемент в <soap:header>, но вы можете изменить его, чтобы добавить атрибуты, текстовое содержимое и другие узлы. Вы также можете посмотреть:

dynamically create elements in a SoapUI request | SiKing

Смежные вопросы