Forum Discussion
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
IS there a script that can add it too all?
I have been doing that manually, but we have tons of test steps?
- faizmuhammad9 years agoOccasional Contributor
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.
- Optical_Image_T9 years agoOccasional Contributor
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) } }
- nmrao9 years agoChampion Level 3Please check this thread
https://community.smartbear.com/t5/SoapUI-Open-Source/Adding-HTTP-headers-to-ALL-test-cases-of-a-test-suite-or-several/m-p/120208#M20745
- Optical_Image_T9 years agoOccasional Contributor
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?
- nmrao9 years agoChampion Level 3Did 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?
Related Content
- 6 years ago
Recent Discussions
- 15 years ago