The article "Read Response Headers in SoapUI using Groovy Script" has how read response header values using Groovy Script. Similarly we can read/write request header values using the below Groovy script. This can be more useful for automating the SoapUI test cases. The below script assertion can be used to read the request header values.

 def header = messageExchange.getRequestHeaders()
 header.each
 {
  key,val ->
  log.info "Key = "+key+" ; value="+val
 }

Read Headers


Read header values from Groovy Script test step.

 def header = testRunner.testCase.testSteps["add"].httpRequest.getRequestHeaders()
 header.each
 {
  key,val ->
  log.info "Key = "+key+" ; value="+val
 }
 
The below Groovy Script can be used to set the request header values.
 import com.eviware.soapui.support.types.StringToStringMap 
 def headers = new StringToStringMap()
 headers.put("name","value");
 headers.put("name1","value1")
 headers.put("name2","value2")
 testRunner.testCase.testSteps["add"].getHttpRequest().setRequestHeaders(headers)
 
The below Groovy Script can be used to update the request header values.
 import com.eviware.soapui.support.types.StringToStringMap 
 def headers = testRunner.testCase.testSteps["add"].getHttpRequest().getRequestHeaders()
 def list = []
 list.add("newvalue")
 headers["name1"] = list;
 testRunner.testCase.testSteps["add"].getHttpRequest().setRequestHeaders(headers)
   
Reference :

http://www.soapui.org/SOAP-and-WSDL/adding-headers-and-attachments.html#1-custom-http-headers
Reactions:
 
Top