Forum Discussion
renatoathaydes
12 years agoContributor
Please allow me to refactor the above script and extend it to work with REST TestSteps as well:
import com.eviware.soapui.impl.wsdl.teststeps.*
def valueOf = { key -> testSuite.getPropertyValue( key ) }
testSuite.testCaseList.each { testCase ->
testCase.testStepList.each { testStep ->
if( testStep instanceof WsdlTestRequestStep || testStep instanceof RestTestRequestStep ) {
def headers = [ (valueOf( "ExampleHeaderName" )) : [ valueOf( "ExampleHeaderValue" ) ] ]
log.info("Setting HTTP headers ${headers} in test case ${testCase.label}")
testStep.testRequest.requestHeaders = headers
}
}
}
- anand78928 years agoOccasional Contributor
Here is more precise solution to this:
Problem: I wanted to add a header with name "Authorization" and value "${#project#token}"(stored at project level)'
Solution:
Run Groovy script and it will solve your problem.
i
import com.eviware.soapui.impl.wsdl.teststeps.* import com.eviware.soapui.support.types.StringToStringMap def project = context.testCase.testSuite.project def token = "\${"+"#"+"Project"+"#"+"token}" ${#project#token} log.info(token) def valueOf = { key -> testSuite.getPropertyValue( key ) } project.testSuiteList.each{ testSuite -> testSuite.testCaseList.each { testCase -> testCase.testStepList.each { testStep -> if( testStep instanceof WsdlTestRequestStep || testStep instanceof RestTestRequestStep ) { def headers = new StringToStringMap() headers.put("Authorization",token) log.info("Setting HTTP headers ${headers} in test case ${testCase.label}") testStep.testRequest.setRequestHeaders(headers) } } } }
Related Content
- 10 years ago
- 11 years ago
Recent Discussions
- 15 years ago