Looking for a JavaEE Architect or Potential Tech Co-Founder?
Please don't hesitate to contact me.

How to set Authorization header in all SoapUI test cases via Script

To set the Authorization header in each test case of a testSuite, we run the script below.

import com.eviware.soapui.impl.wsdl.teststeps.*
import com.eviware.soapui.support.types.*;

StringToStringMap headers = new StringToStringMap();
StringToStringMap headersForSuper = new StringToStringMap();
 
String userPass = testCase.testSuite.project.getPropertyValue("username")+":"+testCase.testSuite.project.getPropertyValue("password");
log.info("userPass=" + userPass);

headers.put("Authorization","Basic "+userPass.getBytes().encodeBase64());

for(testSuiteItem in  testCase.testSuite.project.getTestSuiteList()){
 for( testCaseItem in testSuiteItem.getTestCaseList() ) {
     log.info("Setting basic auth for all WSDL test requests in test case ["+testCaseItem.getName()+"]")
     for( testStep in testCaseItem.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep) ) {
   testStep.getTestRequest().setPreemptive(true);       
   testStep.getTestRequest().setRequestHeaders(headers);
     }
 }
}
How to set Authorization header in all SoapUI test cases via Script How to set Authorization header in all SoapUI test cases via Script Reviewed by Edward Legaspi on Thursday, March 24, 2016 Rating: 5

No comments:

Powered by Blogger.