Originally posted by Optical_Image_T on June 08, 2016
We have SOAP UI 5.1.1, and we have a SOAP test project and a REST test project in it.
We have a bunch of HTTP requests in the SOAP project and all the requests in the REST Test project need new HTTP headers.
If there any script which will add these headers to all my requests , versus me having to do it manually?
Originally posted by faizmuhammad on June 08, 2016
you can add headers for HTTP REST or SOAP from the request. look at the bottom of your request screen there are options for it.
see highlighted part of attached image
Add headers & Auth
Originally posted by Optical_Image_T on June 08, 2016
IS there a script that can add it too all?
I have been doing that manually, but we have tons of test steps?
Originally posted by faizmuhammad on June 08, 2016
there is an alternate way i.e. VIA groovy.
//////////////////////////
import com.eviware.soapui.support.types.StringToStringMap
def headers = new StringToStringMap()
headers.put(“Header1”,“value123”)
testRunner.testCase.getTestStepByName(“HTTP Request”).testRequest.setRequestHeaders(headers)
///////////////////////////
in above script
Header1 is the name of header
value123 is the value of Header1
and HTTP Request is the name of test step
if you have many test step you can do multiple iteration using this code.
let me know if you need further help.
system
June 17, 2016, 8:49pm
5
Originally posted by Optical_Image_T on June 17, 2016
Using this code I can print each step name, But now how do I add the headers?
import com.eviware.soapui.support.types.StringToStringMap
def headers = new StringToStringMap()
headers.put("Cookie","XSRF-TOKEN=soap;")
headers.put("X-XSRF-TOKEN","soap")
def testCases = testRunner.testCase
testCases.each
{
for(testStep in it.testStepList)
{
log.info "~~~Test Step:" + testStep.name
//testStep.testRequest.setRequestHeaders(headers)
}
}
system
June 18, 2016, 12:08pm
6
Originally posted by nmrao on June 18, 2016
Please check this thread
</t/adding-http-headers-to-all-test-cases-of-a-test-suite-or-several-test-suites/675>
system
June 20, 2016, 2:05pm
7
Originally posted by Optical_Image_T on June 20, 2016
When you mention multiple iteration how do we do that?
Why can’t I simply do this
import com.eviware.soapui.support.types.StringToStringMap
def headers = new StringToStringMap()
headers.put(“Cookie”,“XSRF-TOKEN=soap;”)
headers.put(“X-XSRF-TOKEN”,“soap”)
def testCases = testRunner.testCase
List name = new ArrayList();
testCases.each
{
for(testStep in it.testStepList)
{
log.info “~~~Test Step:” + testStep.name
name.add(testStep.name);
}
}
for(int i=0;i<name.size();i++){
testRunner.testCase.getTestStepByName(name.get(i)).testRequest.setRequestHeaders(headers)
}
When I iterate over the testStep if I can get the name why ca’t I update the headers also?
system
June 20, 2016, 3:35pm
8
Originally posted by nmrao on June 20, 2016
Did not get what you mean by multiple iteration? What are you referring here?
If you go thru the mentioned thread, that user is able to achieve the same.
I thought, from the original post, that you need to add the headers to all the outgoing requests.
Not sure what you mean by why can’t I do this. You want some to review what you wrote? or you want to explain what your script does?