Skip to content

Instantly share code, notes, and snippets.

@anandsunderraman
Last active August 29, 2015 14:07
Show Gist options
  • Save anandsunderraman/42785f1e1be0cd7dcc15 to your computer and use it in GitHub Desktop.
Save anandsunderraman/42785f1e1be0cd7dcc15 to your computer and use it in GitHub Desktop.
iterate thru test steps and add header to each of them
import groovy.json.JsonSlurper;
import com.eviware.soapui.support.types.StringToStringMap;
//get the response from the test step that makes the call to get the authentication token
def authResponse = testRunner.testCase.getTestStepByName("GetToken").getPropertyValue("response");
//parse the json response
def authResponseJSON = new JsonSlurper().parseText(authResponse);
//access the access_token property in the respose
def oauthToken = authResponseJSON.access_token;
//create a new empty map for headers
def headers = new StringToStringMap();
//create a key value pair in the headers mao
headers.put("OAuth-Token", oauthToken);
//obtain the list of test steps
def steps = context.testCase.getTestStepList();
//iterate thru each of the test steps and set the oauth token to each of the steps
steps.each{
// This block will loop through the test steps and set headers for each of them
if (it.name != 'GetToken' && it.name != 'TransferOauthToken')
it.testRequest.setRequestHeaders(headers);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment