no

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.*...

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);
     }
 }
}

Post a Comment

item