Contributions
Setting project-wide custom http headers
Hi, I'm currently testing webservices that require a number of custom http headers. By now I've found a way to set those headers for all requests inside of one TestSuite (see https://www.eviware.com/forum/viewtopic.php?f=5&t=3746#p22158), but this doesn't cover those requests automatically created after importing a new WSDL into the project. Since I use those requests to test and fine-tune the SOAP content before copying them into the TestSuite, I would have to manually add the needed headers to each request Is there a way to preconfigure those requests with http headers, perhaps by changing a template or by using another groovy script? Regards, Felix1.2KViews0likes1CommentRe: Using Groovy to set a HTTP header value
I ran into the same problem. The solution is simple: There is both StringToStringMap and StringToStringsMap in com.eviware.soapui.support.types - the method expects the plural variant. Here's an adaption of M McDonald's script (combined with code from https://thewonggei.wordpress.com/2010/08/05/configure-http-basic-auth-once-for-soapui-test-suties/) to write TestSuite properties into the headers of all called TestRequests: import com.eviware.soapui.impl.wsdl.teststeps.* import com.eviware.soapui.support.types.StringToStringsMap for( testCase in testSuite.getTestCaseList() ) { for( testStep in testCase.getTestStepList() ) { if( testStep instanceof WsdlTestRequestStep ) { def headers = new StringToStringsMap() headers.put(testSuite.getPropertyValue("ExampleHeaderName"),testSuite.getPropertyValue("ExampleHeaderValue")) log.info("Setting HTTP headers ${headers} in test case ${testCase.getLabel()}") testStep.getTestRequest().setRequestHeaders(headers) } } } Just set the properties ExampleHeaderName and ExampleHeaderValue for your TestSuite and use the script as "Setup Script" of the TestSuite.31KViews0likes0Comments