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.*...
https://www.czetsuyatech.com/2016/03/how-to-set-authorization-header-in-all.html
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