GreatCall__Supp
10 years agoNew Contributor
Trying to post Header value to another test case
My groovy scripting skills are beginner level, which is giving me this problem.
So I'm using JSONslurper to grab the value for access_token to use as a header value for Authorization in a later test case. Currently, I'm only able to get it to post on the current test case "ObtainAccessToken", which I don't want it to do, and I'm not sure how to get it to post to the other test case (ex. "UseAccessToken").
Also, how do I get it to print additional text like "Bearer" for example, along with the token value? For example, is there a way to get to print like this?
headers["Authorization"] = "Bearer ".slurperresponse.access_token (which I've tried and didn't work)
Here is my groovy code:
So I'm using JSONslurper to grab the value for access_token to use as a header value for Authorization in a later test case. Currently, I'm only able to get it to post on the current test case "ObtainAccessToken", which I don't want it to do, and I'm not sure how to get it to post to the other test case (ex. "UseAccessToken").
Also, how do I get it to print additional text like "Bearer" for example, along with the token value? For example, is there a way to get to print like this?
headers["Authorization"] = "Bearer ".slurperresponse.access_token (which I've tried and didn't work)
Here is my groovy code:
import com.eviware.soapui.support.types.StringToStringMap
import groovy.json.JsonSlurper
def request = context.testCase.testSteps["ObtainAccessToken"].testRequest
def headers = request.getRequestHeaders()
responseContent = testRunner.testCase.getTestStepByName("ObtainAccessToken").getPropertyValue("response") //add your property value here
slurperresponse = new JsonSlurper().parseText(responseContent)
headers["Authorization"] = slurperresponse.access_token
request.setRequestHeaders(new StringToStringMap(headers))