Reputation: 185
I have a test case, in the first testStep I make a request. I retrieved the JSESSIONID in the response of the first request and now I want to put it as a "cookie" property in the header of all my others testStep requests. How can I do it?
log.info "$jsessionid"
for (testStep in testRunner.testCase.getTestStepList()){
if (testStep.getName() != "Request 1" && testStep.getName() != "Groovy Script") {
//set the JSESSIONID in the request header property "Cookie"
}
}
My others testStep have some values in their header
I want to add the "cookie : JSESSIONID=MYVALUE" in the list, or replace it if the property already exists.
Upvotes: 0
Views: 1438
Reputation: 185
I found a way to set the "Cookie" property in the header of every other testStep. The property is added in a list, this way it will replace older cookie values.
import com.eviware.soapui.impl.wsdl.teststeps.*
//(...)
//Retrieve the JSESSIONID and put it in a variable
log.info "$jsessionid"
for (testStep in testRunner.testCase.getTestStepList()){
if (testStep instanceof RestTestRequestStep && testStep.getName() != "Request 1" && testStep.getName() != "Groovy Script") {
def list = []
list.add(jsessionid)
def headers = testStep.testRequest.requestHeaders
headers["Cookie"] = list
testStep.testRequest.requestHeaders = headers
log.info testStep.testRequest.requestHeaders["Cookie"]
}
}
Upvotes: 2