MarcovS
9 years agoContributor
Add HTTP headerfield to Requests
Hi All,
I'm using Ready API 1.5.0 for testing REST API calls. Came across this Groovy-script that seems to be useful to add a HTTP-header field to all teststeps. I'm executing it on Project-level fot all TestSuites and TestSteps in that area. The remark that it only should work in 3.5.1 sounds a bit odd to me; executing the script results in the error attached to this message. How can I get this script to work properly in SOAP UI NG?
// Add HTTP headers to Requests // NOTE: will work only in 3.5.1 version import com.eviware.soapui.impl.wsdl.teststeps.* import com.eviware.soapui.support.types.StringToStringMap; def tc = testRunner.testCase.testSuite.getTestCaseByName("<TESTCASE_NAME>") def ts = tc.getTestStepByName("<TESTSTEP_NAME>") def headers = new StringToStringMap() headers.putIfMissing("PmAuthenticationToken","<TOKEN>") log.info ts.getHttpRequest().setRequestHeaders(headers)
def token = new File('C:/temp/SOAPUI/PmAuthenticationToken.txt').text if (token) { request.requestHeaders['PmAuthenticationToken'] = [token] } else { log.error("Token is empty or null") }